class Meta: model = Discussion fields = ('title', 'description', 'location_desc', 'tags', 'parent_url', 'parent_url_text', 'picture') widgets = { 'title': forms.Textarea(attrs={ 'rows': 1, 'cols': 40 }), 'description': forms.Textarea(attrs={ 'rows': 10, 'cols': 40 }), 'location_desc': forms.Textarea(attrs={ 'rows': 1, 'cols': 40 }), 'tags': TagWidgetBig(attrs={ 'rows': 3, 'cols': 40 }), 'parent_url': forms.Textarea(attrs={ 'rows': 1, 'cols': 40 }), 'parent_url_text': forms.Textarea(attrs={ 'rows': 1, 'cols': 40 }), 'picture': forms.ClearableFileInput, }
class Meta: model = Feedback fields = [ 'rating', 'interest', 'comments', 'notes', ] widgets = { 'rating': RadioNoULInput, 'interest': RadioNoULInput, 'comments': forms.Textarea(attrs={'rows': 4}), 'notes': forms.Textarea(attrs={'rows': 4}), }
class UpdateDiscussionForm(forms.Form): description = forms.CharField(max_length=MAX_MESSAGE_INPUT_CHARS, label=u'תאור הפעילות', help_text=u'תאור היעד ואיזו עזרה מבוקשת', widget=forms.Textarea(attrs={ 'rows': '3', 'cols': '40' })) m_tags = TagField(required=False, label='תגיות', help_text=u'רשימה של תגים מופרדת עם פסיקים.', widget=forms.Textarea(attrs={ 'rows': '3', 'cols': '40' }))
class Meta: widgets = { 'sender': forms.TextInput(), 'email': forms.TextInput(), 'subject': forms.Select(), 'message': forms.Textarea(), }
class Meta: model = Issue fields = [ 'title', 'body', ] widgets = {'body': forms.Textarea(attrs={'rows': 5})}
class AddDecisionForm(forms.Form): content = forms.CharField(max_length=MAX_MESSAGE_INPUT_CHARS, label='', widget=forms.Textarea(attrs={ 'rows': '3', 'class': 'form-control' }))
class EscalationMessageForm(forms.Form): subject = forms.CharField( label=_("Subject"), max_length=230, widget=forms.TextInput(attrs={"class": "form-control"})) message = forms.CharField( widget=forms.Textarea(attrs={"class": "form-control"}), label=_("Your message"), ) def __init__(self, foirequest, *args, **kwargs): super(EscalationMessageForm, self).__init__(*args, **kwargs) self.foirequest = foirequest def clean_message(self): message = self.cleaned_data['message'] message = message.replace('\r\n', '\n').strip() empty_form = self.foirequest.get_escalation_message_form() if message == empty_form.initial['message'].strip(): raise forms.ValidationError( _('You need to fill in the blanks in the template!')) return message def clean(self): throttle_message = check_throttle(self.foirequest.user, FoiMessage) if throttle_message: raise forms.ValidationError(throttle_message) def save(self): self.foirequest.add_escalation_message(**self.cleaned_data)
class Meta: model = Profile fields = ('first_name', 'last_name', 'about', 'photo', 'phone', 'website', 'twitter') widgets = { 'about': forms.Textarea(attrs={ 'rows': 2, 'class': 'form-control' }), 'first_name': forms.TextInput(attrs={'class': 'form-control'}), 'last_name': forms.TextInput(attrs={'class': 'form-control'}), 'phone': forms.TextInput(attrs={ 'class': 'form-control', 'placeholder': 'Not publicly displayed' }), 'website': forms.URLInput(attrs={ 'class': 'form-control', 'placeholder': 'Include http://' }), #'twitter': TwitterTextInput(), 'twitter': forms.TextInput(attrs={'class': 'form-control'}), 'photo': SimpleFileInput(), }
def __init__(self, *args, **kwargs): super(FlatPageForm, self).__init__(*args, **kwargs) # Revert widget modifications done by MapentityForm.__init__() for fieldname in self.fields.keys(): if fieldname.startswith('content_'): self.fields[fieldname].widget = forms.Textarea() self.fields['source'].help_text = None self.fields['portal'].help_text = None
class NewDiscussionForm(forms.Form): title = forms.CharField(label=_("title"), max_length=200, widget=forms.Textarea(attrs={ 'rows': '1', 'cols': '100' })) description = forms.CharField(label=_("description"), max_length=MAX_MESSAGE_INPUT_CHARS, widget=forms.Textarea(attrs={ 'rows': '6', 'cols': '100' })) location_desc = forms.CharField(label=u'כתובת', required=False, max_length=MAX_MESSAGE_INPUT_CHARS, widget=forms.Textarea(attrs={ 'rows': '1', 'cols': '100' })) tags = forms.CharField(required=False, label=u'תגיות מופרדות בפסיקים', widget=TagWidgetBig(attrs={ 'rows': 3, 'cols': 40 })) # parent_url = forms.URLInput(label=u"דף קשור", max_length=200, # widget=forms.Textarea( # attrs={'rows': '1', 'cols': '100'})) parent_url = forms.URLField( label=u'קישור לדף רלוונטי. לדוגמה http://hp.com', required=False, max_length=MAX_TEXT) parent_url_text = forms.CharField(label=u"שם הדף הקשור", required=False, max_length=MAX_TEXT, widget=forms.Textarea(attrs={ 'rows': '1', 'cols': '100' })) picture = forms.ImageField(required=False)
class AddTaskForm(forms.Form): goal_description = forms.CharField( max_length=MAX_MESSAGE_INPUT_CHARS, label='', widget=forms.Textarea(attrs={ 'rows': '3', 'class': 'form-control' })) target_date = forms.DateTimeField(widget=SelectDateWidget)
class Meta: model = McUser fields = [ 'title', 'first_name', 'real_name', 'last_name', 'maiden_name', 'birthday', 'gender', 'class_year', 'hometown', 'hometown_state', 'high_school', 'phone_number', 'id', 'pic', 'staff_title', 'staff_phone', 'linkedin', 'website', 'facebook', 'email', 'dorm_type', 'dorm_number', 'mailing_address', 'mailing_city', 'mailing_state', 'mailing_zip', 'mailing_country', 'mailing_address_type', 'in_dfw', 'current_city', 'significant_other', 'children', 'personal_news', ] widgets = { 'id': forms.HiddenInput(), 'pic': ImageThumbnailInput, 'birthday': DateInput(), 'mailing_address_type': forms.Select(choices=(('', ''), ('parent', 'parent address'), ('alum', 'current alum address'))), 'in_dfw': forms.Select(choices=(('', ''), ('Yes', 'Yes'), ('No', 'No'))), 'title': forms.Select(choices=TITLE_CHOICES), 'personal_news': forms.Textarea(attrs={ 'rows': 4, 'cols': 15 }), }
class SendMessageForm(forms.Form): to = forms.TypedChoiceField( label=_("To"), choices=[], coerce=int, required=True, widget=forms.RadioSelect(attrs={"class": "form-control"})) subject = forms.CharField( label=_("Subject"), max_length=230, widget=forms.TextInput(attrs={"class": "form-control"})) message = forms.CharField( widget=forms.Textarea(attrs={"class": "form-control"}), label=_("Your message")) def __init__(self, foirequest, *args, **kwargs): super(SendMessageForm, self).__init__(*args, **kwargs) self.foirequest = foirequest choices = [(0, _("Default address of %(publicbody)s") % { "publicbody": foirequest.public_body.name })] choices.extend([ (m.id, m.reply_address_entry) for k, m in foirequest.possible_reply_addresses().items() ]) self.fields['to'].choices = choices if foirequest.law and foirequest.law.email_only: self.fields['send_address'] = forms.BooleanField( label=_("Send physical address"), help_text=(_( 'If the public body is asking for your post ' 'address, check this and we will append it to your message.' )), required=False) def save(self, user): if self.cleaned_data["to"] == 0: recipient_name = self.foirequest.public_body.name recipient_email = self.foirequest.public_body.email recipient_pb = self.foirequest.public_body else: message = list( filter(lambda x: x.id == self.cleaned_data["to"], list(self.foirequest.messages)))[0] recipient_name = message.sender_name recipient_email = message.sender_email recipient_pb = message.sender_public_body return self.foirequest.add_message(user, recipient_name, recipient_email, self.cleaned_data["subject"], self.cleaned_data['message'], recipient_pb=recipient_pb, send_address=self.cleaned_data.get( 'send_address', True))
class Meta: model = AdContact widgets = { 'message': forms.Textarea(attrs={ 'class': 'form-control', 'rows': 3, 'placeholder': 'Votre message' }), } exclude = ['user', 'content_type', 'object_pk']
class CommentForm(forms.ModelForm): comment = forms.CharField( label='', widget=forms.Textarea(attrs={ 'rows': 2, 'placeholder': 'Add your comment here' })) class Meta: model = Comment fields = ['comment']
class Meta: model = Shop fields = ( 'title', 'description', 'currency_name', ) widgets = { 'title': forms.Textarea(attrs={ 'rows': '1', 'cols': '50' }), 'description': forms.Textarea, }
class EscalationMessageForm(forms.Form): subject = forms.CharField(label=_("Subject"), widget=forms.TextInput(attrs={"class": "span5"})) message = forms.CharField( widget=forms.Textarea(attrs={"class": "span5"}), label=_("Your message"), ) def __init__(self, foirequest, *args, **kwargs): super(EscalationMessageForm, self).__init__(*args, **kwargs) self.foirequest = foirequest def save(self): self.foirequest.add_escalation_message(**self.cleaned_data)
class Meta: model = Comment fields = [ "text", ] widgets = { 'text': forms.Textarea( attrs={ 'rows': 4, 'class': 'form-control', 'placeholder': 'Add a comment...' }), }
class Meta: model = Experience fields = [ 'user', 'exp_type', 'title', 'organization', 'description', 'location', 'start_time', 'end_time' ] widgets = { 'user': forms.HiddenInput(), 'description': forms.Textarea(attrs={ 'rows': 4, 'cols': 15 }), 'start_time': DateInput(), 'end_time': DateInput(), }
class UserChangeAddressForm(forms.Form): address = forms.CharField(max_length=300, label=_('Mailing Address'), help_text=_('Your address will never be displayed publicly.'), widget=forms.Textarea(attrs={'placeholder': _('Street, Post Code, City'), 'class': 'inline smalltext'})) def __init__(self, profile, *args, **kwargs): super(UserChangeAddressForm, self).__init__(*args, **kwargs) self.profile = profile self.fields['address'].initial = self.profile.address def save(self): self.profile.address = self.cleaned_data['address'] self.profile.save()
class Meta: model = StudyAbroad fields = [ 'user', 'study_abroad_type', 'organization', 'description', 'primary_location', 'other_locations', 'start_time', 'end_time' ] widgets = { 'user': forms.HiddenInput(), 'description': forms.Textarea(attrs={ 'rows': 4, 'cols': 15 }), 'start_time': DateInput(), 'end_time': DateInput(), }
class ContactForm(forms.Form): name = forms.CharField(required=True) email = forms.EmailField(required=True) subject = forms.CharField(required=forms.Textarea) # http://stackoverflow.com/questions/1694447/how-to-set-an-event-handler-in-a-django-form-input-field # https://chriskief.com/2012/12/16/override-django-form-is_valid/ # http://stackoverflow.com/questions/30424394/django-forms-how-to-override-field-validation # overriding field validation # Creating drop-down list sales = "Sales" marketing = "Marketing" hr = "Recruitment" customer = "customers" it = "IT" other = "Other/Not Specified" dep_choices = {(sales, 'Sales'), (marketing, 'Marketing'), (hr, 'Recruitment'), (it, 'IT'), (customer, 'Customers'), (other, 'Other/Not Specified')} # choice field would be tracked # http://stackoverflow.com/questions/1694447/how-to-set-an-event-handler-in-a-django-form-input-field # http://stackoverflow.com/questions/1355150/django-when-saving-how-can-you-check-if-a-field-has-changed # triggering changes inside current contact form instance # from experiments I found that 'attrs' below executes pure javascript # so I just used javascript to update image department = forms.ChoiceField( choices=dep_choices, # widget=forms.Select(attrs={'onchange': "alert(this.value)"})) widget=forms.Select(attrs={'onchange': 'changepic(this.value)'})) # set initial state department.initial = {'other', 'Other/Not Specified'} # http://stackoverflow.com/questions/16076420/django-dropdownlist-onchange-submission message = forms.CharField(widget=forms.Textarea( attrs={'style': 'resize:allow;'})) def __init__(self, *args, **kwargs): self.helper = FormHelper() self.helper.add_input(Submit('submit', 'Submit')) # self.initial['department'] = ... # possible variant here # http://herself.movielady.net/2012/12/15/initial-value-in-djangos-admin-for-a-choice-field/ super(ContactForm, self).__init__(*args, **kwargs)
class Meta: model = Product fields = ( 'title', 'description', 'item_price', 'number_of_abailabale_items', 'end_of_sale_at', 'end_of_use_at', ) widgets = { 'title': forms.Textarea(attrs={ 'rows': '1', 'cols': '50' }), 'description': forms.Textarea, 'end_of_sale_at': forms.DateInput, 'end_of_use_at': forms.DateInput, }
class Meta: model = Sprint widgets = { 'name': forms.TextInput, 'slug': SlugInput, 'start_date': date5, 'end_date': date5, 'notes': forms.Textarea(attrs={ 'class': 'span5', }), } fields = ( 'name', 'slug', 'start_date', 'end_date', 'notes', 'team', )
class Meta: model = Page fields = ('website', 'parent', 'title', 'slug', 'draft', 'app_page_type', 'is_diplayed_in_menu', 'menu_title', 'meta_keywords', 'meta_description', 'default_template') widgets = { 'meta_description': forms.Textarea(attrs={'cols': 40, 'rows': 5}), 'website': forms.HiddenInput(), 'slug': SlugWidget('title'), 'parent': forms.HiddenInput(attrs={'value': ""}), }
class UserChangeForm(forms.Form): email = forms.EmailField(required=False, widget=forms.EmailInput( attrs={ 'placeholder': _('*****@*****.**'), 'class': 'form-control' }), label=_('Your email address')) address = forms.CharField(max_length=300, label=_('Your mailing address'), help_text=_('Your address will never be displayed publicly.'), widget=forms.Textarea(attrs={'placeholder': _('Street, Post Code, City'), 'class': 'form-control'})) field_order = ['email', 'newsletter', 'address'] def __init__(self, user, *args, **kwargs): super(UserChangeForm, self).__init__(*args, **kwargs) self.user = user self.fields['address'].initial = self.user.address self.fields['email'].initial = self.user.email if HAVE_NEWSLETTER(): self.fields['newsletter'] = forms.BooleanField(required=False, label=_("Newsletter")) self.fields['newsletter'].initial = self.user.newsletter self.order_fields(self.field_order) def clean_email(self): email = self.cleaned_data['email'].lower() if (self.user.email != email and get_user_model().objects.filter(email=email).exists()): raise forms.ValidationError( _('Another user with that email address already exists!') ) return email def save(self): self.user.address = self.cleaned_data['address'] if HAVE_NEWSLETTER(): self.user.newsletter = self.cleaned_data['newsletter'] self.user.save()
class EventForm(forms.Form): name = forms.CharField(widget=forms.TextInput( attrs={'placeholder': 'name your event'})) date = forms.DateTimeField(widget=forms.SplitDateTimeWidget) location = forms.CharField(widget=forms.TextInput( attrs={'placeholder': 'address'})) city = forms.CharField(widget=forms.TextInput( attrs={'placeholder': 'city'})) category = forms.ChoiceField(choices=CategoryOptions().CATEGORY_OPTIONS) description = forms.CharField(widget=forms.Textarea( attrs={'placeholder': 'don\'t be shy - tell us about it some more'})) budget = forms.IntegerField() max_people = forms.IntegerField() is_vegan = forms.BooleanField(required=False) is_kosher = forms.BooleanField(required=False) is_vegeterian = forms.BooleanField(required=False) rsvp = forms.ChoiceField(widget=forms.RadioSelect, choices=RsvpOptions().RSVP_OPTIONS) picture = forms.ImageField()
class Meta: model = InterviewerFeedback fields = [ 'checkbox_1', 'checkbox_2', 'checkbox_3', 'checkbox_4', 'checkbox_5', 'checkbox_6', 'checkbox_7', 'checkbox_8', 'checkbox_9', 'checkbox_10', 'checkbox_11', 'checkbox_12', 'checkbox_13', 'checkbox_14', 'checkbox_15', 'checkbox_16', 'checkbox_17', 'checkbox_18', 'question_1', 'question_2', 'question_3', 'question_4', 'question_5', 'question_6', 'rating', 'comments', ] widgets = { 'rating': RadioNoULInput, 'question_1': forms.Textarea(attrs={'rows': 4}), 'question_2': forms.Textarea(attrs={'rows': 4}), 'question_3': forms.Textarea(attrs={'rows': 4}), 'question_4': forms.Textarea(attrs={'rows': 4}), 'question_5': forms.Textarea(attrs={'rows': 4}), 'question_6': forms.Textarea(attrs={'rows': 4}), 'comments': forms.Textarea(attrs={'rows': 4}), }
class Meta: model = McEvent fields = [ # 'owner', 'id', 'subject', 'start_date', 'start_time', 'end_date', 'end_time', 'all_day_event', 'description', 'location', 'private', #'relevant_years', ] widgets = { 'id': forms.HiddenInput(), 'start_date': DateInput(), 'start_time': TimeInput(), 'end_date': DateInput(), 'end_time': TimeInput(), 'description': forms.Textarea(attrs={'rows':4}), }
class PostalReplyForm(forms.Form, PostalScanMixin): scan_help_text = mark_safe( _("Uploaded scans can be PDF, JPG or PNG. Please make sure to <strong>redact/black out all private information concerning you</strong>." )) date = forms.DateField( widget=forms.TextInput(attrs={ "class": "form-control", "placeholder": _('mm/dd/YYYY') }), label=_("Send Date"), help_text=_("Please give the date the reply was sent."), localize=True) sender = forms.CharField( label=_("Sender Name"), widget=forms.TextInput(attrs={ "class": "form-control", "placeholder": _("Sender Name") }), required=True) subject = forms.CharField( label=_("Subject"), required=False, max_length=230, widget=forms.TextInput(attrs={ "class": "form-control", "placeholder": _("Subject") })) text = forms.CharField( label=_("Letter"), widget=forms.Textarea( attrs={ "placeholder": _("Letter text you have received"), "class": "form-control" }), required=False, help_text= _("The text can be left empty, instead you can upload scanned documents." )) scan = forms.FileField(label=_("Scanned Letter"), required=False, help_text=scan_help_text) not_publishable = forms.BooleanField( label=_("You are not allowed to publish some received documents"), initial=False, required=False, help_text= _('If the reply explicitly states that you are not allowed to publish some of the documents (e.g. due to copyright), check this.' )) def clean_date(self): date = self.cleaned_data['date'] now = timezone.now().date() if date > now: raise forms.ValidationError( _("Your reply date is in the future, that is not possible.")) return date def clean(self): cleaned_data = self.cleaned_data text = cleaned_data.get("text") scan = cleaned_data.get("scan") if not (text or scan): raise forms.ValidationError( _("You need to provide either the letter text or a scanned document." )) return cleaned_data