Commits

Anonymous committed 9c9163e

work on another type of urls/views : analytics

Comments (0)

Files changed (2)

followerslookup/urls.py

 from django.conf.urls.defaults import patterns, url
-from views import CsvGenericListView
+from views import CsvGenericListView,TwitterUserListView#,GenericListView
 from django.views.generic import TemplateView
 from models import TwitterUser, User
 
 urlpatterns = patterns('',
     url(r'^howto/$',TemplateView.as_view(template_name="how-to.html")),
+#    url(r'^twitteruser/(?P<user>\w+)/$',GenericListView.as_view(model = User, paginate_by=100)),
     url(r'^lookup/(?P<user>\w+)/$',
         CsvGenericListView.as_view(model = User,paginate_by=100)),
-    url(r'^lookup/$',CsvGenericListView.as_view(model = User,paginate_by=100))
+    url(r'^lookup/$',CsvGenericListView.as_view(model = User,paginate_by=100)),
+    url(r'^test/(?P<pk>\d+)/$',TwitterUserListView.as_view(model=TwitterUser)),
     )
 

followerslookup/views.py

 from models import User, TwitterUser
-from django.views.generic import ListView
+from django.views.generic import ListView,DetailView
 from django.http import HttpResponse
 import csv,codecs
 try:
 except ImportError:
     from StringIO import StringIO
 
+class TwitterUserListView(DetailView):
+    
+    def get_context_data(self,**kwargs):
+        context = super(TwitterUserListView,self).get_context_data(**kwargs)
+        avg = GenericListViewMixin()
+        avg.kwargs, avg.request = self.kwargs, self.request
+        # count number of users
+        extra_queryset = avg.get_queryset()
+        context['count'] = extra_queryset.count()
+        # count users without picture
+        context['nopicture'] = extra_queryset.filter(profile_image_url__contains = "default_profile").count()
+        context['notweet'] = extra_queryset.filter(statuses_count = 0).count()
+        return context
 
-    
-
-class GenericListView(ListView):
+class GenericListViewMixin(object):
     def get_queryset(self):
         qs = User.objects.all()
         if "user" in self.kwargs:
                 qs = qs.filter((k,v))
         return qs
 
+
+class CsvGenericListView(GenericListViewMixin, ListView):
+
     def render_to_response(self,context):
         return self.get_csv_response(self.convert_context_to_csv(context))
 
-class CsvGenericListView(GenericListView):
     
     def get_csv_response(self, content, **httpresponse_kwargs):
         "Construct an `HttpResponse` object."