Skip to content

Commit

Permalink
Added in better support for uni-form errorMsg
Browse files Browse the repository at this point in the history
  • Loading branch information
pydanny committed Apr 14, 2010
1 parent bfb3afc commit 51f4e8c
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 51 deletions.
50 changes: 6 additions & 44 deletions test_project/test_app/forms.py
Expand Up @@ -73,50 +73,12 @@ class LayoutTestForm(forms.Form):


submit = Submit('add','Add this contact') submit = Submit('add','Add this contact')
helper.add_input(submit) helper.add_input(submit)



class MessageResponseForm(forms.Form):


class ComplexLayoutTest(forms.Form): character_field = forms.CharField(label="Character Field", help_text="I am help text", max_length=30, required=True, widget=forms.TextInput())
"""
TODO: get digi604 to make this work


help_text = render_to_string("example/help_text.html") def clean(self):
layout = Layout(Fieldset(_('Basic Settings'), cleaned_data = self.cleaned_data
'title', raise forms.ValidationError("This is a forced error")
'type', return cleaned_data
'available_date',
),
Fieldset(_('Overview'),
Column(Fieldset(_('Object address'),
Row('address', 'street_number'),
Row('zip', 'city'),
'area',
),
Fieldset(_("Next public transport"),
'train_station',
Row('tram_station','tram_number'),
Row('bus_station','bus_number'),
),
),
Column("is_for_rent",
Fieldset(_("Rent"),
'rent-price',
),
Fieldset(_("Sell"),
'buy_price',
),
Fieldset(_("Measurements"),
'floor_space',
'room_height',
'construction_year',
),
),
Fieldset(_('Additional Function'),
HTML('<p class="tip">%s</p>' % unicode(help_text)),
'features',
),
Fieldset(_("Description"),
"description")
)
helper.add_layout(layout)
"""
1 change: 1 addition & 0 deletions test_project/test_app/templates/test_app/base.html
Expand Up @@ -122,6 +122,7 @@ <h2>Test Pages</h2>
<li><a href="{% url layout_test %}">Layout test</a></li> <li><a href="{% url layout_test %}">Layout test</a></li>
<li><a href="{% url set_action_test %}">Set action test</a></li> <li><a href="{% url set_action_test %}">Set action test</a></li>
<li><a href="{% url lacking_form_tag %}">Lacking form tag</a></li> <li><a href="{% url lacking_form_tag %}">Lacking form tag</a></li>
<li><a href="{% url message_response %}">Message Response</a></li>
</ul> </ul>
</div> </div>


Expand Down
11 changes: 11 additions & 0 deletions test_project/test_app/templates/test_app/message_response.html
@@ -0,0 +1,11 @@
{% extends "test_app/base.html" %}
{% load uni_form_tags %}

{% block body%}
<h1>
Django Uni-Form message response test
</h1>

{% uni_form form helper %}

{% endblock %}
1 change: 1 addition & 0 deletions test_project/test_app/urls.py
Expand Up @@ -9,6 +9,7 @@
url(r'^layout_test/$', "test_app.views.layout_test", name='layout_test'), url(r'^layout_test/$', "test_app.views.layout_test", name='layout_test'),
url(r'^view_helper_set_action/$', "test_app.views.view_helper_set_action", name='set_action_test'), url(r'^view_helper_set_action/$', "test_app.views.view_helper_set_action", name='set_action_test'),
url(r'^lacking_form_tag/$', "test_app.views.lacking_form_tag", name='lacking_form_tag'), url(r'^lacking_form_tag/$', "test_app.views.lacking_form_tag", name='lacking_form_tag'),
url(r'^message_response/$', "test_app.views.message_response", name='message_response'),




) )
28 changes: 26 additions & 2 deletions test_project/test_app/views.py
Expand Up @@ -4,7 +4,7 @@


from uni_form.helpers import FormHelper, Submit, Reset, Hidden from uni_form.helpers import FormHelper, Submit, Reset, Hidden


from test_app.forms import TestForm, HelperTestForm, LayoutTestForm from test_app.forms import TestForm, HelperTestForm, LayoutTestForm, MessageResponseForm


def basic_test(request): def basic_test(request):
if request.method == "POST": if request.method == "POST":
Expand Down Expand Up @@ -107,4 +107,28 @@ def lacking_form_tag(request):
return render_to_response('test_app/lacking_form_tag.html', return render_to_response('test_app/lacking_form_tag.html',
response_dictionary, response_dictionary,
context_instance=RequestContext(request)) context_instance=RequestContext(request))


def message_response(request):

if request.method == "POST":
form = MessageResponseForm(request.POST)
else:
form = MessageResponseForm()

# create a formHelper
helper = FormHelper()

# add in a error and success button
error = Submit('generate-result','Generate Error')
helper.add_input(error)

# add in a submit and reset button
success = Submit('generate-result','Generate Success')
helper.add_input(success)

# create the response dictionary
response_dictionary = {'form':form, 'helper': helper}

return render_to_response('test_app/message_response.html',
response_dictionary,
context_instance=RequestContext(request))
15 changes: 13 additions & 2 deletions uni_form/templates/uni_form/whole_uni_form.html
@@ -1,10 +1,21 @@
{% load uni_form_tags i18n %} {% load uni_form_tags i18n %}



{% if form_tag %}<form action="{{ form_action|lower }}" class="uniForm{% if form_class %} {% endif %}{{ form_class }}" method="{{ form_method }}"{% if form_id %} id="{{ form_id|slugify }}"{% endif %}{% if form.is_multipart %} enctype="multipart/form-data"{% endif %}>{% endif %} {% if form_tag %}<form action="{{ form_action|lower }}" class="uniForm{% if form_class %} {% endif %}{{ form_class }}" method="{{ form_method }}"{% if form_id %} id="{{ form_id|slugify }}"{% endif %}{% if form.is_multipart %} enctype="multipart/form-data"{% endif %}>{% endif %}
{% if form_html %}{{ form_html }}{% else %} {% if form.non_field_errors %}
<div id="errorMsg">
<h3>{% if error_message_title %}{{ error_message_title }}{% else %}Errors{% endif %}</h3>
<ol>
{{ form.non_field_errors|unordered_list }}
</ol>
</div>
{% endif %}
{% if form_html %}{{ form_html }}{% else %}
<fieldset class="inlineLabels"> <fieldset class="inlineLabels">
<legend>* {% trans "Required fields" %}</legend> <legend>* {% trans "Required fields" %}</legend>
{{ form|as_uni_form }} {% for field in form %}
{% include "uni_form/field.html" %}
{% endfor %}
</fieldset> </fieldset>
{% endif %} {% endif %}
{% if inputs %} {% if inputs %}
Expand Down
9 changes: 6 additions & 3 deletions uni_form/templatetags/uni_form_tags.py
Expand Up @@ -82,16 +82,19 @@ def get_render(self, context):
attrs = None attrs = None
if helper: if helper:
if not isinstance(helper, FormHelper): if not isinstance(helper, FormHelper):
raise TypeError('helper object provided to uni_form tag must be a uni_form.helpers.FormHelper object or a None object.') raise TypeError('helper object provided to uni_form tag must be a uni_form.helpers.FormHelper object.')
attrs = helper.get_attr() attrs = helper.get_attr()
form_class = '' form_class = ''
form_id = '' form_id = ''
form_method = 'post'
form_action = ''
form_tag = True
inputs = [] inputs = []
toggle_fields = set(()) toggle_fields = set(())
if attrs: if attrs:
form_tag = attrs.get("form_tag", True) form_tag = attrs.get("form_tag", True)
form_method = attrs.get("form_method", 'POST') form_method = attrs.get("form_method", form_method)
form_action = attrs.get("form_action", '') form_action = attrs.get("form_action", form_action)
form_class = attrs.get("class", '') form_class = attrs.get("class", '')
form_id = attrs.get("id", "") form_id = attrs.get("id", "")
inputs = attrs.get('inputs', []) inputs = attrs.get('inputs', [])
Expand Down

0 comments on commit 51f4e8c

Please sign in to comment.