def get_context_data(self, **kwargs): context = {} # channel is needed everywhere self.channel = self.channel or Channel.objects.get_homepage( site=get_current_site(self.request)) if not self.channel and getattr(settings, 'OPPS_MULTISITE_FALLBACK', None): self.channel = Channel.objects.filter(homepage=True, published=True)[:1].get() context['channel'] = self.channel if not self.long_slug: return context context = super(View, self).get_context_data(**kwargs) if hasattr(self, 'articleboxes'): context['articleboxes'] = self.articleboxes else: context['articleboxes'] = ContainerBox.objects.filter( channel__long_slug=self.long_slug) self.excluded_ids = [] for box in context['articleboxes']: self.excluded_ids += [a.pk for a in box.ordered_containers()] obj_filter = {} obj_filter['site_domain'] = self.site.domain obj_filter['date_available__lte'] = timezone.now() obj_filter['published'] = True filters = obj_filter filters['channel_long_slug__in'] = self.channel_long_slug is_paginated = self.page_kwarg in self.request.GET if self.channel and self.channel.is_root_node() and not is_paginated: filters['show_on_root_channel'] = True article = Container.objects.filter(**filters) context['posts'] = article.filter(child_class='Post').exclude( pk__in=self.excluded_ids)[:self.limit] context['albums'] = Album.objects.filter(**filters).exclude( pk__in=self.excluded_ids)[:self.limit] context['channel'] = {} context['channel']['long_slug'] = self.long_slug if self.channel: context['channel'] = self.channel context['breadcrumb'] = self.get_breadcrumb() if self.slug: try: context['next'] = self.get_object() \ .get_next_by_date_insert(**obj_filter) except self.get_object().DoesNotExist: pass try: context['prev'] = self.get_object() \ .get_previous_by_date_insert(**obj_filter) except self.get_object().DoesNotExist: pass context['articleboxes'] = context['articleboxes'].filter( containers__slug=self.slug) if self.get_object().child_class == 'Mirror': context['context'] = self.get_object().container if self.request.META.get('HTTP_X_PJAX', False) or \ self.request.is_ajax(): context['extends_parent'] = 'base_ajax.html' try: # opps.field append on context context['context'].fields = field_template_read( context['context'].custom_fields()) except AttributeError: pass return context
def test_empty_dict(self): """Dict empty is false in Python""" read_on_template = field_template_read({}) self.assertFalse(read_on_template) self.assertEqual(read_on_template, {})
def test_down_case(self): read_on_template = field_template_read(self.dict_out) self.assertEqual(read_on_template, self.dict_out)
def test_self_dict(self): read_on_template = field_template_read(self.dict) self.assertNotEqual(self.dict, self.dict_out) self.assertTrue(read_on_template) self.assertEqual(read_on_template, self.dict_out)
def get_context_data(self, **kwargs): context = {} # channel is needed everywhere self.channel = self.channel or Channel.objects.get_homepage( site=get_current_site(self.request) ) if not self.channel and getattr( settings, 'OPPS_MULTISITE_FALLBACK', None): self.channel = Channel.objects.filter( homepage=True, published=True)[:1].get() context['channel'] = self.channel if not self.long_slug: return context context = super(View, self).get_context_data(**kwargs) if hasattr(self, 'articleboxes'): context['articleboxes'] = self.articleboxes else: context['articleboxes'] = ContainerBox.objects.filter( channel__long_slug=self.long_slug) self.excluded_ids = [] for box in context['articleboxes']: self.excluded_ids += [a.pk for a in box.ordered_containers()] obj_filter = {} obj_filter['site_domain'] = self.site.domain obj_filter['date_available__lte'] = timezone.now() obj_filter['published'] = True filters = obj_filter filters['channel_long_slug__in'] = self.channel_long_slug is_paginated = self.page_kwarg in self.request.GET if self.channel and self.channel.is_root_node() and not is_paginated: filters['show_on_root_channel'] = True article = Container.objects.filter(**filters) context['posts'] = article.filter( child_class='Post' ).exclude(pk__in=self.excluded_ids)[:self.limit] context['albums'] = Album.objects.filter( **filters ).exclude(pk__in=self.excluded_ids)[:self.limit] context['channel'] = {} context['channel']['long_slug'] = self.long_slug if self.channel: context['channel'] = self.channel context['breadcrumb'] = self.get_breadcrumb() if self.slug: try: context['next'] = self.get_object() \ .get_next_by_date_insert(**obj_filter) except self.get_object().DoesNotExist: pass try: context['prev'] = self.get_object() \ .get_previous_by_date_insert(**obj_filter) except self.get_object().DoesNotExist: pass context['articleboxes'] = context['articleboxes'].filter( containers__slug=self.slug) if self.get_object().child_class == 'Mirror': context['context'] = self.get_object().container if self.request.META.get('HTTP_X_PJAX', False) or \ self.request.is_ajax(): context['extends_parent'] = 'base_ajax.html' try: # opps.field append on context context['context'].fields = field_template_read( context['context'].custom_fields()) except AttributeError: pass return context