def publish(self): """Convenience method to publish a page""" published_status_name = get_published_status_name() if self.status != published_status_name: self.status = published_status_name self.save() return True
def add_view(self, request, form_url='', extra_context=None): """ Ensure the user is not trying to add a published or visible page if they lack the necessary permissions. """ if request.method == 'POST': lookup_perm = get_lookup_function(request.user, get_permissions()) # In evaluating permissions for status and visibility, it's not # necessary to do more than raise a 403 if the user does not have # the necessary permissions; status and visibility are disabled # client side, so if they're not what they should be, the user is # doing something suspicious. if not lookup_perm('change_status'): form = self.get_form(request)(request.POST, request.FILES) if form.is_valid(): is_published_value = get_published_status_name() if form.cleaned_data.get('status') == is_published_value: raise PermissionDenied("Can't create published pages.") if not lookup_perm('change_visibility'): form = self.get_form(request)(request.POST, request.FILES) if form.is_valid(): is_public_value = get_public_visibility_name() if form.cleaned_data.get('visibility') == is_public_value: raise PermissionDenied("Can't create public pages.") return super(PageAdmin, self).add_view(request, form_url=form_url, extra_context=extra_context )
def add_view(self, request, form_url='', extra_context=None): """ Ensure the user is not trying to add a published or visible page if they lack the necessary permissions. """ if request.method == 'POST': lookup_perm = get_lookup_function(request.user, get_permissions()) # In evaluating permissions for status and visibility, it's not # necessary to do more than raise a 403 if the user does not have # the necessary permissions; status and visibility are disabled # client side, so if they're not what they should be, the user is # doing something suspicious. if not lookup_perm('change_status'): form = self.get_form(request)(request.POST, request.FILES) if form.is_valid(): is_published_value = get_published_status_name() if form.cleaned_data.get('status') == is_published_value: raise PermissionDenied("Can't create published pages.") if not lookup_perm('change_visibility'): form = self.get_form(request)(request.POST, request.FILES) if form.is_valid(): is_public_value = get_public_visibility_name() if form.cleaned_data.get('visibility') == is_public_value: raise PermissionDenied("Can't create public pages.") return super(PageAdmin, self).add_view(request, form_url=form_url, extra_context=extra_context)
def publish(self): """Convenience method to publish a page""" published_status_name = get_published_status_name() if self.status != published_status_name: self.status = published_status_name self.save() return True
def clean(self): """ Make sure that an item that is a draft copy is always unpublished. """ cleaned_data = super(PageAdminFormMixin, self).clean() status = cleaned_data.get('status') copy_of = self.instance.copy_of if status == get_published_status_name() and copy_of: model_name = self.instance._meta.verbose_name raise forms.ValidationError(( "This %s is an unpublished draft copy of a %s that is already " "published. If you want to publish this over top of the " "existing item, you can do so by merging it." ) % (model_name, model_name)) return cleaned_data
def is_published(self): return self.status == get_published_status_name()
def is_published(self): return self.status == get_published_status_name()
def unpublished(self): """ Returns all unpublished objects.""" return self.get_query_set().exclude( status=get_published_status_name() )
def published(self): """ Returns all published items.""" return self.get_query_set().filter( status=get_published_status_name() )
def unpublished(self): """ Returns all unpublished objects.""" return self.get_query_set().exclude( status=get_published_status_name() )
def published(self): """ Returns all published items.""" return self.get_query_set().filter( status=get_published_status_name() )