Beispiel #1
0
    def test_order(self):
        f = PersonForm()
        self.assertFalse(f.is_reversed)
        self.assertEqual(f.as_table(), """<tr><th><label for="id_firstname">\
Firstname:</label></th><td><input id="id_firstname" type="text" \
name="firstname" maxlength="80" /></td></tr>
<tr><th><label for="id_lastname">Lastname:</label></th><td><input \
id="id_lastname" type="text" name="lastname" maxlength="80" /></td></tr>
<tr><th><label for="id_biography">Biography:</label></th><td><textarea \
id="id_biography" rows="10" cols="80" name="biography"></textarea></td></tr>
<tr><th><label for="id_birth_date">Birth date:</label></th><td><img \
class="calendar" src="/site_media/img/baloon_24.png" alt="Calendar"><input \
id="id_birth_date" type="text" class="vDateField" name="birth_date" size="10" \
/></td></tr>""")
        f.reverseOrder(True)
        self.assertTrue(f.is_reversed)
        self.assertEqual(f.as_table(), """<tr><th><label for="id_birth_date">\
Birth date:</label></th><td><img class="calendar" src="/site_media/img/\
baloon_24.png" alt="Calendar"><input id="id_birth_date" type="text" \
class="vDateField" name="birth_date" size="10" /></td></tr>
<tr><th><label for="id_biography">Biography:</label></th><td><textarea \
id="id_biography" rows="10" cols="80" name="biography"></textarea></td></tr>
<tr><th><label for="id_lastname">Lastname:</label></th><td><input \
id="id_lastname" type="text" name="lastname" maxlength="80" /></td></tr>
<tr><th><label for="id_firstname">Firstname:</label></th><td><input \
id="id_firstname" type="text" name="firstname" maxlength="80" /></td></tr>""")
Beispiel #2
0
    def post(self, request):
        form = PersonForm(request.POST)

        if not form.is_valid():
            return HttpResponseRedirect(reverse('register-fail'))

        Person.objects.create(
            first_name=form.cleaned_data.get('first_name'),
            last_name=form.cleaned_data.get('last_name'),
            date_of_birth=form.cleaned_data.get('date_of_birth'),
            add_author=request.user,
            modified_author=request.user,
        )

        return HttpResponseRedirect(reverse('contact-add-success'))
Beispiel #3
0
def edit(request, queryset, object_id):
    person = get_object_or_404(queryset, pk=object_id)
    response_dict = {}

    if request.method == "POST":
        form = PersonForm(request.POST, request.FILES,
                instance=person)
        formset = ContactFormSet(request.POST, request.FILES,
                instance=person)
        errors = {}

        if form.is_valid():
            form.save()
        else:
            errors.update([(key, unicode(value[0]))
                for key, value in form.errors.items()])

        if formset.is_valid():
            formset.save()
        else:
            errors.update([(key, unicode(value[0]))
                for key, value in formset.errors.items()])

        if len(errors) > 0:
            response_dict['type'] = 'error'
            response_dict['msg'] = 'Fix errors and submit again'
            response_dict['errors'] = errors
        else:
            response_dict['type'] = 'success'
            response_dict['msg'] = 'Thank you-u-u'

        if request.is_ajax():
            json = simplejson.dumps(response_dict, ensure_ascii=False)
            return HttpResponse(json, mimetype='application/javascript')

    else:
        form = PersonForm(instance=person)
        formset = ContactFormSet(instance=person)
        if 'button_reverse' in request.GET:
            form.reverseOrder(request.GET['is_reversed'] == 'False')

    response_dict['is_reversed'] = form.is_reversed
    response_dict.update({"form": form, "formset": formset})
    return render_to_response("contact/edit.html", response_dict,
            context_instance=RequestContext(request))
Beispiel #4
0
 def get_context_data(self, **kwargs):
     form = PersonForm()
     return locals()