Skip to content

Commit 4e6bed0

Browse files
committed
Added Github call for downloads
1 parent b0e96c8 commit 4e6bed0

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

biojs/settings.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@
132132

133133
USE_TZ = True
134134

135+
CACHES = {
136+
"default": {
137+
"BACKEND": "django_redis.cache.RedisCache",
138+
"LOCATION": "redis://127.0.0.1:6379/1",
139+
"OPTIONS": {
140+
"CLIENT_CLASS": "django_redis.client.DefaultClient",
141+
}
142+
}
143+
}
144+
135145

136146
# Static files (CSS, JavaScript, Images)
137147
# https://docs.djangoproject.com/en/1.10/howto/static-files/

main/management/commands/updatecomponents.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ def get_contributors_data(contributors_url):
2727
data = json.load(response)
2828
return data
2929

30+
def get_downloads(downloads_url):
31+
import ast
32+
print downloads_url
33+
response = urllib.urlopen(downloads_url)
34+
downloads = 0
35+
data = ast.literal_eval(response.read())
36+
for download in data:
37+
downloads += int(download['download_count'])
38+
return downloads
39+
3040

3141
class Command(BaseCommand):
3242
# during --help
@@ -123,6 +133,7 @@ def handle(self, *args, **options):
123133
_contribution = Contribution.objects.create(component=_component, contributor=_contributor, contributions=contributor["contributions"])
124134
commits += _contribution.contributions
125135
count +=1
136+
_component.downloads = get_downloads(str(github_data['downloads_url']) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET)
126137
_component.commits = commits
127138
_component.no_of_contributors = count
128139
_component.save()

main/serializers.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class DownloadSerializer(serializers.ModelSerializer):
55
property = serializers.SerializerMethodField()
66

77
def get_property(self, component):
8-
return component.forks
8+
return component.downloads
99

1010
class Meta:
1111
model = Component
@@ -39,13 +39,6 @@ def get_tags(self, obj):
3939
for t in obj.tags.all():
4040
tags.append(t.name)
4141
return tags
42-
def get_icon_url(self, obj):
43-
if obj.icon:
44-
request = self.context.get('request')
45-
icon_url = obj.icon.url
46-
return request.build_absolute_uri(icon_url)
47-
else:
48-
return '#'
4942
class Meta:
5043
model = Component
5144
fields = ('name', 'tags', 'icon_url', 'downloads', 'stars', 'modified_time', 'short_description', 'id', 'url_name', 'author')

main/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import urllib, json
77

88
def index(request):
9-
top_dl_components = Component.objects.all().order_by('-forks')[:3]
9+
top_dl_components = Component.objects.all().order_by('-downloads')[:3]
1010
top_starred_components = Component.objects.all().order_by('-stars')[:3]
1111
recent_components = Component.objects.all().order_by('-modified_time')[:3]
1212
dl = DownloadSerializer(top_dl_components, many=True) # serialized data containing number of downloads

0 commit comments

Comments
 (0)