def __init__(self, *args, **kwargs): # Check if form is in editing mode editing = False if 'editing' in kwargs: editing = kwargs.pop('editing') user_uri = kwargs.pop('user_uri') choices = [None] + p2pu_user_api.get_partners_for_user(user_uri) published = False if 'published' in kwargs: published = kwargs.pop('published') super(BadgeForm, self).__init__(*args, **kwargs) # stack choices for partner self.fields['partner'].choices = [(0, '----') if name is None else (name, name)for name in choices] # if form in in editing mode image does not need to be required if editing: self.fields['image_uri'].required = False self.fields['image_uri'].help_text = _('If you are satisfied with the image ' 'you uploaded previously than leave this field blank') # if badge has already been published than edit is limited only to requirements field if published: self.fields['image_uri'].widget.attrs['readonly'] = True self.fields['title'].widget.attrs['readonly'] = True self.fields['description'].widget.attrs['readonly'] = True
def __init__(self, *args, **kwargs): # Check if form is in editing mode editing = False if 'editing' in kwargs: editing = kwargs.pop('editing') user_uri = kwargs.pop('user_uri') choices = [None] + p2pu_user_api.get_partners_for_user(user_uri) super(BadgeForm, self).__init__(*args, **kwargs) # stack choices for partner self.fields['partner'].choices = [(0, '----') if name == None else (name, name)for name in choices] # if form in in editing mode image does not need to be required if editing: self.fields['image_uri'].required = False self.fields['image_uri'].help_text=_('If you are satisfied with the image you uploaded previously than leave this field blank')