def render(self, request, place, context, block_content_relation=None, *args, **kwargs): section = None content = None standingout_categories = StandingOutCategory.objects.all() standingouts = None for standingout_category in standingout_categories: variable_value = context.get(standingout_category.context_variable, None) if variable_value: variable_real_instance = getattr(variable_value, 'get_real_instance', None) if variable_real_instance: variable_value = variable_real_instance() if standingout_category.context_variable == 'section': standingouts = get_section_standingouts(StandingOut.objects.all(), variable_value) section = standingouts and variable_value else: filter_ctypes = get_filter_ct(variable_value) standingouts = StandingOut.objects.filter(related_id=variable_value.pk).filter(filter_ctypes) content = standingouts and variable_value if content: sections = content.sections.all() if sections.count(): section = sections[0] if standingouts: break standingouts = standingouts or StandingOut.objects.filter(related_content_type__isnull=True, related_id__isnull=True) limit = self.get_config().get('limit', None) if limit: standingouts = standingouts[:limit.get_value()] return self.render_block(request, template_name='block_standingout.html', block_title=_('Search'), context={'standingouts': standingouts, 'section': section, 'content': content})
def clean(self): cleaned_data = super(HotLinkForm, self).clean() section = self.get_section(cleaned_data) if self.is_menu(cleaned_data) and section: main_menu = section.get_real_instance().main_menu menu = main_menu.get_children().filter(slug=cleaned_data['slug']) if menu: raise forms.ValidationError(_(u'Already exits a menu in your section with this slug')) if self.is_standingout(cleaned_data) and section: from plugins.standingout.utils import get_filter_ct standingouts = self.get_standingout_of_section(section).filter( obj_id=self.content.id).filter( get_filter_ct(self.content, 'obj')) if standingouts: raise forms.ValidationError(_(u'Already exits a standing out in your section with this content')) return cleaned_data
def render(self, request, place, context, block_content_relation=None, *args, **kwargs): section = None content = None standingout_categories = StandingOutCategory.objects.all() standingouts = None for standingout_category in standingout_categories: variable_value = context.get(standingout_category.context_variable, None) if variable_value: variable_real_instance = getattr(variable_value, 'get_real_instance', None) if variable_real_instance: variable_value = variable_real_instance() if standingout_category.context_variable == 'section': standingouts = get_section_standingouts( StandingOut.objects.all(), variable_value) section = standingouts and variable_value else: filter_ctypes = get_filter_ct(variable_value) standingouts = StandingOut.objects.filter( related_id=variable_value.pk).filter(filter_ctypes) content = standingouts and variable_value if content: sections = content.sections.all() if sections.count(): section = sections[0] if standingouts: break standingouts = standingouts or StandingOut.objects.filter( related_content_type__isnull=True, related_id__isnull=True) limit = self.get_config().get('limit', None) if limit: standingouts = standingouts[:limit.get_value()] return self.render_block(request, template_name='block_standingout.html', block_title=_('Search'), context={ 'standingouts': standingouts, 'section': section, 'content': content })
def get_standingout_of_section(self, section): from plugins.standingout.models import StandingOut from plugins.standingout.utils import get_filter_ct return StandingOut.objects.filter(related_id=section.id).filter( get_filter_ct(section))