class AskForm(forms.Form): """the form used to openode questions field ask_anonymously is shown to the user if the if ALLOW_ASK_ANONYMOUSLY live setting is True however, for simplicity, the value will always be present in the cleaned data, and will evaluate to False if the settings forbids anonymous asking """ title = TitleField() text = WysiwygFormField(widget=Wysiwyg(mode="full")) def __init__(self, *args, **kwargs): self.user = kwargs.pop('user') self.node = kwargs.pop('node') allow_tags = kwargs.pop("allow_tags", True) super(AskForm, self).__init__(*args, **kwargs) if allow_tags and self.user.has_perm('openode.change_tag'): self.fields['tags'] = TagNamesField() self.fields["text"].widget = Wysiwyg(mode="full", upload_url=reverse_lazy( "upload_attachment_node", args=[self.node.pk]))
def __init__(self, *args, **kwargs): node = kwargs.pop("node") super(NodeAnnotationEditForm, self).__init__(*args, **kwargs) upload_url = reverse_lazy("upload_attachment_node", args=[node.pk]) self.fields["text"].widget = Wysiwyg(mode="full", upload_url=upload_url)
class OrganizationForm(forms.ModelForm): desc = forms.CharField(widget=Wysiwyg(mode='simple', width='800px'), required=False, label=_('description')) class Meta: model = Organization fields = ('title', 'long_title', 'desc', 'logo', 'preapproved_emails', 'preapproved_email_domains') def __init__(self, *args, **kwargs): super(OrganizationForm, self).__init__(*args, **kwargs) if self.instance and self.instance.description: self.fields['desc'].initial = self.instance.description.text def save(self, request, force_insert=False, force_update=False, commit=True): org = super(OrganizationForm, self).save(commit=True) org.approved = False description = self.cleaned_data['desc'] request.user.post_object_description(org, body_text=description) org.save() return org
class OrganizationLogoForm(forms.ModelForm): desc = forms.CharField(widget=Wysiwyg(mode='simple', width='800px'), required=False, label=_('description')) class Meta: fields = ("logo", ) model = Organization
class DiscussionAddForm(AskForm): """the form used to openode questions field ask_anonymously is shown to the user if the if ALLOW_ASK_ANONYMOUSLY live setting is True however, for simplicity, the value will always be present in the cleaned data, and will evaluate to False if the settings forbids anonymous asking """ text = WysiwygFormField(widget=Wysiwyg(), required=False)
def __init__(self, *args, **kwargs): super(PerexesEditForm, self).__init__(*args, **kwargs) upload_url = reverse_lazy("upload_attachment_node", args=[self.instance.pk]) for key in Node.WYSIWYG_FIELDS: if key not in self.fields: continue self.fields[key].widget = Wysiwyg(mode="full", upload_url=upload_url)
def __init__(self, answer, revision, *args, **kwargs): self.answer = answer super(EditAnswerForm, self).__init__(*args, **kwargs) #it is important to add this field dynamically self.fields['text'] = WysiwygFormField( min_length=openode_settings.MIN_ANSWER_BODY_LENGTH) self.fields['text'].widget = Wysiwyg( mode="full", upload_url=reverse_lazy("upload_attachment_node", args=[self.answer.thread.node.pk])) self.fields['text'].initial = revision.text
def __init__(self, *args, **kwargs): self.user = kwargs.pop('user') self.node = kwargs.pop('node') allow_tags = kwargs.pop("allow_tags", True) super(AskForm, self).__init__(*args, **kwargs) if allow_tags and self.user.has_perm('openode.change_tag'): self.fields['tags'] = TagNamesField() self.fields["text"].widget = Wysiwyg(mode="full", upload_url=reverse_lazy( "upload_attachment_node", args=[self.node.pk]))
def __init__(self, *args, **kwargs): self.node = kwargs.pop("node") super(AnswerForm, self).__init__(*args, **kwargs) self.fields['email_notify'].widget.attrs[ 'id'] = 'question-subscribe-updates' self.fields[ "text"].min_length = openode_settings.MIN_ANSWER_BODY_LENGTH self.fields["text"].widget = Wysiwyg(mode="full", upload_url=reverse_lazy( "upload_attachment_node", args=[self.node.pk]))
class ClassicRegisterForm(SetPasswordForm): """ legacy registration form """ next = NextUrlField() first_name = CleanCharField(max_length=30) last_name = CleanCharField(max_length=30) display_name = CleanCharField(max_length=23, required=False, min_length=6) email = UserEmailField() user_description = forms.CharField(required=False, widget=Wysiwyg(mode='simple')) login_provider = PasswordLoginProviderField() one_plus_one = forms.IntegerField(required=True) def clean_one_plus_one(self): one_plus_one = self.cleaned_data['one_plus_one'] if one_plus_one != 2: raise forms.ValidationError(_('Please, enable javascript in your browser.'))
class EditUserForm(forms.Form): # email = forms.EmailField( # label=u'Email', # required=True, # max_length=255, # widget=forms.TextInput(attrs={'size': 35}) # ) first_name = CleanCharField( required=True, max_length=30, widget=forms.TextInput() ) last_name = CleanCharField( required=True, max_length=30, widget=forms.TextInput() ) display_name = CleanCharField( required=False, max_length=25, widget=forms.TextInput() ) user_description = forms.CharField( required=False, widget=Wysiwyg(mode='simple') ) privacy_email_form = forms.BooleanField(required=False) privacy_show_followed = forms.BooleanField(required=False) def __init__(self, user, *args, **kwargs): super(EditUserForm, self).__init__(*args, **kwargs) logging.debug('initializing the form') # self.fields['email'].initial = user.email self.fields['first_name'].initial = user.first_name self.fields['last_name'].initial = user.last_name self.fields['display_name'].initial = user.display_name self.fields['user_description'].initial = user.description.text if user.description else '' self.fields['privacy_email_form'].initial = user.privacy_email_form self.fields['privacy_show_followed'].initial = user.privacy_show_followed self.user = user
def __init__(self, *args, **kwargs): """ overwrite default simple wysiwyg """ super(NodeAdminForm, self).__init__(*args, **kwargs) widget_attrs = { "mode": "full", "width": "800px", } if self.instance.pk: widget_attrs.update({ "upload_url": reverse_lazy("upload_attachment_node", args=[self.instance.pk]) }) for key in Node.WYSIWYG_FIELDS: self.fields[key].widget = Wysiwyg(**widget_attrs)
class OrganizationAdminForm(BaseAdminModelForm): class Meta: fields = ( 'approved', 'title', 'long_title', 'logo', 'desc', 'openness', 'preapproved_emails', 'preapproved_email_domains', ) desc = forms.CharField(widget=Wysiwyg(mode='simple', width='800px'), required=False, label=_('description')) def __init__(self, *args, **kwargs): super(OrganizationAdminForm, self).__init__(*args, **kwargs) if self.instance and self.instance.description: self.fields['desc'].initial = self.instance.description.text
def __init__(self, *args, **kwargs): """populate EditQuestionForm with initial data""" self.main_post = kwargs.pop('main_post') self.user = kwargs.pop('user') # preserve for superclass revision = kwargs.pop('revision') self.node = kwargs.pop('node') text_required = kwargs.pop("text_required", True) super(EditQuestionForm, self).__init__(*args, **kwargs) #it is important to add this field dynamically self.fields['text'] = WysiwygFormField() self.fields['text'].widget = Wysiwyg(mode="full", upload_url=reverse_lazy( "upload_attachment_node", args=[self.node.pk])) self.fields['text'].initial = revision.text self.fields['text'].required = text_required # TODO: use Thread.can_retag method if self.user.has_perm('openode.change_tag'): self.fields['tags'] = TagNamesField() self.fields['tags'].initial = revision.tagnames self.fields['title'].initial = revision.title self.fields['allow_external_access'] = forms.BooleanField( label=_('Allow external access'), initial=self.main_post.thread.external_access, required=False) self.fields["category"] = TreeNodeChoiceField( queryset=self.main_post.thread.node.thread_categories.all(), initial=self.main_post.thread.category, required=False, )
class OpenidRegisterForm(forms.Form): """ openid signin form """ next = NextUrlField() display_name = CleanCharField(max_length=255, required=False) email = UserEmailField() user_description = forms.CharField(required=False, widget=Wysiwyg(mode='simple'))
class ProxyUserAdminForm(BaseAdminModelForm): class Meta: fields = ('first_name', 'last_name', 'display_name', 'email', 'password_1', 'password_2', 'desc', 'is_active', 'is_staff', 'is_hidden', 'groups') model = models.ProxyUser desc = forms.CharField(widget=Wysiwyg(mode='simple'), required=False, label=capfirst(_('description'))) password_1 = forms.CharField(widget=forms.PasswordInput, label=_('Password'), min_length=const.PASSWORD_MIN_LENGTH) password_2 = forms.CharField(widget=forms.PasswordInput, label=_('Password retyped')) def __init__(self, *args, **kwargs): super(ProxyUserAdminForm, self).__init__(*args, **kwargs) if self.instance and self.instance.description: self.fields['desc'].initial = self.instance.description.text self.fields['email'].required = True self.fields['groups'].help_text = _( 'Don\'t forget to activate Staff status field.') self.fields['groups'].widget = FilteredSelectMultiple( self.fields['groups'].label, False, attrs=self.fields['groups'].widget.attrs, choices=self.fields['groups'].widget.choices) self.fields['password_1'].required = not bool(self.instance) self.fields['password_1'].widget = forms.PasswordInput() self.fields['password_2'].required = not bool(self.instance) def clean(self): cl_data = super(ProxyUserAdminForm, self).clean() email = cl_data.get('email') if email: if self.instance: qs = User.objects.exclude(pk=self.instance.pk) else: qs = User.objects.all() if qs.filter(email=email).exists(): raise forms.ValidationError( _('Account with this email already exists.')) if cl_data.get('password_1') and cl_data.get('password_2'): if cl_data['password_1'] != cl_data['password_2']: raise forms.ValidationError(_('Passwords did not match')) return cl_data def save(self, commit=True): instance = super(ProxyUserAdminForm, self).save(commit=False) ''' set password ''' cl_data = self.cleaned_data if cl_data.get('password_1') and cl_data['password_1'] != '': instance.set_password(cl_data['password_1']) ''' username is the same as email ''' instance.username = cl_data['email'] if commit: instance.save() self.save_m2m() return instance
class Meta: widgets = {'text': Wysiwyg(mode='full', width="800px")}