Пример #1
0
    def get_form(self, request, obj=None, **kwargs):
        """Get a :class:`Page <pages.admin.forms.PageForm>` for the
        :class:`Page <pages.models.Page>` and modify its fields depending on
        the request."""

        template = get_template_from_request(request, obj)

        #model = create_page_model(get_placeholders(template))

        form = make_form(self.model, get_placeholders(template))

        # bound the form
        language = get_language_from_request(request)
        form.base_fields['language'].initial = language
        if obj:
            initial_slug = obj.slug(language=language, fallback=False)
            initial_title = obj.title(language=language, fallback=False)
            form.base_fields['slug'].initial = initial_slug
            form.base_fields['title'].initial = initial_title

        template = get_template_from_request(request, obj)
        page_templates = settings.get_page_templates()
        template_choices = list(page_templates)
        # is default template is not in the list add it
        if not [
                tpl for tpl in template_choices
                if tpl[0] == settings.PAGE_DEFAULT_TEMPLATE
        ]:
            template_choices.insert(
                0, (settings.PAGE_DEFAULT_TEMPLATE, _('Default template')))
        form.base_fields['template'].choices = template_choices
        form.base_fields['template'].initial = force_text(template)

        for placeholder in get_placeholders(template):
            ctype = placeholder.ctype
            if obj:
                initial = placeholder.get_content(obj,
                                                  language,
                                                  lang_fallback=False)
            else:
                initial = None
            form.base_fields[ctype] = placeholder.get_field(obj,
                                                            language,
                                                            initial=initial)

        return form
Пример #2
0
    def get_form(self, request, obj=None, **kwargs):
        """Get a :class:`Page <pages.admin.forms.PageForm>` for the
        :class:`Page <pages.models.Page>` and modify its fields depending on
        the request."""

        template = get_template_from_request(request, obj)

        model = create_page_model(get_placeholders(template))

        form = make_form(model)

        # bound the form
        language = get_language_from_request(request)
        form.base_fields['language'].initial = language
        if obj:
            initial_slug = obj.slug(language=language, fallback=False)
            initial_title = obj.title(language=language, fallback=False)
            form.base_fields['slug'].initial = initial_slug
            form.base_fields['title'].initial = initial_title
            form.base_fields['slug'].label = _('Slug')

        template = get_template_from_request(request, obj)
        page_templates = settings.get_page_templates()
        if len(page_templates) > 0:
            template_choices = list(page_templates)
            template_choices.insert(
                0, (settings.PAGE_DEFAULT_TEMPLATE, _('Default template')))
            form.base_fields['template'].choices = template_choices
            form.base_fields['template'].initial = force_text(template)

        for placeholder in get_placeholders(template):
            name = placeholder.name
            if obj:
                initial = placeholder.get_content(obj, language, name)
            else:
                initial = None
            form.base_fields[name] = placeholder.get_field(obj,
                                                           language,
                                                           initial=initial)

        return form
Пример #3
0
    def get_form(self, request, obj=None, **kwargs):
        """Get a :class:`Page <pages.admin.forms.PageForm>` for the
        :class:`Page <pages.models.Page>` and modify its fields depending on
        the request."""

        template = get_template_from_request(request, obj)

        #model = create_page_model(get_placeholders(template))

        form = make_form(self.model, get_placeholders(template))

        # bound the form
        language = get_language_from_request(request)
        form.base_fields['language'].initial = language
        if obj:
            initial_slug = obj.slug(language=language, fallback=False)
            initial_title = obj.title(language=language, fallback=False)
            form.base_fields['slug'].initial = initial_slug
            form.base_fields['title'].initial = initial_title

        template = get_template_from_request(request, obj)
        page_templates = settings.get_page_templates()
        template_choices = list(page_templates)
        # is default template is not in the list add it
        if not [tpl for tpl in template_choices if tpl[0] == settings.PAGE_DEFAULT_TEMPLATE]:
            template_choices.insert(0, (settings.PAGE_DEFAULT_TEMPLATE,
                    _('Default template')))
        form.base_fields['template'].choices = template_choices
        form.base_fields['template'].initial = force_text(template)

        for placeholder in get_placeholders(template):
            ctype = placeholder.ctype
            if obj:
                initial = placeholder.get_content(obj, language, lang_fallback=False)
            else:
                initial = None
            form.base_fields[ctype] = placeholder.get_field(obj,
                language, initial=initial)

        return form
Пример #4
0
    def get_form(self, request, obj=None, **kwargs):
        """Get a :class:`Page <pages.admin.forms.PageForm>` for the
        :class:`Page <pages.models.Page>` and modify its fields depending on
        the request."""

        template = get_template_from_request(request, obj)

        model = create_page_model(get_placeholders(template))

        form = make_form(model)

        # bound the form
        language = get_language_from_request(request)
        form.base_fields['language'].initial = language
        if obj:
            initial_slug = obj.slug(language=language, fallback=False)
            initial_title = obj.title(language=language, fallback=False)
            form.base_fields['slug'].initial = initial_slug
            form.base_fields['title'].initial = initial_title
            form.base_fields['slug'].label = _('Slug')

        template = get_template_from_request(request, obj)
        page_templates = settings.get_page_templates()
        if len(page_templates) > 0:
            template_choices = list(page_templates)
            template_choices.insert(0, (settings.PAGE_DEFAULT_TEMPLATE,
                                        _('Default template')))
            form.base_fields['template'].choices = template_choices
            form.base_fields['template'].initial = force_text(template)

        for placeholder in get_placeholders(template):
            name = placeholder.name
            if obj:
                initial = placeholder.get_content(obj, language, name)
            else:
                initial = None
            form.base_fields[name] = placeholder.get_field(obj,
                                                           language, initial=initial)

        return form