def fe_identifier(self): """ Returns an identifier which is understood by the frontend editing javascript code. (It is used to find the URL which should be used to load the form for every given block of content.) """ return '%s-%s-%s-%s-%s' % ( cls._meta.app_label, get_model_name(cls._meta), self.__class__.__name__.lower(), self.parent_id, self.id, )
def __init__(self, *args, **kwargs): super(CommentContentAdminForm, self).__init__(*args, **kwargs) parent = kwargs.get('instance', None) if parent is not None: f = self.fields['comments_enabled'] r = f.help_text r += '<hr />' comments_model = comments.get_model() for c in comments_model.objects.for_model( parent.parent).order_by('-submit_date'): r += ( '<div class="form-row" style="margin-left: 60px">' '# %(pk)d <a href="/admin/%(app)s/%(model)s/%(pk)' 'd/">%(comment)s</a> - %(is_public)s</div>') % { 'pk': c.id, 'comment': c.comment[:80], 'is_public': ( _('public') if c.is_public else _('not public')), 'app': comments_model._meta.app_label, 'model': get_model_name(comments_model._meta), } f.help_text = r
def clean(self): cleaned_data = super(PageAdminForm, self).clean() # No need to think further, let the user correct errors first if self._errors: return cleaned_data current_id = None # See the comment below on why we do not use Page.objects.active(), # at least for now. active_pages = self.page_manager.filter(active=True) if self.instance: current_id = self.instance.id active_pages = active_pages.exclude(id=current_id) if hasattr(Site, 'page_set') and 'site' in cleaned_data: active_pages = active_pages.filter(site=cleaned_data['site']) # Convert PK in redirect_to field to something nicer for the future redirect_to = cleaned_data.get('redirect_to') if redirect_to and re.match(r'^\d+$', redirect_to): opts = self.page_model._meta cleaned_data['redirect_to'] = '%s.%s:%s' % ( opts.app_label, get_model_name(opts), redirect_to) if 'active' in cleaned_data and not cleaned_data['active']: # If the current item is inactive, we do not need to conduct # further validation. Note that we only check for the flag, not # for any other active filters. This is because we do not want # to inspect the active filters to determine whether two pages # really won't be active at the same time. return cleaned_data if 'override_url' in cleaned_data and cleaned_data['override_url']: if active_pages.filter( _cached_url=cleaned_data['override_url']).count(): self._errors['override_url'] = ErrorList( [_('This URL is already taken by an active page.')]) del cleaned_data['override_url'] return cleaned_data if current_id: # We are editing an existing page parent = self.page_manager.get(pk=current_id).parent else: # The user tries to create a new page parent = cleaned_data['parent'] if parent: new_url = '%s%s/' % (parent._cached_url, cleaned_data['slug']) else: new_url = '/%s/' % cleaned_data['slug'] if active_pages.filter(_cached_url=new_url).count(): self._errors['active'] = ErrorList( [_('This URL is already taken by another active page.')]) del cleaned_data['active'] if parent and parent.template.enforce_leaf: self._errors['parent'] = ErrorList( [_('This page does not allow attachment of child pages')]) del cleaned_data['parent'] return cleaned_data
def clean(self): cleaned_data = super(PageAdminForm, self).clean() # No need to think further, let the user correct errors first if self._errors: return cleaned_data current_id = None # See the comment below on why we do not use Page.objects.active(), # at least for now. active_pages = self.page_manager.filter(active=True) if self.instance: current_id = self.instance.id active_pages = active_pages.exclude(id=current_id) if hasattr(Site, 'page_set') and 'site' in cleaned_data: active_pages = active_pages.filter(site=cleaned_data['site']) # Convert PK in redirect_to field to something nicer for the future redirect_to = cleaned_data.get('redirect_to') if redirect_to and re.match(r'^\d+$', redirect_to): opts = self.page_model._meta cleaned_data['redirect_to'] = '%s.%s:%s' % ( opts.app_label, get_model_name(opts), redirect_to) if 'active' in cleaned_data and not cleaned_data['active']: # If the current item is inactive, we do not need to conduct # further validation. Note that we only check for the flag, not # for any other active filters. This is because we do not want # to inspect the active filters to determine whether two pages # really won't be active at the same time. return cleaned_data if 'override_url' in cleaned_data and cleaned_data['override_url']: if active_pages.filter( _cached_url=cleaned_data['override_url']).count(): self._errors['override_url'] = ErrorList([ _('This URL is already taken by an active page.')]) del cleaned_data['override_url'] return cleaned_data if current_id: # We are editing an existing page parent = self.page_manager.get(pk=current_id).parent else: # The user tries to create a new page parent = cleaned_data['parent'] if parent: new_url = '%s%s/' % (parent._cached_url, cleaned_data['slug']) else: new_url = '/%s/' % cleaned_data['slug'] if active_pages.filter(_cached_url=new_url).count(): self._errors['active'] = ErrorList([ _('This URL is already taken by another active page.')]) del cleaned_data['active'] if parent and parent.template.enforce_leaf: self._errors['parent'] = ErrorList( [_('This page does not allow attachment of child pages')]) del cleaned_data['parent'] return cleaned_data