Example #1
0
    def save_model(self, request, obj, form, change):
        super().save_model(request, obj, form, change)
        element_id = obj.glossary['element_id']
        if not change:
            # when adding a new element, `element_id` can not be validated for uniqueness
            postfix = 0
            # check if form simplewarpper has function check_unique_element_id
            if not 'check_unique_element_id' in dir(form):
                form_ = SectionFormMixin
            else:
                form_ = form
            while True:
                try:
                    form_.check_unique_element_id(obj, element_id)
                except ValidationError:
                    postfix += 1
                    element_id = '{element_id}_{0}'.format(
                        postfix, **obj.glossary)
                else:
                    break
            if postfix:
                obj.glossary['element_id'] = element_id
                obj.save()

        cms_page = obj.placeholder.page
        if cms_page:
            # storing the element_id on a placholder only makes sense, if it is non-static
            CascadePage.assure_relation(cms_page)
            cms_page.cascadepage.glossary.setdefault('element_ids', {})
            cms_page.cascadepage.glossary['element_ids'][str(
                obj.pk)] = element_id
            cms_page.cascadepage.save()
Example #2
0
    def setUp(self):
        self.home_page = create_page(title='HOME',
                                     template='testing.html',
                                     language='en')
        if not self.home_page.is_home:
            # >= Django CMS v3.5.x
            self.home_page.set_as_homepage()
        CascadePage.assure_relation(self.home_page)

        self.placeholder = self.home_page.placeholders.get(slot='Main Content')

        self.request = self.get_request(self.home_page, 'en')
        self.admin_site = admin.sites.AdminSite()

        UserModel = get_user_model()
        UserModel.objects.get_or_create(
            username='******',
            is_staff=True,
            is_superuser=True,
            is_active=True,
            password=make_password('admin'),
        )
        UserModel.objects.get_or_create(
            username='******',
            is_staff=True,
            is_superuser=False,
            is_active=True,
            password=make_password('staff'),
        )
Example #3
0
    def save_model(self, request, obj, form, change):
        super(SectionMixin, self).save_model(request, obj, form, change)
        element_id = obj.glossary['element_id']
        if not change:
            # when adding a new element, `element_id` can not be validated for uniqueness
            postfix = 0
            while True:
                try:
                    form.check_unique_element_id(obj, element_id)
                except ValidationError:
                    postfix += 1
                    element_id = '{element_id}_{0}'.format(postfix, **obj.glossary)
                else:
                    break
            if postfix:
                obj.glossary['element_id'] = element_id
                obj.save()

        cms_page = obj.placeholder.page
        if cms_page:
            # storing the element_id on a placholder only makes sense, if it is non-static
            CascadePage.assure_relation(cms_page)
            cms_page.cascadepage.glossary.setdefault('element_ids', {})
            cms_page.cascadepage.glossary['element_ids'][str(obj.pk)] = element_id
            cms_page.cascadepage.save()
Example #4
0
def cms_page():
    home_page = create_page(title='HOME',
                            template='testing.html',
                            language='en')
    if not home_page.is_home:
        home_page.set_as_homepage()
    CascadePage.assure_relation(home_page)
    return home_page
Example #5
0
    def setUp(self):
        self.home_page = create_page(title='HOME', template='testing.html', language='en')
        if not self.home_page.is_home:
            # >= Django CMS v3.5.x
            self.home_page.set_as_homepage()
        CascadePage.assure_relation(self.home_page)

        self.placeholder = self.home_page.placeholders.get(slot='Main Content')

        self.request = self.get_request(self.home_page, 'en')
        self.admin_site = admin.sites.AdminSite()
Example #6
0
    def setUp(self):
        self.home_page = create_page(title='HOME',
                                     template='testing.html',
                                     language='en')
        if not self.home_page.is_home:
            # >= Django CMS v3.5.x
            self.home_page.set_as_homepage()
        CascadePage.assure_relation(self.home_page)

        self.placeholder = self.home_page.placeholders.get(slot='Main Content')

        self.request = self.get_request(self.home_page, 'en')
        self.admin_site = admin.sites.AdminSite()
Example #7
0
    def _preset_section(self, data, initial):
        choices = [(None, _("Page root"))]
        try:
            if data:
                cms_page = Page.objects.get(pk=data['cms_page'])
            else:
                cms_page = Page.objects.get(pk=initial['link']['pk'])
        except (KeyError, ValueError, ObjectDoesNotExist):
            pass
        else:
            CascadePage.assure_relation(cms_page)
            for key, val in cms_page.cascadepage.glossary.get('element_ids', {}).items():
                choices.append((key, val))

        self.base_fields['section'].initial = initial['link'].get('section')
        self.base_fields['section'].choices = choices
Example #8
0
    def save_model(self, request, obj, form, change):
        super(SectionMixin, self).save_model(request, obj, form, change)
        CascadePage.assure_relation(obj.page)
        element_id = obj.glossary['element_id']
        if not change:
            # when adding a new element, `element_id` can not be validated for uniqueness
            postfix = 0
            while form.check_unique_element_id(obj, element_id) is False:
                postfix += 1
                element_id = '{element_id}_{0}'.format(postfix, **obj.glossary)
            if postfix:
                obj.glossary['element_id'] = element_id
                obj.save()

        obj.page.cascadepage.glossary.setdefault('element_ids', {})
        obj.page.cascadepage.glossary['element_ids'][str(obj.pk)] = element_id
        obj.page.cascadepage.save()
Example #9
0
    def save_model(self, request, obj, form, change):
        super(SectionMixin, self).save_model(request, obj, form, change)
        CascadePage.assure_relation(obj.page)
        element_id = obj.glossary['element_id']
        if not change:
            # when adding a new element, `element_id` can not be validated for uniqueness
            postfix = 0
            while form.check_unique_element_id(obj, element_id) is False:
                postfix += 1
                element_id = '{element_id}_{0}'.format(postfix, **obj.glossary)
            if postfix:
                obj.glossary['element_id'] = element_id
                obj.save()

        obj.page.cascadepage.glossary.setdefault('element_ids', {})
        obj.page.cascadepage.glossary['element_ids'][str(obj.pk)] = element_id
        obj.page.cascadepage.save()