Ejemplo n.º 1
0
def partner_preferences(student, partner_popup):
    offer = Student.objects.filter(partner=student)
    partner = PartnerForm(instance=student)

    return {
        'student': student,
        'partner': partner,
        'offer': offer,
        'partner_popup': partner_popup
    }
Ejemplo n.º 2
0
def preferences(request, id):
    if not Student.objects.filter(magic_id=id).exists():
        return index(request, popup=get_invalid_id_popup())

    student = Student.objects.get(magic_id=id)
    response = None

    if request.method == 'POST':
        if 'preference' in request.POST:
            preference = PreferenceForm(request.POST, instance=student)

            if preference.is_valid():
                preference.save()
        elif 'partner' in request.POST:
            partner = PartnerForm(request.POST, instance=student)

            if student.partner is None and partner.is_valid():
                partner.save()

                response = partner.get_successful_proposal_popup()
        elif 'username' in request.POST:
            partner = Student.objects.get(username=request.POST.get("username"))

            if partner is None:
                response = get_student_does_not_exist_popup()
            elif 'accept' in request.POST:
                response = student.marry_to(partner)
            elif 'reject' in request.POST:
                response = student.reject_proposal(partner)
            elif 'withdraw' in request.POST:
                response = student.withdraw_proposal()

    return render(request, 'portal/preferences.html', {'student': student, 'partner_popup': response})
Ejemplo n.º 3
0
 def create_form(instance=None, partner=None):
     if not partner:
         form_data = {}
     else:
         form_data = {'partner': partner.id}
     return PartnerForm(instance=instance, data=form_data)