コード例 #1
0
def dissertations(request):
    person = mdl.person.find_by_user(request.user)

    if mdl.student.find_by_person(person) and not \
            mdl.tutor.find_by_person(person) and not \
            adviser.find_by_person(person):
            return redirect('home')

    elif adviser.find_by_person(person):
        adv = adviser.search_by_person(person)
        count_advisers_pro_request = dissertation_role.count_by_adviser(adv, 'PROMOTEUR', 'DIR_SUBMIT')

        return layout.render(request, "dissertations.html",
                             {'section': 'dissertations',
                              'person': person,
                              'adviser': adv,
                              'count_advisers_pro_request': count_advisers_pro_request})
    else:
        if request.method == "POST":
            form = AdviserForm(request.POST)
            if form.is_valid():
                adv = Adviser(person=person, available_by_email=False, available_by_phone=False,
                              available_at_office=False)
                adv.save()
                adv = adviser.search_by_person(person)
                count_advisers_pro_request = dissertation_role.count_by_adviser(adv, 'PROMOTEUR', 'DIR_SUBMIT')

                return layout.render(request, "dissertations.html",
                                     {'section': 'dissertations',
                                      'person': person,
                                      'adviser': adv,
                                      'count_advisers_pro_request': count_advisers_pro_request})
        else:
            form = AdviserForm()
            return layout.render(request, 'dissertations_welcome.html', {'form': form})
コード例 #2
0
def _get_rendering_data(form, manager, template, template_prefix):
    data = form.cleaned_data
    person = Person.objects.filter(email=data['email'])
    message, email, message_add = '', '', ''
    form = ManagerAddAdviserPreForm()
    pers = None
    if not data['email']:  # empty search -> step 1
        message = "empty_data"

    elif person and adviser.find_by_person(
            person[0]):  # person already adviser -> step 1
        email = "%s (%s)" % (list(person)[0], data['email'])
        message = "person_already_adviser"

    elif Person.objects.filter(email=data['email']).count(
    ) > 0:  # person found and not adviser -> go forward
        pers = list(person)[0]
        form = ManagerAddAdviserForm() if manager else AddAdviserForm()
        template = template_prefix + 'informations_add.html'

    else:  # person not found by email -> step 1
        email = data['email']
        message = "person_not_found_by_mail"
        message_add = "add_new_person_explanation"
    return email, form, message, message_add, pers, template
コード例 #3
0
def dissertations(request):
    person = get_object_or_404(Person.objects.select_related('adviser'),
                               pk=request.user.person.pk)

    if mdl.student.find_by_person(person) and not \
            tutor.find_by_person(person) and not \
            adviser.find_by_person(person):
        return redirect('home')

    elif adviser.find_by_person(person):
        count_advisers_pro_request = dissertation_role.count_by_adviser(
            person.adviser, dissertation_role_status.PROMOTEUR,
            dissertation_status.DIR_SUBMIT)

        return render(
            request, "dissertations.html", {
                'section': 'dissertations',
                'person': person,
                'adviser': person.adviser,
                'count_advisers_pro_request': count_advisers_pro_request
            })
    else:

        form = AdviserForm(request.POST or None)
        if form.is_valid():
            adv = Adviser(person=person,
                          available_by_email=False,
                          available_by_phone=False,
                          available_at_office=False)
            adv.save()
            count_advisers_pro_request = dissertation_role.count_by_adviser(
                adv, dissertation_role_status.PROMOTEUR,
                dissertation_status.DIR_SUBMIT)
            return render(
                request, "dissertations.html", {
                    'section': 'dissertations',
                    'person': person,
                    'adviser': adv,
                    'count_advisers_pro_request': count_advisers_pro_request
                })
        else:
            return render(request, 'dissertations_welcome.html',
                          {'form': form})
コード例 #4
0
def manager_informations_add(request):
    if request.method == "POST":
        if 'search_form' in request.POST:  # step 2 : second form to select person in list
            form = ManagerAddAdviserPreForm(request.POST)
            if form.is_valid():  # mail format is valid
                data = form.cleaned_data
                person = mdl.person.search_by_email(data['email'])

                if not data['email']:  # empty search -> step 1
                    form = ManagerAddAdviserPreForm()
                    message = "empty_data"
                    return layout.render(
                        request, 'manager_informations_add_search.html', {
                            'form': form,
                            'message': message
                        })

                elif person and adviser.find_by_person(
                        person):  # person already adviser -> step 1
                    form = ManagerAddAdviserPreForm()
                    email = "%s (%s)" % (list(person)[0], data['email'])
                    message = "person_already_adviser"
                    return layout.render(
                        request, 'manager_informations_add_search.html', {
                            'form': form,
                            'message': message,
                            'email': email
                        })
                elif mdl.person.count_by_email(
                        data['email']
                ) > 0:  # person found and not adviser -> go forward
                    pers = list(person)[0]
                    select_form = ManagerAddAdviserForm()
                    return layout.render(request,
                                         'manager_informations_add.html', {
                                             'form': select_form,
                                             'pers': pers
                                         })

                else:  # person not found by email -> step 1
                    form = ManagerAddAdviserPreForm()
                    email = data['email']
                    message = "person_not_found_by_mail"
                    message_add = "add_new_person_explanation"
                    return layout.render(
                        request, 'manager_informations_add_search.html', {
                            'form': form,
                            'message': message,
                            'email': email,
                            'message_add': message_add
                        })
            else:  # invalid form (invalid format for email)
                form = ManagerAddAdviserPreForm()
                message = "invalid_data"
                return layout.render(request,
                                     'manager_informations_add_search.html', {
                                         'form': form,
                                         'message': message
                                     })

        else:  # step 3 : everything ok, register the person as adviser
            form = ManagerAddAdviserForm(request.POST)
            if form.is_valid():
                adv = form.save(commit=False)
                adv.save()
                return redirect('manager_informations_detail', pk=adv.pk)
            else:
                return redirect('manager_informations')

    else:  # step 1 : initial form to search person by email
        form = ManagerAddAdviserPreForm()
        return layout.render(request, 'manager_informations_add_search.html',
                             {'form': form})