Ejemplo n.º 1
0
    def post(self, request, patient_id, spec, medical_id):
        kwargs = {
            'spec': spec,
            'patient_id': patient_id,
            'medical_id': medical_id
        }

        if len(request.POST) > 1:
            form = DateVisitRegisterForm(data=request.POST)

            if form.is_valid():
                cd = form.cleaned_data
                date_of_visit = cd['date_of_visit']

                if date_of_visit >= date.today():
                    if date_of_visit.weekday() < 5:
                        if date_of_visit not in holidays(
                                date_of_visit).values():
                            date_of_visit = datetime.strftime(
                                date_of_visit, '%Y-%m-%d')
                            kwargs['date_of_visit'] = date_of_visit
                            return HttpResponseRedirect(
                                reverse('medical_visit:visit_hour_register',
                                        kwargs=kwargs))
                        else:
                            msg = r'Selected date is a holiday ({}). Please select correct date!'
                            for key, value in holidays(date_of_visit).items():
                                if value == date_of_visit:
                                    messages.error(request, msg.format(key))
                    else:
                        if date_of_visit.weekday() == 5:
                            msg = r'Selected date is a Saturday... Please select correct date!'
                            messages.error(request, msg)
                        else:
                            msg = r'Selected date is a Sunday... Please select correct date!'
                            messages.error(request, msg)

                else:
                    msg = r"Please select today's or future date..."
                    messages.error(request, msg)

                return HttpResponseRedirect(
                    reverse('medical_visit:visit_date_register',
                            kwargs=kwargs))

            else:
                msg = r'Please select a valid visit date...'
                messages.error(request, msg)

                return HttpResponseRedirect(
                    reverse('medical_visit:visit_date_register',
                            kwargs=kwargs))
Ejemplo n.º 2
0
 def test_year_holidays_to_known_holidays_2065(self):
     for d in self.known_holidays_2065.values():
         result = holidays(d)
         self.assertEqual(self.known_holidays_2065, result)