Skip to content

Commit

Permalink
feature/add-form-markdown: Paragraph now renders on the front end
Browse files Browse the repository at this point in the history
  • Loading branch information
AltusBarry committed Nov 17, 2017
1 parent 9b51746 commit 634ecda
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions formfactory/fields.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import markdown

from django.forms.fields import Field
from django.utils.text import mark_safe

from formfactory import widgets


# TODO add support for paragraph field. Mark safe in templates.
class ParagraphField(Field):
widget = widgets.ParagraphWidget
def __init__(self, paragraph, *args, **kwargs):
super(ParagraphField, self).__init__(*args, **kwargs)

# Always empty out label for a pragraph field.
# Always empty out label for a paragraph field.
self.label = ""

# No matter what is set, this field should never be required.
self.required = False
self.widget.is_required = False

# Pass the paragraph text to the widget without needing to override
# widgit __init__.
# widget __init__. Process markdown here, its up to custom fields to
# worry about what they are trying to do, not factory.py
attrs = self.widget.build_attrs(self.widget.attrs,
{"paragraph": paragraph}
{"paragraph": markdown.markdown(paragraph)}
)
self.widget.attrs = attrs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{ widget }}
{{ widget.attrs.paragraph|safe }}

0 comments on commit 634ecda

Please sign in to comment.