Commit 77608779 authored by chris's avatar chris

Meilleur gestion des erreurs dans la page de sélection des dates (bug #465)

parent d411df30
......@@ -9,7 +9,7 @@ class PollForm(forms.ModelForm):
class ChoiceForm(forms.ModelForm):
choice = forms.DateField(widget=forms.DateTimeInput(format='%d-%m-%Y',attrs={'class':'hasdatepicker','size':'12',}),input_formats=['%d-%m-%Y'])
details = forms.CharField(required=False,widget=forms.TextInput(attrs={'size':'32',}))
details = forms.CharField(required=False,max_length='200',widget=forms.TextInput(attrs={'size':'32',}))
class Meta:
model = Choice
exclude = ('poll','votecount')
......
......@@ -22,7 +22,7 @@ class Poll(models.Model):
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.DateField()
details = models.CharField(max_length=120,blank=True)
details = models.CharField(max_length=200,blank=True)
votecount = models.IntegerField(default=0,blank=True)
def __unicode__(self):
......
......@@ -56,7 +56,7 @@ def editchoices(request, poll_id):
poll = get_object_or_404(Poll.objects.all(),id=poll_id)
language_code = request.LANGUAGE_CODE
error_message = ''
if poll.author == 'AnonymousUser': # Anonymous wants to edit his new poll
key = 'is_' + poll_id + '_author'
if not request.session.get(key, False):
......@@ -105,21 +105,23 @@ def editchoices(request, poll_id):
pass
except:
pass
#error_message = "Choices saved successfully."
redir = '/' + str(poll.id) + '/'
return HttpResponseRedirect(redir)
else:
#return HttpResponse(instances)
vforms=OrderedItemFormset(request.POST, instance=poll)
return render_to_response('sondage/choice_form.html', {'error_message' : instances.errors,'object': poll, 'vforms': vforms,}, context_instance=RequestContext(request))
if Choice.objects.filter(poll=poll_id).count() == 0:
# Sall we replace next line with something like OrderedItemFormset(extra=2)
OrderedItemFormset = get_ordereditem_formset(ChoiceForm, extra=2, can_delete=True)
vforms = OrderedItemFormset()
#vforms=OrderedItemFormset(request.POST, instance=poll)
error_message = "There are some errors in the form you posted."
vforms=instances
else:
vforms = OrderedItemFormset(instance=poll)
return render_to_response('sondage/choice_form.html', {'object': poll, 'vforms': vforms, 'language_code': language_code,}, context_instance=RequestContext(request))
if Choice.objects.filter(poll=poll_id).count() == 0:
# Sall we replace next line with something like OrderedItemFormset(extra=2)
OrderedItemFormset = get_ordereditem_formset(ChoiceForm, extra=2, can_delete=True)
vforms = OrderedItemFormset()
else:
vforms = OrderedItemFormset(instance=poll)
return render_to_response('sondage/choice_form.html', {'object': poll, 'vforms': vforms, 'error_message' : error_message, 'language_code': language_code,}, context_instance=RequestContext(request))
@login_required
def delete(request, poll_id):
......@@ -132,7 +134,6 @@ def delete(request, poll_id):
return HttpResponseRedirect('/')
def make_buletin_form(poll, **kwargs):
return [ [VoteForm(prefix=choice) ] for choice in Choice.objects.filter(poll=poll.id) ]
......@@ -178,7 +179,7 @@ def vote(request, poll_id):
try:
choice = Choice.objects.get(choice=vorm.cleaned_data['choice'],poll=poll)
except:
return HttpResponse("")
return HttpResponse(vorm.cleaned_data['choice'])
if not Vote.objects.filter(choice=choice,bulletin=bulletin):
vorm.cleaned_data['choice'] = choice
......
......@@ -18,7 +18,7 @@ a:link, a:active, a:visited {
a:hover {
color:#044bcd;
background-color: #f7f7ff;
//border: 1px solid #efefff;
border: 1px solid #f1f1ff;
}
h2, h3, h4 {color: #555;}
......@@ -157,15 +157,12 @@ form label {
.icone {
float: left;
//display: block;
text-align: center;
//width: 180px;
padding: 8px;
margin: 8px;
-moz-border-radius: 13px;
-webkit-border-radius: 13px;
border: 1px solid #fff;
//background-color: transparent;
}
.icone a {
......
......@@ -94,12 +94,12 @@
<tr id="{{ v.prefix }}-row">
<td>
{% for fld in v.hidden_fields %}{{ fld }}{% endfor %}
{{ v.management_form }}
{% if v.instance.pk %}{{ v.DELETE }}{% endif %}
{{ v.choice }}
{{ v.choice.errors }}{{ v.choice }}
</td>
<td>
{{ v.details }}
{{ v.details.errors }}{{ v.details }}
</td>
</tr>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment