class Meta: model = Job fields = [ 'title', 'description', 'category', 'pay', 'number_of_positions', 'address' ] #styling through bootstrap class in form-control widgets = { 'title': forms.TextInput(attrs={'class': 'form-control'}), 'description': forms.Textarea( attrs={ 'class': 'form-control', 'placeholder': "Describe the job in 3-5 sentences." }), 'category': forms.Select(attrs={'class': 'form-control'}), 'pay': forms.TextInput(attrs={'class': 'form-control'}), 'number_of_positions': forms.NumberInput(attrs={'class': 'form-control'}), 'address': forms.TextInput(attrs={'class': 'form-control'}), }
class NewBlog(ModelForm): title = forms.CharField( max_length=200, required=True, widget=forms.TextInput( attrs={'placeholder': 'Enter Title For the Bog'})) byline = forms.CharField( max_length=400, required=True, widget=forms.TextInput(attrs={'placeholder': 'Enter byline'})) content = forms.CharField( required=False, widget=forms.Textarea(attrs={'placeholder': 'Enter Content'})) class Meta: model = Post exclude = ('slug', 'is_published', 'updated_on', 'created_on', 'publish_on', 'author', 'list_display', 'search_fields', 'list_filter', 'date_hierarchy') def __init__(self, *args, **kwargs): super(NewBlog, self).__init__(*args, **kwargs) self.fields['title'].widget.attrs['class'] = 'input is-medium' self.fields['featured_image'].widget.attrs['id'] = "file" self.fields['byline'].widget.attrs['class'] = 'input is-medium' self.fields['featured_image'].widget.attrs['class'] = 'file-input' self.fields['tags'].widget.attrs['class'] = ' '
class Meta: model = QuestionModule exclude = [] widgets = { 'description': forms.Textarea(attrs={ "rows": 6, "cols": 30 }) }
class Meta: model = Item fields = ('name', 'age', 'sex', 'memo') widgets = { 'name': forms.TextInput(attrs={'placeholder': '記入例:山田 太郎'}), 'age': forms.NumberInput(attrs={'min': 1}), 'sex': forms.RadioSelect(), 'memo': forms.Textarea(attrs={'rows': 4}), }
class Meta: model = AboutUs widgets = { 'content': forms.Textarea(attrs={ "rows": 10, 'cols': 40, "id": "content-editor" }) }
class Meta: model = SuccessStories widgets = { 'content': forms.Textarea(attrs={ "rows": 10, 'cols': 40, "id": "content-editor" }) } exclude = []
class Meta: model = PodanieKomentarze fields = [ 'comment', ] labels = {'comment': 'Dodaj komentarz'} widgets = { 'comment': forms.Textarea(attrs={ 'rows': 4, 'cols': 15 }), }
class CreateUserProfileForm(ModelForm): bio = forms.CharField(required=False, widget=forms.Textarea(attrs={ 'rows': 5, 'cols': 60 })) class Meta: model = UserProfile fields = ('school', 'hide_school', 'major', 'hide_major', 'state', 'city', 'hide_state', 'year', 'hide_year', 'discord_id', 'zoom_id', 'bio') labels = { "hide_state": "Hide Location", }
class PostForm(forms.Form): def __init__(self, *args, **kwargs): kwargs.setdefault( 'label_suffix', '') # globally override the Django >=1.6 default of ':' super(PostForm, self).__init__(*args, **kwargs) """Post Form""" Post = forms.CharField(widget=forms.Textarea( attrs={ "placeholder": "What's going on? Mesmerise us.", "rows": "1", "cols": "50", "autocomplete": "on" })) Pic = forms.FileField(required=False, label="📷 ")
class EditUserProfileForm(ModelForm): bio = forms.CharField(required=False, widget=forms.Textarea(attrs={ 'rows': 5, 'cols': 60 })) class Meta: model = UserProfile # include fields for school, major, state, year, discord/zoom ids, as well as the ability to hide them all fields = ('school', 'hide_school', 'major', 'hide_major', 'state', 'city', 'hide_state', 'year', 'hide_year', 'discord_id', 'zoom_id', 'bio') labels = { "hide_state": "Hide Location", }
class SignUp(forms.Form): """ Sign Up """ Name = forms.CharField( label="Your Name", widget=forms.TextInput(attrs={"placeholder": "It's Nice to meet you"})) username = forms.CharField( max_length=255, widget=forms.TextInput(attrs={"placeholder": "Make it Creative"})) password = forms.CharField( widget=forms.PasswordInput(attrs={"placeholder": "We wont sell it. "}), label="Password") email = forms.EmailField(label="Email Id") DateOfBirth = forms.DateField(label="Date of Birth") Bio = forms.CharField(widget=forms.Textarea( attrs={"placeholder": "Tell us about yourself"})) profilePic = forms.FileField()
class AddWatchersForm(Form): watchers = forms.MultipleChoiceField(choices=get_user_list, widget=forms.CheckboxSelectMultiple()) comment = forms.CharField(widget=forms.Textarea( attrs={'style': 'height: 80px;'}))
class TopographyForm(CleanVulnerableFieldsMixin, TopographyUnitsForm): """ This form is used for editing 1D and 2D topographies. """ class Meta: model = Topography fields = ('size_editable', 'unit_editable', 'height_scale_editable', 'name', 'description', 'measurement_date', 'tags', 'datafile', 'data_source', 'size_x', 'size_y', 'unit', 'is_periodic', 'height_scale', 'fill_undefined_data_mode', 'detrend_mode', 'instrument_name', 'instrument_type', 'instrument_parameters', 'surface') def __init__(self, *args, **kwargs): autocomplete_tags = kwargs.pop('autocomplete_tags') super().__init__(*args, **kwargs) for fn in ['surface', 'data_source']: self.fields[fn].label = False self.helper.form_tag = True self.helper.form_method = 'POST' self.helper.form_show_errors = False # crispy forms has nicer template code for errors self.helper.layout = Layout( Div( Field('surface', readonly=True, hidden=True), Field('data_source', readonly=True, hidden=True), Field('name'), Field('measurement_date'), Field('description'), Field('tags'), Fieldset(*self._size_fieldset_args), Fieldset('Height conversion', Field('height_scale')), Fieldset('Filters', Field('fill_undefined_data_mode'), Field('detrend_mode')), InstrumentLayout(), *self.editable_fields, ), FormActions( Submit('save-stay', 'Save and keep editing'), Submit('save-finish', 'Save and finish editing'), HTML(""" <a href="{% url 'manager:topography-detail' object.id %}" class="btn btn-default" id="cancel-btn"> Finish editing without saving</a> """), ), ASTERISK_HELP_HTML) self.fields['tags'] = TagField( required=False, autocomplete_tags=autocomplete_tags, # set special values for user help_text=TAGS_HELP_TEXT, ) datafile = forms.FileInput() measurement_date = forms.DateField( widget=DatePickerInput(format=MEASUREMENT_DATE_INPUT_FORMAT), help_text=MEASUREMENT_DATE_HELP_TEXT) description = forms.Textarea() is_periodic = make_is_periodic_field()
class TopographyMetaDataForm(CleanVulnerableFieldsMixin, forms.ModelForm): """ Form used for meta data 'data source' (channel), name of measurement, description and tags. """ class Meta: model = Topography fields = ('name', 'description', 'measurement_date', 'data_source', 'tags') def __init__(self, *args, **kwargs): data_source_choices = kwargs.pop('data_source_choices') autocomplete_tags = kwargs.pop('autocomplete_tags') self._surface = kwargs.pop('surface') super(TopographyMetaDataForm, self).__init__(*args, **kwargs) self.fields['data_source'] = forms.ChoiceField( choices=data_source_choices) self.fields['tags'] = TagField(required=False, autocomplete_tags=autocomplete_tags, help_text=TAGS_HELP_TEXT) measurement_date_help_text = MEASUREMENT_DATE_HELP_TEXT if self.initial['measurement_date']: measurement_date_help_text += f" The date \"{self.initial['measurement_date']}\" is the latest date " \ "we've found over all channels in the data file." else: measurement_date_help_text += f" No valid measurement date could be read from the file." self.fields['measurement_date'] = forms.DateField( widget=DatePickerInput(format=MEASUREMENT_DATE_INPUT_FORMAT), help_text=measurement_date_help_text) helper = FormHelper() helper.form_method = 'POST' helper.form_show_errors = False # crispy forms has nicer template code for errors helper.form_tag = False name = forms.CharField() description = forms.Textarea() helper.layout = Layout( Div( Field('data_source'), Field('name'), Field('measurement_date'), Field('description'), Field('tags'), ), FormActions( Submit('save', 'Next'), HTML(""" <a href="{{ cancel_action }}" class="btn btn-default" id="cancel-btn">Cancel</a> """), ), ASTERISK_HELP_HTML) def clean_name(self): name = super().clean_name() if Topography.objects.filter(name=name, surface=self._surface).exists(): msg = f"A topography with same name '{name}' already exists for same surface" raise forms.ValidationError( msg, code='duplicate_topography_name_for_same_surface') return name