Commit b2895806fa99e3b008ab609e6c01568f1aaec9c7
1 parent
334435de
Exists in
master
and in
3 other branches
display error message on create website link correctly
Showing
2 changed files
with
15 additions
and
5 deletions
Show diff stats
links/forms.py
@@ -50,19 +50,16 @@ class LinkForm(forms.ModelForm): | @@ -50,19 +50,16 @@ class LinkForm(forms.ModelForm): | ||
50 | if cleaned_data.get('end_view'): | 50 | if cleaned_data.get('end_view'): |
51 | end_view = cleaned_data.get('end_view') | 51 | end_view = cleaned_data.get('end_view') |
52 | if end_view and not cleaned_data.get('end_view_date'): | 52 | if end_view and not cleaned_data.get('end_view_date'): |
53 | - print("here 1") | ||
54 | raise ValidationError(_('End View Date is not set'), code='invalid' ) | 53 | raise ValidationError(_('End View Date is not set'), code='invalid' ) |
55 | 54 | ||
56 | if cleaned_data.get('initial_view'): | 55 | if cleaned_data.get('initial_view'): |
57 | initial_view = cleaned_data.get('initial_view') | 56 | initial_view = cleaned_data.get('initial_view') |
58 | if initial_view and not cleaned_data.get('initial_view_date'): | 57 | if initial_view and not cleaned_data.get('initial_view_date'): |
59 | - print("here 2") | ||
60 | - raise ValidationError(_('Initial View Date is not set'), code='invalid' ) | 58 | + raise ValidationError(_('Initial View Date is not set'), code='invalid' ) |
61 | if cleaned_data.get('initial_view_date') and cleaned_data.get('end_view_date'): | 59 | if cleaned_data.get('initial_view_date') and cleaned_data.get('end_view_date'): |
62 | end_view_date = cleaned_data.get('end_view_date') | 60 | end_view_date = cleaned_data.get('end_view_date') |
63 | initial_view_date = cleaned_data.get('initial_view_date') | 61 | initial_view_date = cleaned_data.get('initial_view_date') |
64 | if end_view_date < initial_view_date: | 62 | if end_view_date < initial_view_date: |
65 | - print("here 3") | ||
66 | raise ValidationError(_('End View Date before Initial View Date'), code='invalid' ) | 63 | raise ValidationError(_('End View Date before Initial View Date'), code='invalid' ) |
67 | 64 | ||
68 | return cleaned_data | 65 | return cleaned_data |
links/templates/links/_form.html
@@ -4,7 +4,18 @@ | @@ -4,7 +4,18 @@ | ||
4 | <form method="post" action="" enctype="multipart/form-data"> | 4 | <form method="post" action="" enctype="multipart/form-data"> |
5 | {% csrf_token %} | 5 | {% csrf_token %} |
6 | 6 | ||
7 | - {{form.non_field_errors}} | 7 | + {% if form.errors %} |
8 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
9 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
10 | + <span aria-hidden="true">×</span> | ||
11 | + </button> | ||
12 | + <ul> | ||
13 | + {% for key, message in form.errors.items %} | ||
14 | + <li>{{message}}</li> | ||
15 | + {% endfor %} | ||
16 | + </ul> | ||
17 | + </div> | ||
18 | + {% endif %} | ||
8 | 19 | ||
9 | {% render_field form.control_subject %} | 20 | {% render_field form.control_subject %} |
10 | 21 | ||
@@ -388,6 +399,8 @@ | @@ -388,6 +399,8 @@ | ||
388 | </div> | 399 | </div> |
389 | {% endif %} | 400 | {% endif %} |
390 | </div> | 401 | </div> |
402 | + | ||
403 | + | ||
391 | 404 | ||
392 | <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> | 405 | <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> |
393 | <div class="text-center"> | 406 | <div class="text-center"> |