Example #1
0
    def render_tag(self, context, kwargs, varname):
        """
        RUS: Отображает в шаблоне контекст, если есть шаблон.
        """
        alias = kwargs.get('alias', 'index')

        template = self.get_cached_template(
            alias, kwargs.get('layout', PAGE_LAYOUT_ROOT_TERM_SLUG),
            kwargs.get('terms_ids'))

        if template is not None:
            sekizai_varname = sekizai_get_varname()
            ctx = copy.copy(context)
            request = ctx.get("request")
            ctx.update({
                "params": kwargs,
                sekizai_varname: getattr(request, sekizai_varname)
            })
            template_string = template.template.read_template(alias)
            t = django_template.Template(template_string)
            c = django_template.Context(ctx)
            data = t.render(c)
        else:
            data = ''
        if varname:
            context[varname] = data
            return ''
        else:
            return data
Example #2
0
    def render(self, request, instance, **kwargs):
        """
        RUS: Возвращает результат обработки html шаблонов,
        если страница была создана и сохранена, был добавлен шаблон и обновлен контекст.
        """
        template_str = instance.template.read_template()

        sekizai_varname = sekizai_get_varname()
        if template_str:
            template = django_template.Template(template_str)
            context = django_template.Context(
                self.get_context(request, instance, **kwargs))
            context.update({
                'config': config,
                'request': request,
                sekizai_varname: getattr(request, sekizai_varname),
            })

            page_id = instance.placeholder.parent_id
            if page_id:
                try:
                    page = SimplePage.objects.get(id=page_id)
                except SimplePage.DoesNotExist:
                    page = None
                if page:
                    context.update({'page': page})

            return template.render(context)
        else:
            return mark_safe(self.render_error(_('Template is not defined')))
Example #3
0
    def get_context(self, request, instance, **kwargs):
        """
        RUS: Возвращает контекст с обновленными данными.
        """
        if update_hot_tags_on_render:
            instance = update_hot_tags_on_render(instance)

        context = super(BaseBlockPlugin,
                        self).get_context(request, instance, **kwargs)
        current_index = getattr(request, '_blockitem_index', 0)
        publication = request.GET.get(
            EntityViewSet.REQUEST_CACHED_SERIALIZED_DATA_KEY, None)
        if publication is None:
            publication_serializer = EntityDetailSerializer(
                instance.parent, context={"request": request})
            publication = publication_serializer.data
            request.GET[
                EntityViewSet.REQUEST_CACHED_SERIALIZED_DATA_KEY] = publication

        sekizai_varname = sekizai_get_varname()
        context.update({
            'key':
            instance.id,
            'publication':
            publication,
            'position':
            current_index,
            'text':
            instance.text,
            'subjects':
            instance.subjects.all(),
            'images':
            EntityImage.objects.filter(key=str(instance.id)),
            'files':
            EntityFile.objects.filter(key=str(instance.id)),
            'related_data_marts': [
                x.data_mart for x in EntityRelatedDataMart.objects.filter(
                    key=str(instance.id))
            ],
            'comments':
            PublicationComment.objects.filter(key=str(instance.id)),
            'config':
            config,
            sekizai_varname:
            getattr(request, sekizai_varname),
        })
        request._blockitem_index = current_index + 1

        return context
    def get_context(self, request, instance, **kwargs):
        """
        Return the context to use in the template defined by ``render_template`` (or :func:`get_render_template`).
        By default, it returns the model instance as ``instance`` field in the template.
        RUS: Возвращает контекст для шаблонов плагина "дизайнер форм".
        """

        sekizai_varname = sekizai_get_varname()

        context = {
            'instance': instance,
            'config': config,
            sekizai_varname: getattr(request, sekizai_varname),
        }

        return process_form(request,
                            instance.form_definition,
                            context,
                            disable_redirection=True)
    def get_context(self, request, instance, **kwargs):
        """
        RUS: Возвращает контекст с обновленными расширенными данными в зависимости от количества текстовых блоков.
        """
        context = super(DataMartPlugin,
                        self).get_context(request, instance, **kwargs)
        datamarts = instance.datamarts.active()
        terms_ids = list(instance.terms.active().values_list('id', flat=True))
        subj_ids = list(instance.subjects.active().values_list('id',
                                                               flat=True))
        type_id = instance.polymorphic_ctype_id
        pos = instance.sort_order

        sekizai_varname = sekizai_get_varname()

        if pos == 0:
            before = False
        else:
            before = instance.placeholder.contentitems.filter(
                polymorphic_ctype_id=type_id,
                sort_order__exact=pos - 1).exists()
        after = instance.placeholder.contentitems.filter(
            polymorphic_ctype_id=type_id, sort_order__exact=pos + 1).exists()

        context.update({
            'request': request,
            'config': config,
            'data_marts': datamarts,
            'data_mart_pk': str(datamarts[0].pk),
            'data_mart_name': datamarts[0].name,
            'terms_ids': terms_ids,
            'subj_ids': subj_ids,
            'is_first': not before,
            'is_last': not after,
            sekizai_varname: getattr(request, sekizai_varname),
        })
        return context