Beispiel #1
0
def offer_edit(request, idOffer):
    offer = Offer.pickById(idOffer)
    if request.method == 'POST':
        form = OfferForm(request.POST)
        form.updateForm()
        if form.is_valid():
            idProfessor = form.cleaned_data['dropDownProfessor']
            classNumber = form.cleaned_data['classNumber']
            practical = form.cleaned_data['dropDownTeoricaPratica']
            numberOfRegistrations = form.cleaned_data['numberOfRegistrations']
            schedulesIds = form.cleaned_data['listSchedules']
            schedules = [
                Schedule.pickById(int(schedule)) for schedule in schedulesIds
            ]
            schedules_string_old = '[ '
            schedules_string = '[ '
            for schedule in offer.schedules:
                schedules_string_old += str(schedule).replace('ç', 'c') + " "
            for schedule in schedules:
                schedules_string += str(schedule).replace('ç', 'c') + " "
            schedules_string_old += ']'
            schedules_string += ']'
            user = request.user
            user_name = request.user.username
            time = get_time()
            action = u"Usuário " + user_name + u" editou o oferecimento id: " + str(offer.idOffer) + " {" \
            + u" Código do Curso: " + str(offer.course.courseCode) \
            + u"; Periodo: " + str(offer.timePeriod) \
            + u"; Turma: T" + str(offer.classNumber) + " => T" + str(classNumber) \
            + u"; Professor: " + offer.professor.name + " => " + Professor.pickById(idProfessor).name \
            + u"; Horários: " + schedules_string_old +  " => " + schedules_string + " }"
            offer_edit_log = Log(user=user, action=action, time=time)
            offer_edit_log.save()
            offer.setProfessor(Professor.pickById(idProfessor))
            offer.classNumber = classNumber
            offer.practical = practical
            numberOfRegistrations = None if not numberOfRegistrations else numberOfRegistrations
            offer.setNumberOfRegistrations(numberOfRegistrations)
            offer.setSchedules(schedules)
            offer.store()
            return HttpResponseRedirect('/interface/offer/' + str(idOffer))
    else:
        form = OfferForm(
            initial={
                'dropDownProfessor': offer.professor.idProfessor,
                'classNumber': offer.classNumber,
                'dropDownTeoricaPratica': offer.practical,
                'numberOfRegistrations': offer.numberOfRegistrations
            })
        form.updateForm()
        form.fields['listSchedules'].initial = [
            schedule.idSchedule for schedule in offer.schedules
        ]
    rendered_page = render(request, 'offer_edit.html', {
        'offer': offer,
        'form': form
    })
    return rendered_page
Beispiel #2
0
def offer_create(request, idTimePeriod, idCourse):
    timePeriod = TimePeriod.pickById(idTimePeriod)
    course = Course.pickById(idCourse)
    if request.method == 'POST':
        form = OfferForm(request.POST)
        form.updateForm()
        if form.is_valid():
            idProfessor = form.cleaned_data['dropDownProfessor']
            classNumber = form.cleaned_data['classNumber']
            practical = form.cleaned_data['dropDownTeoricaPratica']
            numberOfRegistrations = form.cleaned_data['numberOfRegistrations']
            schedulesIds = form.cleaned_data['listSchedules']
            schedules = [
                Schedule.pickById(schedule) for schedule in schedulesIds
            ]
            professor = Professor.pickById(idProfessor)
            practical = (practical == 1)
            offer = Offer(timePeriod, course, classNumber, practical,
                          professor)
            offer.setSchedules(schedules)
            offer.setNumberOfRegistrations(numberOfRegistrations)
            offer.store()
            user = request.user
            user_name = request.user.username
            time = get_time()
            schedules_string = '[ '
            for schedule in schedules:
                schedules_string += str(schedule).replace('ç', 'c') + " "
            schedules_string += ']'
            action = u"Usuário " + user_name + u" criou o oferecimento id: " + str(offer.idOffer) + " {" \
            + u" Código do Curso: " + str(course.courseCode) \
            + u"; Turma: T" + str(classNumber) \
            + u"; Professor: " + professor.name \
            + u"; Periodo: " + str(timePeriod) \
            + u"; Horários: " + schedules_string + " }"
            offer_create_log = Log(user=user, action=action, time=time)
            offer_create_log.save()
            return HttpResponseRedirect('/interface/offer/' +
                                        str(offer.idOffer))
    else:
        form = OfferForm()
        form.updateForm()
    rendered_page = render(request, 'offer_create.html', {
        'form': form,
        'timePeriod': timePeriod,
        'course': course
    })
    return rendered_page
Beispiel #3
0
def offer_edit(request, idOffer):
    offer = Offer.pickById(idOffer)
    if request.method  == 'POST':
        form = OfferForm(request.POST)
        form.updateForm()
        if form.is_valid():
            idProfessor = form.cleaned_data['dropDownProfessor']
            classNumber = form.cleaned_data['classNumber']
            practical = form.cleaned_data['dropDownTeoricaPratica']
            numberOfRegistrations = form.cleaned_data['numberOfRegistrations']
            schedulesIds = form.cleaned_data['listSchedules']
            schedules = [Schedule.pickById(int(schedule)) for schedule in schedulesIds]
            schedules_string_old = '[ '
            schedules_string = '[ '
            for schedule in offer.schedules:
                schedules_string_old += str(schedule).replace('ç','c') + " "
            for schedule in schedules:
                schedules_string += str(schedule).replace('ç','c') + " "
            schedules_string_old += ']'
            schedules_string += ']'
            user= request.user
            user_name = request.user.username
            time = get_time()
            action = u"Usuário " + user_name + u" editou o oferecimento id: " + str(offer.idOffer) + " {" \
            + u" Código do Curso: " + str(offer.course.courseCode) \
            + u"; Periodo: " + str(offer.timePeriod) \
            + u"; Turma: T" + str(offer.classNumber) + " => T" + str(classNumber) \
            + u"; Professor: " + offer.professor.name + " => " + Professor.pickById(idProfessor).name \
            + u"; Horários: " + schedules_string_old +  " => " + schedules_string + " }"
            offer_edit_log = Log(user=user, action=action, time=time)
            offer_edit_log.save()
            offer.setProfessor(Professor.pickById(idProfessor))
            offer.classNumber = classNumber
            offer.practical = practical
            numberOfRegistrations = None if not numberOfRegistrations else numberOfRegistrations
            offer.setNumberOfRegistrations(numberOfRegistrations)
            offer.setSchedules(schedules)
            offer.store()
            return HttpResponseRedirect('/interface/offer/' + str(idOffer))
    else:
        form = OfferForm(initial={'dropDownProfessor': offer.professor.idProfessor,
                                      'classNumber': offer.classNumber,
                                      'dropDownTeoricaPratica': offer.practical,
                                      'numberOfRegistrations': offer.numberOfRegistrations})
        form.updateForm()
        form.fields['listSchedules'].initial = [schedule.idSchedule for schedule in offer.schedules]
    rendered_page = render(request, 'offer_edit.html', {'offer': offer, 'form': form})
    return rendered_page
Beispiel #4
0
def offer_create(request, idTimePeriod, idCourse):
    timePeriod = TimePeriod.pickById(idTimePeriod)
    course = Course.pickById(idCourse)
    if request.method  == 'POST':
        form = OfferForm(request.POST)
        form.updateForm()
        if form.is_valid():
            idProfessor = form.cleaned_data['dropDownProfessor']
            classNumber = form.cleaned_data['classNumber']
            practical = form.cleaned_data['dropDownTeoricaPratica']
            numberOfRegistrations = form.cleaned_data['numberOfRegistrations']
            schedulesIds = form.cleaned_data['listSchedules']
            schedules = [Schedule.pickById(schedule) for schedule in schedulesIds]
            professor = Professor.pickById(idProfessor)
            practical = (practical == 1)
            offer = Offer(timePeriod, course, classNumber, practical, professor)
            offer.setSchedules(schedules)
            offer.setNumberOfRegistrations(numberOfRegistrations)
            offer.store()
            user= request.user
            user_name = request.user.username
            time = get_time()
            schedules_string = '[ '
            for schedule in schedules:
                schedules_string += str(schedule).replace('ç','c') + " "
            schedules_string += ']'
            action = u"Usuário " + user_name + u" criou o oferecimento id: " + str(offer.idOffer) + " {" \
            + u" Código do Curso: " + str(course.courseCode) \
            + u"; Turma: T" + str(classNumber) \
            + u"; Professor: " + professor.name \
            + u"; Periodo: " + str(timePeriod) \
            + u"; Horários: " + schedules_string + " }"
            offer_create_log = Log(user=user, action=action, time=time)
            offer_create_log.save()
            return HttpResponseRedirect('/interface/offer/' + str(offer.idOffer))
    else:
        form = OfferForm()
        form.updateForm()
    rendered_page = render(request, 'offer_create.html', {'form': form, 'timePeriod': timePeriod, 'course': course})
    return rendered_page