Sure, but one issue is that violating the rule is expected to result in different reactions when creating vs. when moving a page.
If a rule is violated in a page move, the page goes back to its original position. If a rule is violated while creating a page, there should be a way to determine a default position of the page. How about this, along the lines of page permission methods: can_move(self, new_parent) Should return a Boolean and an alternative new_parent and error message if the Boolean is False? It would be called by Page.save() and by admin_page_ordering. The problem with creating a page is that you cannot modify the page order in the change form, so using validation won’t work. Disallowing the save is not really desirable because the user would have to recreate the page and reenter all the data. But still, what should happen if the rule disallows top-level pages and an alternative parent is not provided? ------------------------------ Back to the original pull request, note that the current situation is that I can enforce rules for page position during page creation by overriding the save method, but there is no mechanism for applying any rules to page moves. The purpose of the pull request is just to introduce that hook. On Mon, May 26, 2014 at 4:26 PM, Stephen McDonald <[email protected]> wrote: > Sure - but if that's the intended use case then perhaps we need a better > approach. > > I tried to implement something like this with page permissions, but I > don't think they cover the case of moving a page: > > http://mezzanine.jupo.org/docs/content-architecture.html#page-permissions > > There really should be one way to implement these rules. > > > > > On Mon, May 26, 2014 at 11:23 PM, Ahmad Khayyat <[email protected]>wrote: > >> Put another way: creating an instance is not a page move. >> >> >> On Mon, May 26, 2014 at 4:21 PM, Ahmad Khayyat <[email protected]>wrote: >> >>> Right. Yes, they can. But that would be handled by the save method of >>> the MyPage model (this is what I do in my app). I don't know of a way to >>> handle it in the page tree. >>> >>> >>> On Mon, May 26, 2014 at 4:18 PM, Stephen McDonald <[email protected]>wrote: >>> >>>> Seems incomplete for the use-case - couldn't the user create a new >>>> MyPage instance as a top-level page? >>>> >>>> >>>> On Mon, May 26, 2014 at 10:26 PM, Ahmad Khayyat <[email protected]>wrote: >>>> >>>>> Any comments? >>>>> Any additional information required? >>>>> >>>>> Here is an example that uses this feature to disallow pages of type >>>>> MyPage to be top-level pages: >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> from mezzanine.pages.signals import pre_page_move >>>>> @receiver(pre_page_move, sender=MyPage)def my_move_constraints(sender, >>>>> page, new_parent, **kwargs): >>>>> >>>>> if new_parent is None: >>>>> return "Pages of type MyPage cannot be top-level pages" >>>>> >>>>> If a user drags a MyPage to a top-level position in the page tree in >>>>> Mezzanine admin, the page will be moved back to its original position, and >>>>> an error message will be displayed using Django messages. The text of the >>>>> error message is the returned string: “Pages of type MyPage cannot be >>>>> top-level pages”. A subsequent valid move will remove the error message. >>>>> >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Mezzanine Users" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to [email protected]. >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> >>>> >>>> >>>> -- >>>> Stephen McDonald >>>> http://jupo.org >>>> >>>> -- >>>> You received this message because you are subscribed to a topic in the >>>> Google Groups "Mezzanine Users" group. >>>> To unsubscribe from this topic, visit >>>> https://groups.google.com/d/topic/mezzanine-users/bIxUJkOIdUM/unsubscribe >>>> . >>>> To unsubscribe from this group and all its topics, send an email to >>>> [email protected]. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Mezzanine Users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Stephen McDonald > http://jupo.org > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Mezzanine Users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/mezzanine-users/bIxUJkOIdUM/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Mezzanine Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
