def test_return_modification_when_no_data_changed(self): proposal = ProposalLearningUnitFactory( type=ProposalType.MODIFICATION.name, initial_data={}) actual_proposal_type = compute_proposal_type( proposal, proposal.learning_unit_year) self.assertEqual(proposal_type.ProposalType.MODIFICATION.name, actual_proposal_type)
def test_return_transformation_and_modification_when_modifying_first_letter_and_other_field( self): actual_proposal_type = compute_proposal_type( ["first_letter", "common_title"], None) self.assertEqual( proposal_type.ProposalType.TRANSFORMATION_AND_MODIFICATION.name, actual_proposal_type)
def save(self): # First save to calculate ProposalType proposal = self.form_proposal.save() self.learning_unit_form_container.save() learning_unit_year = self.learning_unit_form_container.instance proposal.type = compute_proposal_type(proposal, learning_unit_year) proposal.save() return proposal
def test_return_suppression_type_when_suppresion_is_initial_proposal_type( self): proposal = ProposalLearningUnitFactory( type=ProposalType.SUPPRESSION.name) actual_proposal_type = compute_proposal_type( proposal, proposal.learning_unit_year) self.assertEqual(proposal_type.ProposalType.SUPPRESSION.name, actual_proposal_type)
def test_return_modification_when_data_changed_consist_of_other_fields_than_first_letter_or_acronym( self): proposal = ProposalLearningUnitFactory( type=ProposalType.MODIFICATION.name, initial_data={'learning_container_year': { 'common_title': 'bibi' }}) actual_proposal_type = compute_proposal_type( proposal, proposal.learning_unit_year) self.assertEqual(proposal_type.ProposalType.MODIFICATION.name, actual_proposal_type)
def test_return_transformation_when_data_changed_consist_of_first_letter( self): proposal = ProposalLearningUnitFactory( type=ProposalType.MODIFICATION.name, initial_data={'learning_unit_year': { 'acronym': 'bibi' }}) actual_proposal_type = compute_proposal_type( proposal, proposal.learning_unit_year) self.assertEqual(proposal_type.ProposalType.TRANSFORMATION.name, actual_proposal_type)
def test_return_transformation_and_modification_when_modifying_acronym_and_other_field( self): proposal = ProposalLearningUnitFactory( type=ProposalType.MODIFICATION.name, initial_data={ 'learning_unit_year': { 'acronym': 'bobo' }, 'learning_container_year': { 'common_title': 'bibi' } }) actual_proposal_type = compute_proposal_type( proposal, proposal.learning_unit_year) self.assertEqual( proposal_type.ProposalType.TRANSFORMATION_AND_MODIFICATION.name, actual_proposal_type)
def _update_proposal(request, user_person, proposal): initial_data = compute_form_initial_data(proposal.learning_unit_year) initial_data.update(_build_proposal_data(proposal)) # Workaround Set initial data from proposal initial data json to compute effectively data modified # and compute proposal type initial_data_from_json = compute_form_initial_data_from_proposal_json( proposal.initial_data) initial_data_from_json.update(_build_proposal_data(proposal)) proposal_form = LearningUnitProposalModificationForm( request.POST or None, initial=initial_data_from_json, instance=proposal, learning_unit=proposal.learning_unit_year.learning_unit, person=user_person) if proposal_form.is_valid(): try: changed_fields = proposal_form.changed_data_for_fields_that_can_be_modified type_proposal = business_proposal.compute_proposal_type( changed_fields, initial_data_from_json.get("type")) proposal_form.save(proposal.learning_unit_year, type_proposal, proposal_form.cleaned_data.get("state")) display_success_messages(request, _("proposal_edited_successfully")) return HttpResponseRedirect( reverse('learning_unit', args=[proposal.learning_unit_year.id])) except (IntegrityError, ValueError) as e: display_error_messages(request, e.args[0]) proposal_form.initial = initial_data return layout.render( request, 'learning_unit/proposal/update_modification.html', { 'learning_unit_year': proposal.learning_unit_year, 'person': user_person, 'form': proposal_form, 'experimental_phase': True })
def propose_modification_of_learning_unit(request, learning_unit_year_id): learning_unit_year = get_object_or_404(LearningUnitYear, id=learning_unit_year_id) user_person = get_object_or_404(Person, user=request.user) if not is_eligible_for_modification_proposal(learning_unit_year, user_person): raise PermissionDenied( "Learning unit year not eligible for proposal or user has not sufficient rights." ) initial_data = compute_form_initial_data(learning_unit_year) if request.method == 'POST': modified_post_data = request.POST.copy() modified_post_data["academic_year"] = str( learning_unit_year.academic_year.id) form = LearningUnitProposalModificationForm(modified_post_data, initial=initial_data) if form.is_valid(): type_proposal = compute_proposal_type(form.initial, form.cleaned_data) form.save(learning_unit_year, user_person, type_proposal, proposal_state.ProposalState.FACULTY.name) messages.add_message( request, messages.SUCCESS, _("success_modification_proposal").format( type_proposal, learning_unit_year.acronym)) return redirect('learning_unit', learning_unit_year_id=learning_unit_year.id) else: form = LearningUnitProposalModificationForm(initial=initial_data) return render( request, 'proposal/learning_unit_modification.html', { 'learning_unit_year': learning_unit_year, 'person': user_person, 'form': form, 'experimental_phase': True })
def propose_modification_of_learning_unit(request, learning_unit_year_id): learning_unit_year = get_object_or_404(LearningUnitYear, id=learning_unit_year_id) user_person = get_object_or_404(Person, user=request.user) initial_data = compute_form_initial_data(learning_unit_year) if request.method == 'POST': form = LearningUnitProposalModificationForm(request.POST, initial=initial_data) if form.is_valid(): type_proposal = compute_proposal_type(initial_data, request.POST) form.save(learning_unit_year, user_person, type_proposal, proposal_state.ProposalState.FACULTY.name) messages.add_message(request, messages.SUCCESS, _("success_modification_proposal") .format(_(type_proposal), learning_unit_year.acronym)) return redirect('learning_unit', learning_unit_year_id=learning_unit_year.id) else: form = LearningUnitProposalModificationForm(initial=initial_data) return render(request, 'learning_unit/proposal/update.html', { 'learning_unit_year': learning_unit_year, 'person': user_person, 'form': form, 'experimental_phase': True})
def learning_unit_modification_proposal(request, learning_unit_year_id): learning_unit_year = get_object_or_404(LearningUnitYear, id=learning_unit_year_id) user_person = get_object_or_404(Person, user=request.user) initial_data = compute_form_initial_data(learning_unit_year) proposal = proposal_learning_unit.find_by_learning_unit_year( learning_unit_year) form = LearningUnitProposalModificationForm( request.POST or None, initial=initial_data, instance=proposal, learning_unit=learning_unit_year.learning_unit, person=user_person) if form.is_valid(): type_proposal = business_proposal.compute_proposal_type( form.changed_data_for_fields_that_can_be_modified, initial_data.get("type")) form.save(learning_unit_year, type_proposal, compute_proposal_state(user_person)) display_success_messages( request, _("success_modification_proposal").format( _(type_proposal), learning_unit_year.acronym)) return redirect('learning_unit', learning_unit_year_id=learning_unit_year.id) return layout.render( request, 'learning_unit/proposal/create_modification.html', { 'learning_unit_year': learning_unit_year, 'person': user_person, 'form': form, 'experimental_phase': True })
def test_return_modification_when_no_data_changed(self): actual_proposal_type = compute_proposal_type([], None) self.assertEqual(proposal_type.ProposalType.MODIFICATION.name, actual_proposal_type)
def test_return_modification_when_data_changed_consist_of_other_fields_than_first_letter_or_acronym( self): actual_proposal_type = compute_proposal_type(["common_title"], None) self.assertEqual(proposal_type.ProposalType.MODIFICATION.name, actual_proposal_type)
def test_return_transformation_when_data_changed_consist_of_acronym(self): actual_proposal_type = compute_proposal_type(["acronym"], None) self.assertEqual(proposal_type.ProposalType.TRANSFORMATION.name, actual_proposal_type)
def test_return_suppression_type_when_suppresion_is_initial_proposal_type( self): actual_proposal_type = compute_proposal_type( [], proposal_type.ProposalType.SUPPRESSION.name) self.assertEqual(proposal_type.ProposalType.SUPPRESSION.name, actual_proposal_type)
def test_return_creation_type_when_creation_is_initial_proposal_type(self): actual_proposal_type = compute_proposal_type( [], proposal_type.ProposalType.CREATION.name) self.assertEqual(proposal_type.ProposalType.CREATION.name, actual_proposal_type)