示例#1
0
 def __init__(self, user, content, data=None, *args, **kwargs):
     super(HotLinkForm, self).__init__(data, *args, **kwargs)
     self.content = content
     if user.is_superuser:
         choices = BaseSection.objects.all()
     else:
         class_names = ['basesection']
         subclasses = BaseSection.__subclasses__()
         class_names += [subclass.__name__.lower() for subclass in subclasses]
         choices = user.contents_owned.filter(class_name__in=class_names)
     if choices.count() == 1:
         self.fields['section'] = forms.ModelChoiceField(initial=choices[0],
                                                          queryset=choices,
                                                          label='',
                                                          widget=forms.HiddenInput)
     else:
         self.fields['section'] = forms.ModelChoiceField(queryset=choices,
                                                          label=_('Section'),
                                                          required=True,
                                                          help_text=_('Choose a section where save the menu'))
     name_lang = transmeta.get_real_fieldname('name', settings.LANGUAGE_CODE)
     self.fields['slug'].required = False
     if not data:
         self.fields['slug'].label = ''
         self.fields['slug'].widget = forms.HiddenInput()
     self.fields[name_lang].label = _('Name')
     self.fields[name_lang].initial = getattr(content, name_lang, unicode(content))
示例#2
0
 def has_action(self, request, content):
     user = request.user
     if user.is_anonymous():
         return False
     if not self.match_type(content):
         return False
     if user.is_superuser:
         return True
     class_names = ['basesection']
     subclasses = BaseSection.__subclasses__()
     class_names += [subclass.__name__.lower() for subclass in subclasses]
     return user.contents_owned.filter(class_name__in=class_names).exists()