class IssueForm(forms.Form): issue_title = forms.CharField(widget=forms.TextInput( attrs={ 'class': 'form-control form-control-user', 'placeholder': "Title" })) content = MDTextFormField()
class CalendrierForm(forms.ModelForm): # titre = forms.CharField(label="Titre") description = MDTextFormField(label="le Calendrier") class Meta: model = Calendrier fields = "__all__"
class PostForm(forms.Form): title=forms.CharField(label="标题", max_length=25, widget=forms.TextInput( attrs={'class': 'form-control', 'placeholder': "文章标题", 'autofocus': ''})) post=MDTextFormField() excerpt=forms.CharField(label="标题", max_length=125, widget=forms.TextInput( attrs={'class': 'form-control', 'placeholder': "文章摘要", 'autofocus': ''})) category=forms.CharField(widget=forms.Select( attrs={'class': 'form-control select2', 'data-placeholder': '点击选择类别'})) tag=forms.CharField(widget=forms.SelectMultiple( attrs={'class': 'form-control select2', 'multiple': 'multiple','data-placeholder': '点击添加标签'})) def __init__(self,*args,**kwargs): super(PostForm, self).__init__(*args,**kwargs) categorys = Category.objects.all() cate_lst = [] for i in categorys: cate_lst.append((i.id, i.name)) self.fields['category'].widget.choices = cate_lst tags = Tag.objects.all() tag_lst = [] for i in tags: tag_lst.append((i.id, i.name)) print(tag_lst) self.fields['tag'].widget.choices = tag_lst
class AdminPostForm(PostFormMixin, forms.ModelForm): title = forms.CharField( label=_("Title"), max_length=90, widget=forms.TextInput(attrs={"style": "width: 50%;"}), ) slug = forms.CharField( label=_("Slug"), widget=forms.TextInput(attrs={"style": "width: 50%;"})) teaser = forms.CharField( label=_("Teaser"), widget=forms.Textarea(attrs={"style": "width: 80%;"}), ) content = MDTextFormField() description = forms.CharField( label=_("Description"), widget=forms.Textarea(attrs={"style": "width: 80%;"}), required=False) class Meta: model = Post fields = FIELDS class Media: js = settings.PINAX_BLOG_ADMIN_JS def save(self, blog=None): post = super().save(commit=False) if blog: post.blog = blog return self.save_post(post)
class PostForm(PostFormMixin, forms.ModelForm): markup_choice = "markdown" teaser = forms.CharField(widget=forms.Textarea()) content = MDTextFormField() class Meta: model = Post fields = [ "section", "title", "teaser", "content", "description", "state" ] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if Section.objects.count() < 2: self.section = Section.objects.first() del self.fields["section"] else: self.section = None def save(self, blog=None, author=None): post = super().save(commit=False) if blog: post.blog = blog if author: post.author = author post.image_set = ImageSet.objects.create(created_by=author) if self.section: post.section = self.section post.slug = slugify(post.title) post.markup = self.markup_choice return self.save_post(post)
class HoraireForm(forms.ModelForm): # titre = forms.CharField(label="Titre") description = MDTextFormField(label="Les horaires") class Meta: model = Horaire fields= "__all__"
class ArticleAdminForm(forms.ModelForm): desc = forms.CharField( widget=forms.Textarea(attrs={'style': 'height: 100px;width:100%'}), label='摘要', required=False) content = MDTextFormField(label='正文', required=False) category = forms.ModelChoiceField( queryset=Category.objects.all(), widget=autocomplete.ModelSelect2(url='category-autocomplete'), label='分类', ) tag = forms.ModelMultipleChoiceField( queryset=Tag.objects.all(), widget=autocomplete.ModelSelect2Multiple(url='tag-autocomplete'), label='标签') class Meta: model = Article fields = ( 'category', 'tag', 'desc', 'title', 'content', 'status', 'visit', )
class LocalNotesForm(forms.ModelForm): # name = forms.CharField(max_length=150) content = MDTextFormField() class Meta: model = LocalThemeTree fields = ('name', 'content') def __init__(self, user, *args, **kwargs): super(LocalNotesForm, self).__init__(*args, **kwargs) self.user = user self.parent = None # self.fields['field1'].queryset = AnotherModel.objects.filter(pk=my_arg1) def set_parent(self, parent): self.parent = parent def save(self): result = {'error': False, 'message': ''} if not self.user.is_authenticated: result['error'] = True result[ 'message'] = 'Не авторизованный пользователь не может создавать заметки!' else: LocalThemeTree.objects.create(name=self.cleaned_data['name'], content=self.cleaned_data['content'], author=self.user, parent=self.parent) return result
class AnswerForm(forms.Form): title = forms.CharField() body = MDTextFormField() tags = forms.MultipleChoiceField() def __init__(self, *args, **kwargs): # 执行父类构造方法 super(AnswerForm, self).__init__(*args, **kwargs)
class MDEditorForm(forms.Form): title = forms.CharField() synopsis = forms.CharField() category = forms.ChoiceField(choices=CATEGORY_CHOICES, label="category", initial='', widget=forms.RadioSelect()) content = MDTextFormField()
class QuestionForm(forms.Form): title = forms.CharField(max_length=20, min_length=2, widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': '请输入题目标题'}), label='题目标题') deadline = forms.DateTimeField(widget=forms.DateTimeInput(attrs={'type': 'datetime-local', 'class': 'form-control'}), label='截至日期') question_text = MDTextFormField()
class ArticleForm(forms.ModelForm): content = MDTextFormField() class Meta: model = Article fields = [ 'category', "title", "abstract", "content", "cover", "tags", "status" ]
class MDEditorForm(forms.Form): title = forms.CharField(label='标题', max_length=128) brief = forms.CharField(label='简要', max_length=128, widget=forms.Textarea(attrs={'rows': 5})) cover = forms.ImageField(label='封面') category = forms.ChoiceField(label='分类', choices=CategoryInfo.objects.values_list( 'id', 'c_name')) content = MDTextFormField(label='正文')
class ArticleForm(forms.ModelForm): content = MDTextFormField() class Meta: model = Article fields = [ 'category', 'title', 'abstract', 'content', 'status', 'tags', 'cover' ]
class ArticleForm(forms.ModelForm): content = MDTextFormField() # content改成用md来渲染 class Meta: model = Article # 希望用户填的字段 fields = [ "category", "title", "abstract", "content", "cover", "tags", "status" ]
class Meta: model = Post fields = ('judul', 'konten', 'kategori') widgets = { 'judul': forms.TextInput(attrs={'class': 'form-control'}), 'kategori': forms.Select(choices=choices_list, attrs={'class': 'form-control'}), 'konten': MDTextFormField(), }
class AnswerForm(forms.Form): answer_text = MDTextFormField() question_pk = forms.IntegerField(widget=forms.HiddenInput) def clean(self): # 问题存在验证 question_pk = self.cleaned_data['question_pk'] try: Question.objects.get(pk=question_pk) except Exception as e: raise ValidationError('问题不存在') return self.cleaned_data
class HuntForm(forms.Form): content = MDTextFormField() start_date = forms.DateTimeField( widget=forms.DateTimeInput(attrs={ 'class': 'col-sm-6', 'readonly': True }), label='', required=False) end_date = forms.DateTimeField(widget=forms.DateTimeInput(attrs={ 'class': 'col-sm-6', 'readonly': True }), label='', required=False)
class ArticleForm(forms.ModelForm): content = MDTextFormField() # category = forms.ModelChoiceField(queryset=ArticleCategory.objects.all(), widget=forms.Select(attrs={'class': 'ui search dropdown'})) class Meta: model = Article fields = ["title", "content", "category", "abstract", "tags", "status"] widgets = { 'title': forms.TextInput(attrs={'placeholder': '文章标题'}), 'tags': forms.TextInput(attrs={'placeholder': '多个标签使用英文逗号(,)隔开'}), 'category': forms.Select(attrs={'class': 'ui search dropdown'}), 'abstract': forms.Textarea(attrs={'placeholder': '文章摘要'}) }
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['title'] = forms.CharField( label='', widget=forms.TextInput(attrs={ 'class': 'title', 'placeholder': 'タイトル' })) self.fields['tags'] = forms.CharField( label='', widget=forms.TextInput(attrs={ 'class': 'tag', 'placeholder': 'タグをスペース区切りで入力' })) self.fields['text'] = MDTextFormField()
class TravelAdminForm(forms.ModelForm): context = MDTextFormField(label='旅途描述', required=False, ) province = forms.ModelChoiceField( queryset=Province.objects.values('id', 'name').filter(status=Province.STATUS_NORMAL), widget=autocomplete.ModelSelect2(url='province-autocomplete'), label='省份', ) class Meta: model = Travel fields = ( 'title', 'context', 'visit', 'status', 'province' )
class ArticleAdminForm(forms.ModelForm): desc = forms.CharField(widget=forms.Textarea, label='摘要', required=False) content = MDTextFormField(widget=MDEditorWidget(), label='正文', required=True) category = forms.ModelChoiceField( queryset=Category.objects.all(), widget=autocomplete.ModelSelect2(url='category-autocomplete'), label='分类', ) tag = forms.ModelMultipleChoiceField( queryset=Tag.objects.all(), widget=autocomplete.ModelSelect2Multiple(url='tag-autocomplete'), label='标签', )
class CycleForm(forms.ModelForm): nom = forms.CharField(label="nom du cycle") description = MDTextFormField(label="La description du cyle") class Meta: model = Cycle exclude = ["slug"] def save(self, commit=True): instance = super(CycleForm, self).save(commit=False) if not instance.slug: instance.slug = unique_slug_generator_identif( instance, instance.nom) if commit: instance.save() return instance
class PresentionForm(forms.ModelForm): titre = forms.CharField(label="Titre") description = MDTextFormField(label="Description globale des cyles") class Meta: model = Presention exclude = ["slug"] def save(self, commit=True): instance = super(PresentionForm, self).save(commit=False) if not instance.slug: instance.slug = unique_slug_generator_identif( instance, instance.titre) if commit: instance.save() return instance
class InfobuleForm(forms.ModelForm): info = forms.CharField(label="Infobule") contenu = MDTextFormField(label="Le contenu") class Meta: model = Infobule exclude = ["slug"] def save(self, commit=True): instance = super(InfobuleForm, self).save(commit=False) print("Voici instance", instance) if not instance.slug: instance.slug = unique_slug_generator_for_null(instance) if commit: instance.save() return instance
class PartenaireForm(forms.ModelForm): nom = forms.CharField(label="Infobule") lien_site = forms.URLField(label="Lien de son site ou page") contenu = MDTextFormField(label="Le contenu") class Meta: model = Partenaire exclude = ["slug"] def save(self, commit=True): instance = super(PartenaireForm, self).save(commit=False) print("Voici instance", instance) if not instance.slug: instance.slug = unique_slug_generator_identif( instance, instance.nom) if commit: instance.save() return instance
class ArticleAddForm(forms.Form): name = forms.CharField(label=u'文章标题', max_length=50) cover = forms.ImageField(label=u'封面', ) content = MDTextFormField(label=u'内容', min_length=50) type = forms.ChoiceField(label=u'分类', choices=BlogTypes) tags = TagField(label=u'标签', max_length=50) def save(self): cd = self.cleaned_data name = cd['name'] cover = cd['cover'] type = cd['type'] content = cd['content'] tags = cd['tags'] article = Article(name=name, cover=cover, content=content, type=type, tags=tags) article.save()
class Meta: model = Post fields = ('judul', 'author', 'kategori', 'konten') widgets = { 'judul': forms.TextInput(attrs={'class': 'form-control'}), 'author': forms.TextInput( attrs={ 'class': 'form-control', 'id': 'author', 'value': '', 'type': 'hidden' }), 'kategori': forms.Select(choices=choices_list, attrs={'class': 'form-control'}), 'konten': MDTextFormField(), }
class ArticleForm(forms.Form): title = forms.CharField(label="文章标题", max_length=20) label = forms.CharField(label="文章标签", max_length=20) content = MDTextFormField(label="文章内容") def clean_title(self): title = self.cleaned_data.get("title") if len(title) < 6: raise forms.ValidationError("标题长度需要大于6") elif len(title) > 20: raise forms.ValidationError("标题长度需要小于20") else: return title def clean_label(self): label = self.cleaned_data.get("label") if len(label) < 6: raise forms.ValidationError("文章标签长度需要大于6") elif len(label) > 20: raise forms.ValidationError("文章标签长度需要小于20") else: return label
class AlterArticleForm(forms.Form): # TODO 文章修改表单--与接口交互渲染?? id = forms.IntegerField(label="文章id") title = forms.CharField(label="文章标题", max_length=20) label = forms.CharField(label="文章标签", max_length=20) content = MDTextFormField(label="文章内容")