Exemplo n.º 1
0
def save(request):
    absenteeism_data = json.loads(request.POST['data'])
    absenteeism = absenteeism_data['absenteeism']

    absenteeism_entries = absenteeism['entries']
    absenteeism.pop('entries')


    absenteeism_form = AbsenteeismForm(absenteeism)
    if absenteeism_form.is_valid():
        entries_form = []
        for entry in absenteeism_entries:
            entry_form = AbsenteeismEntryForm(entry)
            if entry_form.is_valid():
                entries_form.append(entry_form.cleaned_data)
            else:
                return HttpResponseServerError(json.dumps(entry_form.errors),
                                               mimetype="application/json")

    else:
        return HttpResponseServerError(json.dumps(absenteeism_form.errors),
                                       mimetype="application/json")


    new_absenteeism = absenteeism_form.save()
    for entry in entries_form:
        new_absenteeism.absenteeismentry_set.create(**entry)

    return HttpResponse(json.dumps(dict(message="Salvou com sucesso!")),
                        mimetype="application/json")
Exemplo n.º 2
0
    def test_atested_end_greater_than_revised_end(self):
        form = AbsenteeismEntryForm({
            'atested_begin' : "03/01/2012",
            'atested_end' : "04/01/2012",
            'revised_begin' : "03/01/2012",
            'revised_end' : "05/01/2012",
        })

        self.assertFalse(form.is_valid())
        self.assertIn(u'Data Final Abonada não pode ser maior que a Data Final Atestada', form.errors.get('__all__'))
Exemplo n.º 3
0
    def test_atested_begin_lower_than_atested_end(self):
        form = AbsenteeismEntryForm({
            'atested_begin' : "02/01/2012",
            'atested_end' : "01/01/2012",
            'revised_begin' : "01/01/2012",
            'revised_end' : "01/01/2012",
        })

        self.assertFalse(form.is_valid())
        self.assertIn(u'Data Final Atestadada não pode ser menor que a Data Inicial Atestada', form.errors.get('__all__'))