Example #1
0
    def clean(self):
        """
        Perform additional validation of rules regarding the PageLayout's
        existence, rather than those validating the PageLayout's data (which
        can be handled in PageLayoutAdmin.full_clean).

        This is done by calling the validate_layout classmethod on the class
        of the proposed layout, passing it the class of the parent's layout.

        Unfortunately, this validation only occurs in the admin; it is not
        performed when creating Page objects otherwise.
        """
        layout_cls = pagemanager_site.get_by_name(self.data['layout'])
        try:
            parent_cls = self.cleaned_data['parent'].page_layout.__class__
        except AttributeError:
            parent_cls = None
        layout_cls.validate_layout(parent_cls)
        return self.cleaned_data
Example #2
0
    def clean(self):
        """
        Perform additional validation of rules regarding the PageLayout's
        existence, rather than those validating the PageLayout's data (which
        can be handled in PageLayoutAdmin.full_clean).

        This is done by calling the validate_layout classmethod on the class
        of the proposed layout, passing it the class of the parent's layout.

        Unfortunately, this validation only occurs in the admin; it is not
        performed when creating Page objects otherwise.
        """
        layout_cls = pagemanager_site.get_by_name(self.data['layout'])
        try:
            parent_cls = self.cleaned_data['parent'].page_layout.__class__
        except AttributeError:
            parent_cls = None
        layout_cls.validate_layout(parent_cls)
        return self.cleaned_data
Example #3
0
    def save_model(self, request, obj, form, change):
        """
        Given a model instance, saves it to the database.

        Modified to create associations between the Page object and the chosen
        PageLayout object on the initial save.
        """

        if not obj.pk:
            # Create new instance of PostLayout subclass
            layout_model = pagemanager_site.get_by_name(request.POST['layout'])
            layout = layout_model()
            layout.save()

            # Associate PostLayout subclass instance with Page
            obj.layout_type = ContentType.objects.get_for_model(layout_model)
            obj.object_id = layout.pk
        obj.save()
        signals.page_edited.send(sender=self, page=obj, created=True)
Example #4
0
    def save_model(self, request, obj, form, change):
        """
        Given a model instance, saves it to the database.

        Modified to create associations between the Page object and the chosen
        PageLayout object on the initial save.
        """

        if not obj.pk:
            # Create new instance of PostLayout subclass
            layout_model = pagemanager_site.get_by_name(request.POST['layout'])
            layout = layout_model()
            layout.save()

            # Associate PostLayout subclass instance with Page
            obj.layout_type = ContentType.objects.get_for_model(layout_model)
            obj.object_id = layout.pk
        obj.save()
        signals.page_edited.send(sender=self, page=obj, created=True)