5
5
from django .http import HttpResponse
6
6
import urllib , json
7
7
from django .core .management import call_command
8
+ from django .core .serializers .json import DjangoJSONEncoder
8
9
9
10
def index (request ):
10
- top_dl_components = Component .objects .all ().order_by ('-downloads' )[:3 ]
11
- top_starred_components = Component .objects .all ().order_by ('-stars' )[:3 ]
12
- recent_components = Component .objects .all ().order_by ('-modified_time' )[:3 ]
13
- dl = DownloadSerializer (top_dl_components , many = True ) # serialized data containing number of downloads
11
+ top_downloaded_components = Component .objects .all (). only ( 'name' , 'id' , 'downloads' , 'url_name' ).order_by ('-downloads' )[:3 ]
12
+ top_starred_components = Component .objects .all ().only ( 'name' , 'id' , 'stars' , 'url_name' ). order_by ('-stars' )[:3 ]
13
+ recent_components = Component .objects .all ().only ( 'name' , 'id' , 'modified_time' , 'url_name' ). order_by ('-modified_time' )[:3 ]
14
+ downloaded = DownloadSerializer (top_downloaded_components , many = True ) # serialized data containing number of downloads
14
15
starred = StarSerializer (top_starred_components , many = True ) # serialized data containing number of stars
15
- recent = RecentComponentSerializer (recent_components , many = True ) # serialized data according to upload time
16
+ recent = RecentComponentSerializer (recent_components , many = True )
16
17
return JsonResponse ({
17
- 'top_dl_components' :dl .data ,
18
+ 'top_dl_components' :downloaded .data ,
18
19
'top_starred_components' :starred .data ,
19
20
'most_recent_components' :recent .data ,
20
21
})
21
22
22
23
def all_components (request ): # requested on_load() for querying
23
- all_components = BaseComponentSerializer (Component .objects .all (), many = True )
24
+ all_components = BaseComponentSerializer (Component .objects .all (). only ( 'name' , 'id' , 'url_name' ) , many = True )
24
25
return JsonResponse ({
25
26
'all_components' :all_components .data ,
26
27
})
@@ -35,7 +36,7 @@ def top_components(request):
35
36
def component_details (request , url_name ):
36
37
component = Component .objects .get (url_name = url_name )
37
38
details = DetailComponentSerializer (component , context = {'request' :request })
38
- contributions = ContributionSerializer (Contribution . objects . filter ( component = component ) , many = True )
39
+ contributions = ContributionSerializer (component . contributions , many = True )
39
40
return JsonResponse ({
40
41
'details' : details .data ,
41
42
'contributors' : contributions .data ,
0 commit comments