def get_context_data(self, **kwargs): # Call the base implementation first to get a context context = super(HomeView, self).get_context_data(**kwargs) # get last two calendar events context['events'] = Event.future.all().order_by('date')[0:2] context['last_presented_acts'] = Act.objects.\ filter(presentation_date__isnull=False).distinct().\ order_by('-presentation_date')[0:3] news = News.objects.filter(news_type=News.NEWS_TYPE.community, priority=1) context['last_community_news'] = news.order_by("-created")[0:3] context['key_acts'] = Act.objects.filter( is_key=True).order_by('-presentation_date')[0:3] context['key_votations'] = Votation.objects.filter( is_key=True).order_by('-sitting__date')[0:3] context['top_monitored'] = extract_top_monitored_objects( Person, qnt=5, filter_pk=Person.objects.filter(institutioncharge__end_date=None)) today = datetime.today() # fetch most or least try: counselors = municipality.council.charges.select_related().exclude( n_present_votations=0).order_by('person__last_name') context['most_rebellious'] = counselors.rank_most_rebellious()[0:3] context['most_trustworthy'] = counselors.rank_most_rebellious( ).order_by('n_rebel_votations')[0:3] context['least_absent'] = counselors.rank_least_absent()[0:3] context['most_acts'] = counselors.rank_most_acts()[0:3] except ObjectDoesNotExist: # city council not present counselors = () context['most_rebellious'] = () context['most_trustworthy'] = () context['least_absent'] = () context['most_acts'] = () categories = list(Category.objects.all()) tags = list(Tag.objects.all()) locations = list(Location.objects.all()) context['tags_to_cloud'] = set(categories + tags + locations) context['current_site'] = Site.objects.get(pk=settings.SITE_ID) return context
def get_context_data(self, **kwargs): # Call the base implementation first to get a context context = super(HomeView, self).get_context_data(**kwargs) # get last two calendar events context['events'] = Event.future.all().order_by('date')[0:2] context['last_presented_acts'] = Act.objects.\ filter(actsupport__support_type=ActSupport.SUPPORT_TYPE.first_signer).distinct().\ order_by('-actsupport__support_date')[0:3] news = News.objects.filter(news_type=News.NEWS_TYPE.community, priority=1) context['last_community_news'] = sorted(news, key=lambda n: n.news_date, reverse=True)[0:3] context['key_acts'] = Act.objects.filter(is_key=True).order_by('-presentation_date')[0:3] context['key_votations'] = Votation.objects.filter(is_key=True).order_by('-sitting__date')[0:3] context['top_monitored'] = extract_top_monitored_objects(Person, qnt=3) context['most_acts'] = municipality.council.as_institution.charge_set.\ filter(actsupport__support_type=ActSupport.SUPPORT_TYPE.first_signer).\ annotate(n_acts=Count('actsupport')).order_by('-n_acts')[0:3] # fetch most or least counselors = municipality.council.charges.select_related().order_by('person__last_name') context['most_rebellious'] = counselors.order_by('-n_rebel_votations')[0:3] context['most_trustworthy'] = counselors.order_by('n_rebel_votations')[0:3] context['least_absent'] = counselors.order_by('n_absent_votations')[0:3] categories = list(Category.objects.all()) tags = list(Tag.objects.all()) locations = list(Location.objects.all()) context['tags_to_cloud'] = set(categories + tags + locations) context['current_site'] = Site.objects.get(pk=settings.SITE_ID) return context
def get_context_data(self, **kwargs): # print "in custom view ..." ctx = super(OOUserProfileListView, self).get_context_data(**kwargs) news = News.objects.filter(news_type=News.NEWS_TYPE.community, priority=1) filtered_news = self.filter_news(news, self.request.user) ctx["news_community"] = sorted(filtered_news, key=lambda n: n.news_date, reverse=True)[0:3] # below it is not possible to use the mixin method filter_acts because # extract_top_monitored_objects does not return a QuerySet all_acts = extract_top_monitored_objects( Deliberation, Motion, Interpellation, Agenda, Interrogation, Amendment, Fascicolo, qnt=5 ) ctx["top_monitored_acts"] = self.filter_monitored_acts(all_acts) ctx["ordini_monitorati"] = self.filter_monitored_odg(all_acts) return ctx
def get_context_data(self, **kwargs): # print "in custom view ..." ctx = super(OOUserProfileListView, self).get_context_data(**kwargs) news = News.objects.filter(news_type=News.NEWS_TYPE.community, priority=1) filtered_news = self.filter_news(news, self.request.user) ctx["news_community"] = sorted(filtered_news, key=lambda n: n.news_date, reverse=True)[0:3] # below it is not possible to use the mixin method filter_acts because # extract_top_monitored_objects does not return a QuerySet all_acts = extract_top_monitored_objects(Deliberation, Motion, Interpellation, Agenda, Interrogation, Amendment, Fascicolo, qnt=5) ctx["top_monitored_acts"] = self.filter_monitored_acts(all_acts) ctx["ordini_monitorati"] = self.filter_monitored_odg(all_acts) return ctx