Exemple #1
0
    def get_template(self, alias, layout=None, terms=None):
        """
        Returns the template.
        RUS: Добавляет в термины id термина макета
        Возвращает шаблон.
        """
        queryset = self.get_template_queryset().filter(
            **{
                "{}___index__icontains".format(self.template_model._meta.object_name):
                alias
            })

        # clear creation date, time terms & e.t.
        terms = list(
            TermModel.objects.filter(id__in=terms).exclude(
                system_flags=TermModel.system_flags.
                external_tagging_restriction).values_list(
                    'id', flat=True)) if terms is not None else []

        if layout is not None:
            layout_term = get_views_layouts().get(layout, None)
            if layout_term is not None:
                terms.append(layout_term.id)

        return queryset.semantic_filter(terms,
                                        use_cached_decompress=True,
                                        fix_it=False).get_similar(
                                            terms,
                                            use_cached_decompress=True,
                                            fix_it=False)
def invalidate_term_before_delete(sender, instance, **kwargs):
    """
    RUS: Очищает ключ кеша макета отображения перед удалением терминов.
    """
    layout = get_views_layouts().get(instance.key, None)
    if layout is not None:
        layout.hard_delete()
    setattr(sender, VIEW_LAYOUT_CACHE_KEY, None)
Exemple #3
0
 def clean_terms(self):
     """
     RUS: Словарь проверенных и нормализованных данных формы шаблона.
     Вызывает ошибку валидации формы, если нет
     списка терминов представлений разметок страниц и терминов в очищенных данных.
     """
     terms = self.cleaned_data.get("terms")
     if not (set([v.id for (k, v) in get_views_layouts().items()]) & set([x.id for x in terms])):
         raise forms.ValidationError(self.messages['has_view_layout_error'])
     return terms
    def validate_terms(self, origin, **kwargs):
        """
        RUS: При выборе макета представления и его сохранения, проставляются соответствующие термины и выбирается
        автоматически соответствующий шаблон.
        При изменении макета, термины удаляются и заменяются новыми, соответствующими новому макету.
        """
        context = kwargs["context"]

        force_validate_terms = context.get("force_validate_terms", False)

        if force_validate_terms or context.get("validate_view_layout", False):
            views_layouts = get_views_layouts()
            to_remove = [v for k, v in views_layouts.items() if k != PublicationBase.LAYOUT_TERM_SLUG]
            self.terms.remove(*to_remove)
            to_add = views_layouts.get(PublicationBase.LAYOUT_TERM_SLUG, None)
            if to_add is not None:
                self.terms.add(to_add)
        super(PublicationBase, self).validate_terms(origin, **kwargs)
Exemple #5
0
    def validate_terms(self, origin, **kwargs):
        context = kwargs["context"]

        force_validate_terms = context.get("force_validate_terms", False)

        if force_validate_terms or context.get("validate_view_layout", False):
            views_layouts = get_views_layouts()
            to_remove = [v for k, v in views_layouts.items() if k != Product.LAYOUT_TERM_SLUG]
            self.terms.remove(*to_remove)
            to_add = views_layouts.get(Product.LAYOUT_TERM_SLUG, None)
            if to_add is not None:
                self.terms.add(to_add)

        if force_validate_terms or context.get("validate_in_stock", False):

            current_stock_choice = Product.IN_STOCK_CHOICES_TERMS[0] if self.in_stock and self.in_stock > 0 else Product.IN_STOCK_CHOICES_TERMS[1]

            in_stock_root_choices = getattr(Product, '_in_stock_root_choices', None)
            if in_stock_root_choices is None:
                in_stock_root_choices = {}
                try:
                    parent_wraper = get_or_create_model_class_wrapper_term(Product)
                    root = TermModel.objects.get(
                            slug=self.IN_STOCK_ROOT_TERM[0],
                            parent=parent_wraper
                        )
                    for term in root.get_descendants(include_self=True):
                        in_stock_root_choices[term.slug] = term
                except TermModel.DoesNotExist:
                    pass

                    setattr(Product, '_in_stock_root_choices', in_stock_root_choices)

            to_remove = [v for k, v in in_stock_root_choices.items() if k != current_stock_choice[0]]
            self.terms.remove(*to_remove)
            to_add = in_stock_root_choices.get(current_stock_choice[0], None)
            if to_add is not None:
                self.terms.add(to_add)

        super(Product, self).validate_terms(origin, **kwargs)