Exemplo n.º 1
0
Arquivo: views.py Projeto: noknod/code
def registration_choose_date(request):
    if request.method == 'POST':
        method = request.POST.get('_method', None)
        if  method == 'DELETE':
            if 'reg_schedule' in request.session:
                del request.session['reg_schedule']
            return HttpResponseRedirect('/clinic/registration/speciality/')
        else:
            reg_schedule = request.POST.get('schedule')
            if reg_schedule == BLANK_CHOICE[0]:
                request.session['reg_schedule'] = reg_schedule
                return HttpResponseRedirect('/clinic/registration/date/')
            request.session['reg_schedule'] = reg_schedule
            return HttpResponseRedirect('/clinic/registration/')
    else:
        if 'reg_speciality' in request.session:
            speciality = request.session['reg_speciality']
            if 'reg_schedule' in request.session:
                schedule = request.session['reg_schedule']
            else:
                schedule = BLANK_CHOICE[0]
            form = DateChooseForm(FIND_ADMISSION_DAYS_AHEAD, speciality, 
                    initial={'schedule': schedule})
            template = 'clinic_registration_choose_date.html'
            context = {'speciality': Doctor.get_speciality(speciality),
                       'form': form}
            return render(request, template, context)
        else:
            return HttpResponseRedirect('/clinic/registration/speciality/')
Exemplo n.º 2
0
Arquivo: forms.py Projeto: noknod/code
    def __init__(self, days_ahead, *args, **kwargs):
        """ 
        Переопределение метода: отображение специальностей только свободных 
        докторов на заданное время вперёд
        """
        # Вызов метода-предка
        super (SpecialityChooseForm, self ).__init__(*args, **kwargs)

        # Получение для отображения списка специальностей только свободных 
        # докторов на заданное время вперёд
        start_date = datetime.date.today() 
        end_date = start_date + datetime.timedelta(days=days_ahead)

        doctor_id_list = Schedule.objects.filter(
                    vdate__range=(start_date, end_date)
                ).exclude(
                    id__in = Admission.objects.filter(
                                status__in=[0, 1]
                            ).values_list('schedule_id', flat=True)
                ).values_list('doctor_id', flat=True)
        doctor_id_set = set(doctor_id_list)

        speciality_set = Doctor.objects.filter(
                    id__in=doctor_id_set
                ).values_list('speciality', flat=True)

        speciality_list = [BLANK_CHOICE]
        for speciality in speciality_set:
            speciality_list.append((speciality, 
                    Doctor.get_speciality(speciality),))
        
        #self.fields['speciality'].queryset = speciality_list
        self.fields['speciality'].choices = speciality_list