class SceneForm(ModelForm): description = MarkdownxFormField() characters = MarkdownxFormField() encounters = MarkdownxFormField() rewards = MarkdownxFormField() class Meta: model = Scene fields = ("name", "place", "description", "characters", "encounters", "rewards", "sound_effects")
class BookForm(forms.ModelForm): description = MarkdownxFormField() class Meta: model = Book # fields = '__all__' fields = ['name', 'pages', 'status', 'current_price', 'description']
class PageBaseForm(ModelForm): content = MarkdownxFormField() class Meta: model = Page fields = ['title', 'slug', 'exam_date', 'protection', 'content', 'edit_summary'] #labels = {'lat': _('Latitude'), 'lon': _('Longitude'), 'src_link': _('Image Url'), 'src_file': _('Image File')} help_texts = {'edit_summary': _('Briefly describe your changes'),} widgets = { #'tags': CheckboxSelectMultiple(), } def clean_title(self): title = self.cleaned_data['title'] title = title.strip() title = " ".join(w.capitalize() for w in title.split()) return title def clean_slug(self): slug = self.cleaned_data['slug'] slug = slugify(slug) if slug in ['_create', '_update', '_clone', '_move', '_history']: raise ValidationError(_('Slug cannot have this value. (Try using a different word, or not using an underscore at the beginning.)')) if len(slug)>= 1 and not slug[0].isalpha(): raise ValidationError(_('The first character of a slug must be a letter character.)')) return slug def clean_exam_date(self): date = self.cleaned_data['exam_date'] return date def clean_protection(self): protection = self.cleaned_data['protection'] if protection not in ['NO', 'LO', 'CO', 'NC']: raise ValidationError(_('Protection must be one of four values determined by this site. Refresh the page and try again.)')) return protection
class GenericEmailScheduleForm(forms.ModelForm): body_template = MarkdownxFormField( label="Markdown body", widget=AdminMarkdownxWidget, required=True, ) helper = BootstrapHelper( wider_labels=True, add_cancel_button=False, add_submit_button=False, form_tag=False, ) class Meta: model = EmailTemplate fields = [ "slug", "subject", "to_header", "from_header", "cc_header", "bcc_header", "reply_to_header", "body_template", ]
class PostForm(forms.ModelForm): title = forms.CharField(label='Title', max_length=100) text = MarkdownxFormField() class Meta: model = Post fields = ['title', 'text']
class QuestionForm(forms.ModelForm): status = forms.CharField(widget=forms.HiddenInput()) content = MarkdownxFormField() class Meta: model = Question fields = ["title", "content", "tags", "status"]
class EmailMessageForm(forms.ModelForm): message = MarkdownxFormField() image = forms.ImageField(required=False) class Meta: model = EmailMessage fields = ["recipients", "title", "message", 'image']
class MyForm(forms.Form): content = MarkdownxFormField() class Meta: model = Article fields = ['comment']
class PublicacionForm(forms.ModelForm): contenido = MarkdownxFormField() autor = forms.ModelChoiceField(get_user_model().objects.all(), required=False) class Meta: model = Publicacion fields = ['autor', 'titulo', 'fecha_publicacion', 'contenido'] widgets = { 'fecha_publicacion': forms.SelectDateWidget(attrs={'style': 'width: 32%; display: inline-block'}) } def __init__(self, *args, **kwargs): self.helper = FormHelper() self.helper.form_tag = False fecha_publicacion = Div(Field('fecha_publicacion')) fecha_publicacion.css_class = 'col-md-4' titulo = Div(Field('titulo')) titulo.css_class = 'col-md-8' contenido = Div(Field('contenido')) contenido.css_class = 'col-8' tags = Div(Formset('tags')) tags.css_class = 'col-4' row = Div(titulo, fecha_publicacion, contenido, tags) row.css_class = 'row' self.helper.layout = Layout(row) super(PublicacionForm, self).__init__(*args, **kwargs)
class UserCommentForm(forms.ModelForm): bodytext = MarkdownxFormField() class Meta: model = Comment fields = ["bodytext"]
class EventCreateForm(EventForm): comment = MarkdownxFormField( label="Comment", help_text="This will be added to comments after the event is created.", widget=forms.Textarea, required=False, )
class Blog2(forms.Form): title = forms.CharField(max_length=32) # author = forms.CharField(max_length=16) # content = forms.CharField() content = MarkdownxFormField() catagory = forms.CharField() tag = forms.CharField()
def __init__(self, contest_id, user_id, *args, **kwargs): super(StatusForm, self).__init__(*args, **kwargs) self.fields['summary'] = MarkdownxFormField(required=True) cts = Contest.objects.get(id=contest_id) user = User.objects.get(id=user_id) STATUS_OF_AC = [ ('1', 'Solved'), ('2', 'Upsolved'), ('3', 'Not Solved'), ] for i in range(0, cts.num_of_problem): self.fields['p' + str(i)] = forms.ChoiceField(label='Problem ' + chr(ord('A') + i), choices=STATUS_OF_AC) self.initial['p' + str(i)] = '3' # CONTRIBUTOR_FIELD = [ # ('1', user.userprofile.team_member_1), # ('2', user.userprofile.team_member_2), # ('4', user.userprofile.team_member_3), # ] CONTRIBUTOR_FIELD = [ ('1', ""), ('2', ""), ('4', ""), ] self.fields['c' + str(i)] = forms.MultipleChoiceField( label='Contributor', choices=CONTRIBUTOR_FIELD, widget=forms.CheckboxSelectMultiple(), required=False) self.initial['c' + str(i)] = []
class NoteCreateOrUpdateForm(forms.ModelForm): body = MarkdownxFormField() class Meta: model = models.Note fields = "__all__" exclude = ("slug", "writer")
class QuestionForm(forms.ModelForm): status = forms.CharField(widget=forms.HiddenInput()) content = MarkdownxFormField() class Meta: model = Question fields = ['title', 'content', 'tags', 'status']
class CharacterEntryForm(forms.ModelForm): """ A Reverie character form. """ def __init__(self, *args, **kwargs): super(CharacterEntryForm, self).__init__(*args, **kwargs) self.fields['player'] = forms.ModelChoiceField( queryset=self.instance.campaign.players, required=False, widget=forms.Select(), empty_label="----", ) self.fields['is_pc'].label = "Is Player Character" self.fields['slug'].label = "Slug Override (Optional)" description = MarkdownxFormField( widget=ReverieMarkdownWidget() ) class Meta: model = Character fields = ['name', 'tagline', 'image', 'cropping', 'description', 'player', 'is_pc', 'slug'] widgets = { 'image': ImageCropWidget, }
class Meta(): model = Post fields = ('author', 'title', 'text', 'thumbnail') widgets = { 'title': forms.TextInput(attrs={'class': 'textinputclass'}), 'text': MarkdownxFormField() }
class AnswerForm(forms.ModelForm): content = MarkdownxFormField() class Meta: model = Answer fields = [ 'content', ]
class UpdatePageForm(ModelForm): title = CharField(max_length=100) # body = CharField(max_length=2000, widget=Textarea) body2 = MarkdownxFormField() class Meta: model = Page fields = ['body2']
class BlogPostForm(forms.Form): ''' Create or edit blog post ''' title = forms.CharField(max_length=256) thumbnail = forms.ImageField(required=False) preview = forms.CharField(max_length=128) body = MarkdownxFormField()
class Meta: model = Comment fields = ( 'comment_content', ) comment_content = MarkdownxFormField() exclude = ['comment_author'] widgets = {'comment_author': forms.HiddenInput()}
class QuestionForms(forms.ModelForm): content = MarkdownxFormField() class Meta: model = Question fields = ["title", "content", "tags", "status"]
class ArticleForm(forms.ModelForm): status = forms.CharField(widget=forms.HiddenInput()) # 隐藏 edited = forms.BooleanField(widget=forms.HiddenInput(), required=False, initial=False) # 隐藏 content = MarkdownxFormField() class Meta: model = Article fields = ["title", "content", "image", "tags", "status", "edited"]
class Meta: model = Post fields = ['title', 'post_content', 'travel_date'] labels = {'title': '', 'travel_date': '', 'post_content': ''} widgets = { 'post_content': MarkdownxFormField(), 'travel_date': forms.SelectDateWidget(), }
class ArticleForm(forms.ModelForm): content = MarkdownxFormField() status = forms.CharField(widget=forms.HiddenInput()) # 隐藏 edited = forms.BooleanField(widget=forms.HiddenInput(), initial=False, required=False) class Meta: model = Article fields = ['title', 'content', 'image', 'tags', 'status', 'edited']
class NewTopicForm(forms.ModelForm): description = MarkdownxFormField() class Meta: model = Topic fields = ['subject', 'description'] widgets = { 'description': MarkdownxWidget(attrs={'class': 'textarea'}), }
class ArticleForm(forms.ModelForm): """用户发表文章的表单""" edited = forms.BooleanField(widget=forms.HiddenInput(), initial=False, required=False) # initial初始化值,required用户可以不填写 status = forms.CharField(widget=forms.HiddenInput()) # 对用户不可见 content = MarkdownxFormField() class Meta: model = Article fields = ["title", "content", "image", "tags", "status", "edited"]
class MemoForm(forms.ModelForm): content = MarkdownxFormField() class Meta: model = Memo fields = ( 'title', 'content', )
class ProfileForm(forms.ModelForm): """Profile Form + Fields for Photo Processing""" x = forms.FloatField(widget=forms.HiddenInput(), required=False) y = forms.FloatField(widget=forms.HiddenInput(), required=False) width = forms.FloatField(widget=forms.HiddenInput(), required=False) height = forms.FloatField(widget=forms.HiddenInput(), required=False) bio = MarkdownxFormField(validators=[MinLengthValidator(10)]) class Meta: model = Profile fields = [ 'first_name', 'last_name', 'email', 'email_verify', 'date_of_birth', 'bio', 'city', 'state', 'country_of_residence', 'favorite_animal', 'hobby', 'avatar', 'x', 'y', 'width', 'height', ] widgets = { # default date-format %m/%d/%Y will be used 'date_of_birth': DatePickerInput(), } def clean(self): """Clean the whole form""" cleaned_data = super().clean() email = cleaned_data.get('email') verify = cleaned_data.get('email_verify') if email != verify: raise forms.ValidationError('Emails do not match') def save(self): """Override the Save method for saving the crop photo""" photo = super().save() x = self.cleaned_data.get('x') y = self.cleaned_data.get('y') w = self.cleaned_data.get('width') h = self.cleaned_data.get('height') if x is not None: image = Image.open(photo.avatar) cropped_image = image.crop((x, y, w + x, h + y)) resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS) resized_image.save(photo.avatar.path) return photo
class PostCreateForm(forms.ModelForm): content = MarkdownxFormField() class Meta: model = Post exclude = ['date_created', 'date_modified', 'slug', 'author'] help_texts = { 'title': 'Title', 'summary': 'Summary', 'published': 'Published'}