-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/add-form-markdown: Paragraph now renders on the front end
- Loading branch information
1 parent
9b51746
commit 634ecda
Showing
2 changed files
with
8 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{{ widget }} | ||
{{ widget.attrs.paragraph|safe }} |