def detail_view(request, report_id): is_editor = is_user_an_editor(request) r = requests.get(API_HOST + '/api/report/%d/' % (report_id)) if r.status_code // 100 == 4: return render(request, 'not_found.html') widget_html = "" report = r.json() md = "" comment = report.get('comment', None) if comment is None: comment = {'md': ''} value = comment['md'] if is_editor: w = MarkdownxWidget() widget_html = w.render('comment', value, {}) else: markdownify = import_string('markdownx.utils.markdownify') md = markdownify(value) return render( request, 'detail.html', { 'report': report, 'markdownx_editor': widget_html, 'is_editor': is_editor, 'markdownx_md': md })
class Meta: model = Category fields = '__all__' widgets = { 'short_description': MarkdownxWidget(), 'description': MarkdownxWidget(), }
class Meta: model = MyReference fields = ['name', 'description', 'url'] widgets = { 'name': forms.TextInput(attrs={'class': 'form-control'}), 'description': MarkdownxWidget(attrs={'class': 'form-control'}) }
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.layout = Layout( 'user', 'title', 'body', 'created_date', 'mod_date', Submit('submit', 'Submit', css_class='btn btn-primary btn-lg'), ) self.fields['title'].widget = forms.TextInput( attrs={'autocomplete': 'off'}) self.fields['body'].label = '' self.fields['user'].widget = forms.HiddenInput() self.fields['created_date'].widget = forms.HiddenInput() self.fields['mod_date'].widget = forms.HiddenInput() self.fields['body'].widget = MarkdownxWidget( attrs={ 'style': ''' background-color:#ffffe6; min-width:500px; min-height:500px; ''', })
class Meta: model = Post # fields = ('title', 'category', 'tag', 'content', 'is_public') fields = '__all__' widgets = { 'text' : MarkdownxWidget(attrs={'class': 'textarea'}) }
class PositionForm(forms.ModelForm): """Form representing a position. This form is inserted into PositionFormset """ description = forms.CharField( label='', widget=MarkdownxWidget( attrs={ 'placeholder': 'Position Description', 'class': 'card-input' }) ) time_estimate = forms.CharField( widget=forms.TextInput( attrs={ 'class': 'card-input' })) class Meta: model = Position fields = ['title', 'description', 'skills', 'time_estimate', 'id', ] widgets = { 'title': forms.TextInput(attrs={ 'placeholder': 'Position Title', 'class': 'card-input' }), 'id': forms.HiddenInput(), }
def create_exercise_view(request): if request.method == 'POST': form = f.ExerciseForm(request.POST) if form.is_valid(): with reversion.create_revision(): exercise = form.save(commit=False) exercise.author = request.user exercise.save() form.save_m2m() reversion.set_user(request.user) return redirect('learning:exercise', exercise_id=exercise.id) else: if 'section' in request.GET: section = get_object_or_404(m.Section, id=request.GET['section']) form = f.ExerciseForm(initial={'synopses_sections': [ section, ]}) else: form = f.ExerciseForm() context = build_base_context(request) context['pcode'] = 'l_exercises' context['title'] = 'Submeter exercício' context['form'] = form editor = MarkdownxWidget().render(name='', value='', attrs=dict()) context['markdown_editor'] = editor context['sub_nav'] = [{ 'name': 'Exercícios', 'url': reverse('learning:exercises') }, { 'name': 'Submeter exercício', 'url': reverse('learning:exercise_create') }] return render(request, 'learning/editor.html', context)
class UserUpdateForm(forms.ModelForm): """Form for updating user's general information (first_name, last_name, about, avatar, skills) """ about = forms.CharField( widget=MarkdownxWidget( attrs={ "class": "card-input", "placeholder": "Add a short description about yourself..." })) first_name = forms.CharField( widget=forms.TextInput( attrs={ "class": "card-input", "placeholder": "First Name" })) last_name = forms.CharField( widget=forms.TextInput( attrs={ "class": "card-input", "placeholder": "Last Name" })) class Meta: model = User fields = ['first_name', 'last_name', 'about', 'skills']
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['text'].widget = MarkdownxWidget() for field in self.fields.values(): field.widget.attrs['class'] = 'form-control' field.widget.attrs['placeholder'] = field.label self.fields['text'].initial = """## マークダウンの書き方 ### 順序なしリスト * リストアイテム1 * リストアイテム2 * リストアイテム3 ### 順序ありリスト 1. リストアイテム 1. リストアイテム 1. リストアイテム ### 文字強調 *イタリック* **太文字** ### 引用 > #### コラム~マークダウンとは > このサイトでは[マークダウン形式](https://ja.wikipedia.org/wiki/Markdown)での入力を受け付けています。 > 上記に例を示したので、例にならって入力してみてください。""" self.fields['tags'].widget = MyCheckboxSelectMultiple() self.fields['tags'].queryset = Tag.objects
class Meta: model = Article fields = ('thumbnail', 'categories', 'title', 'text', 'is_public', 'title_seo', 'description', 'keywords') widgets = { 'text': MarkdownxWidget(attrs={'class': 'textarea'}), }
class Meta: model = Content fields = [ "text", "visibility", "pinned", "show_preview", "federate", "include_following", "recipients", ] widgets = { "text": MarkdownxWidget() }
class Meta: model = Comment fields = ( 'author', 'text', ) widgets = { 'text': MarkdownxWidget(attrs={'class': 'textarea'}), }
class Meta: model = Comment fields = ( 'name', 'content', ) widgets = { 'content': MarkdownxWidget(attrs={'class': 'com-form'}), }
class Meta: model = Post fields = ( 'title', 'outlined_material_icon_name', 'text', ) widgets = { 'text': MarkdownxWidget(attrs={'class': 'textarea'}), }
class Meta: model = Question fields = ('title', 'tag', 'text', 'is_public') widgets = { 'tag': forms.CheckboxSelectMultiple( attrs={'class': 'list-unstyled',} ), 'question_text': MarkdownxWidget( attrs={'placeholder': 'マークダウンに対応しています。'} ), }
class Meta: model = Post fields = ( 'post', 'category', 'content', 'is_public', ) widgets = { 'content': MarkdownxWidget(attrs={'class': 'post-form'}), }
class NoteForm(forms.Form): #tags = TagField(widget=forms.TextInput(attrs={'class' : 'tag-field'}), max_length=200) tag_dropdown = forms.ChoiceField( choices=[(tag, tag) for tag in Tag.objects.all()], widget=forms.Select(attrs={'class': 'tag-field'}), label='') text = MarkdownxFormField( widget=MarkdownxWidget(attrs={'class': 'text-box'}), label='', )
class Meta: model = TalkAtArticle fields = [ 'msg', ] widgets = { 'msg': MarkdownxWidget( attrs={ 'placeholder': 'あなたの回答を入力(コードを含む場合はMarkdown記法をご使用ください)' }) }
class Meta: model = ToDo fields = [ 'title', 'description', 'source_url', 'slug', 'status', 'progress', 'ref_title1', 'ref_url1', 'ref_title2', 'ref_url2', 'ref_title3', 'ref_url3', 'ref_title4', 'ref_url4', 'ref_title5', 'ref_url5' ] widgets = { 'title': forms.TextInput(attrs={'class': 'form-control'}), 'description': MarkdownxWidget(attrs={'class': 'form-control'}) }
class Meta: model = Article fields = ( 'title', 'text', 'tag', 'photo', ) widgets = { # 'text': forms.Textarea(attrs={'rows':5, 'cols':8}), 'title': forms.TextInput(attrs={"placeholder":"タイトル"}), 'text': MarkdownxWidget(attrs={'class': 'textarea','rows': 7, 'cols': 22, 'style': 'resize:none;'}), }
class CreateProjectForm(forms.ModelForm): """Form for creating a project """ STATUS = [ ('A', 'Open'), ('B', 'Closed'), ('C', 'Complete'), ] title = forms.CharField( max_length=255, widget=forms.TextInput( attrs={ 'class': 'card-input', 'placeholder': 'Project Title' })) description = forms.CharField( widget=MarkdownxWidget( attrs={ 'class': 'card-input', 'placeholder': 'Project description' })) status = forms.CharField( widget=forms.RadioSelect( choices=STATUS, attrs={ 'class': 'status-list' })) time_estimate = forms.CharField( max_length=10, widget=forms.TextInput( attrs={ 'class': 'card-input', 'placeholder': 'Time estimate'} )) applicant_requirements = forms.CharField( widget=forms.Textarea( attrs={ 'class': 'card-input' } ) ) class Meta: model = Project fields = ['title', 'description', 'time_estimate', 'applicant_requirements', 'status', ]
class AddNoteForm(forms.Form): tags = forms.CharField(widget=forms.Textarea(attrs={ "rows": 1, "cols": 120 })) note = MarkdownxFormField(widget=MarkdownxWidget(attrs={ "rows": 6, "cols": 120 })) def clean_data(self): tags = self.cleaned_data['tags'] note = self.cleaned_data['note'] return tags, note
class Meta: model = Article fields = [ 'is_published', 'title', 'category', 'course', 'lesson', 'content', 'article_image_1', 'article_image_2' ] labels = { 'title': '', 'content': '', } widgets = { 'title': forms.TextInput(attrs={'placeholder': '記事タイトル:30文字以内'}), 'content': MarkdownxWidget( attrs={ 'placeholder': '本文を入力(コードを含む場合はMarkdown記法をご使用ください)<br> * 実現したいこと <br> * 試したこと <br> * 出力されたエラー <br> などを書きましょう' }) }
class ArticleForm(forms.ModelForm): title = forms.CharField( label = 'Título', required = True, widget = forms.TextInput(attrs={'class': 'form-control'}) ) labels = forms.CharField( label = 'Etiquetas', required = True, widget = forms.TextInput(attrs={'class': 'form-control'}) ) pub_date = forms.DateTimeField( label = "Fecha de publicación", required = True, initial = datetime.datetime.now, widget = forms.DateTimeInput(attrs={'class': 'form-control'}) ) content = MarkdownxFormField( label = "Contenido de la publicación", required = True, widget = MarkdownxWidget(attrs={'class': 'form-control'}) ) category = forms.ModelChoiceField( label = 'Categoría', queryset = Category.objects.all(), initial = 0, widget = forms.Select(attrs={'class': 'form-control'}) ) author = forms.ModelChoiceField( label = 'Autor', queryset = User.objects.all(), initial = 0, widget = forms.Select(attrs={'class': 'form-control'}) ) class Meta: model = Article fields = ('title', 'labels', 'pub_date', 'category', 'content', 'author')
class Meta: model = Question fields = [ 'title', 'category', 'lesson', 'course', 'content', 'question_image_1', 'question_image_2' ] labels = { 'title': '', 'category': '', 'lesson': '', 'course': '', 'content': '', } # emply_label = '選択してください' widgets = { 'title': forms.TextInput(attrs={'placeholder': '質問タイトル:30文字以内'}), 'content': MarkdownxWidget( attrs={ 'placeholder': '本文を入力(コードを含む場合はMarkdown記法をご使用ください) ・実現したいこと ・試したこと ・出力されたエラー などを書きましょう' }) }
class MyForm(forms.Form): body = MarkdownxFormField(widget=MarkdownxWidget( attrs={'class': 'custom-class-body'}))
class MyForm(forms.Form): markdownx_form_field1 = MarkdownxFormField(widget=MarkdownxWidget( attrs={'class': 'custom-class-markdownx_form_field1'})) markdownx_form_field2 = MarkdownxFormField(widget=MarkdownxWidget( attrs={'class': 'custom-class-markdownx_form_field2'}))
class Meta: model = Article fields = ('title', 'text') widgets = { 'text': MarkdownxWidget(), }
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['desc'].widget = MarkdownxWidget() for field in self.fields.values(): field.widget.attrs['class'] = 'form-control' field.widget.attrs['placeholder'] = field.label
class Meta: model = Content fields = ["text", "visibility", "pinned"] widgets = {"text": MarkdownxWidget()}