Beispiel #1
0
def get_proposal_learning_unit_creation_form(request, academic_year):
    person = get_object_or_404(Person, user=request.user)
    academic_year_pk = request.POST.get(
        'academic_year',
        academic_year) if person.is_faculty_manager else academic_year
    academic_year = get_object_or_404(AcademicYear, pk=academic_year_pk)

    proposal_form = CreationProposalBaseForm(request.POST or None, person,
                                             academic_year)
    if proposal_form.is_valid():
        proposal = proposal_form.save()
        success_msg = _(
            "Proposal learning unit <a href='%(link)s'> %(acronym)s (%(academic_year)s) </a> successfuly created."
        ) % {
            'link':
            reverse("learning_unit",
                    kwargs={
                        'learning_unit_year_id': proposal.learning_unit_year.id
                    }),
            'acronym':
            proposal.learning_unit_year.acronym,
            'academic_year':
            proposal.learning_unit_year.academic_year
        }
        display_success_messages(request, success_msg, extra_tags='safe')
        return redirect('learning_unit',
                        learning_unit_year_id=proposal.learning_unit_year.pk)

    return render(request, "learning_unit/proposal/creation.html",
                  proposal_form.get_context())
Beispiel #2
0
 def test_proposal_learning_unit_form_with_empty_title_fields(self):
     learning_unit_form = CreationProposalBaseForm(
         self.get_empty_title_fields(), person=self.person)
     self.assertFalse(learning_unit_form.is_valid(),
                      learning_unit_form.errors)
     lcy_errors = learning_unit_form.learning_unit_form_container.forms[
         LearningContainerYearModelForm].errors
     self.assertEqual(lcy_errors['common_title'],
                      [_('must_set_common_title_or_specific_title')])
Beispiel #3
0
    def test_proposal_learning_unit_form_with_empty_fields(self):
        learning_unit_form = CreationProposalBaseForm(self.get_empty_required_fields(), person=self.person)
        self.assertFalse(learning_unit_form.is_valid(), learning_unit_form.errors)
        luy_errors = learning_unit_form.learning_unit_form_container.forms[LearningUnitYearModelForm].errors
        lcy_errors = learning_unit_form.learning_unit_form_container.forms[LearningContainerYearModelForm].errors

        self.assertEqual(luy_errors['acronym'], [_('This field is required.')])
        self.assertEqual(lcy_errors['container_type'], [_('This field is required.')])
        self.assertEqual(luy_errors['periodicity'], [_('This field is required.')])
        self.assertEqual(luy_errors['language'], [_('This field is required.')])
        self.assertEqual(luy_errors['campus'], [_('This field is required.')])
Beispiel #4
0
    def test_proposal_learning_unit_add_with_valid_data_for_faculty_manager(self):
        learning_unit_form = CreationProposalBaseForm(self.get_valid_data(), person=self.faculty_person)

        self.assertTrue(learning_unit_form.is_valid(), learning_unit_form.errors)
        self.client.force_login(self.faculty_person.user)
        url = reverse(get_proposal_learning_unit_creation_form, args=[self.current_academic_year.id])
        response = self.client.post(url, data=self.get_valid_data())
        self.assertEqual(response.status_code, 302)
        count_learning_unit_year = LearningUnitYear.objects.all().count()
        self.assertEqual(count_learning_unit_year, 1)
        count_proposition_by_author = ProposalLearningUnit.objects.filter(author=self.faculty_person).count()
        self.assertEqual(count_proposition_by_author, 1)
Beispiel #5
0
    def test_academic_year_default_from_form_equal(self):
        full_form = CreationProposalBaseForm(self.get_valid_data(),
                                             person=self.faculty_person)

        self.assertEqual(
            self.next_academic_year.id,
            full_form.learning_unit_form_container.academic_year.id)
Beispiel #6
0
def get_proposal_learning_unit_creation_form(request, academic_year):
    person = get_object_or_404(Person, user=request.user)
    academic_year = get_object_or_404(AcademicYear, pk=academic_year)

    proposal_form = CreationProposalBaseForm(request.POST or None, person,
                                             academic_year)

    if proposal_form.is_valid():
        proposal = proposal_form.save()
        show_success_proposal_learning_unit_year_creation_message(
            request, proposal.learning_unit_year)
        return redirect('learning_unit',
                        learning_unit_year_id=proposal.learning_unit_year.pk)

    return render(request, "learning_unit/proposal/creation.html",
                  proposal_form.get_context())
Beispiel #7
0
    def test_restrict_type_choice_for_proposal_creation(self):
        full_form = CreationProposalBaseForm(self.get_valid_data(),
                                             person=self.faculty_person)

        self.assertEqual(full_form.fields['container_type'].choices,
                         [(None, '---------'), ('COURSE', 'Cours'),
                          ('DISSERTATION', 'Mémoire'),
                          ('INTERNSHIP', 'Stage')])
Beispiel #8
0
    def test_academic_year_from_form_equal_to_data(self):
        full_form = CreationProposalBaseForm(
            self.get_valid_data(),
            person=self.faculty_person,
            default_ac_year=AcademicYear.objects.get(
                pk=self.get_valid_data()['academic_year']))

        self.assertEqual(
            self.get_valid_data()['academic_year'],
            full_form.learning_unit_form_container.academic_year.id)