Skip to content

Commit

Permalink
Show contributor image
Browse files Browse the repository at this point in the history
  • Loading branch information
KVGarg committed Feb 4, 2019
1 parent 2a5d9bd commit 97fdf02
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions data/contrib_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def import_data(contributor):
try:
contributor['issues_opened'] = contributor.pop('issues')
contributor['num_commits'] = contributor.pop('contributions')
contributor['image_url'] = get_image_url(login)
contributor.pop('teams')
c, create = Contributor.objects.get_or_create(
**contributor
Expand All @@ -45,3 +46,7 @@ def import_data(contributor):
logger.error(
'Something went wrong saving this contributor %s: %s'
% (login, ex))


def get_image_url(username):
return 'https://avatars1.githubusercontent.com/{}'.format(username)
18 changes: 18 additions & 0 deletions data/migrations/0005_contributor_image_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.1.5 on 2019-02-04 18:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('data', '0004_auto_20180809_2229'),
]

operations = [
migrations.AddField(
model_name='contributor',
name='image_url',
field=models.ImageField(default=None, null=True, upload_to=''),
),
]
1 change: 1 addition & 0 deletions data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Contributor(models.Model):
num_commits = models.IntegerField(default=None, null=True)
reviews = models.IntegerField(default=None, null=True)
issues_opened = models.IntegerField(default=None, null=True)
image_url = models.ImageField(default=None, null=True)
teams = models.ManyToManyField(Team)

def __str__(self):
Expand Down
8 changes: 8 additions & 0 deletions templates/contributors.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Contributors Data</title>
<style>
.user-image {
width: 100%;
}
</style>
</head>
<body>
<h1>Details of all the contributors</h1>
<ul>
{% for contributor in contributors %}
<div class="container">
<div class="row">
<div class="col-sm-6 col-md-4">
<img src="{{ contributor.image_url }}" class="user-image" alt="User Avatar">
</div>
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<div class="caption">
Expand Down

0 comments on commit 97fdf02

Please sign in to comment.