def manager_informations_add_person(request): if request.method == "POST": form = ManagerAddAdviserPerson(request.POST) if form.is_valid(): person = Person(**form.cleaned_data, source=person_source_type.DISSERTATION) person.save() adv = adviser.add(person, 'PRF', False, False, False, '') return redirect('manager_informations_detail', pk=adv.pk) else: form = ManagerAddAdviserPerson() return render(request, 'manager_information_add_person.html', {'form': form})
def _create_update_person(user, person, user_infos): if not person: person = find_by_user(user) if not person: person = Person(user=user, global_id=user_infos.get('USER_FGS'), first_name=user_infos.get('USER_FIRST_NAME'), last_name=user_infos.get('USER_LAST_NAME'), email=user_infos.get('USER_EMAIL')) person.save() person_created.send(sender=None, person=person) else: updated, person = _update_person_if_necessary( person, user, user_infos.get('USER_FGS')) return person
def test_necessary_update(self): user = get_or_create_user(self.user_infos) person = Person(user=None, first_name="user3", last_name="user3", email='*****@*****.**', global_id="1111111") updated, updated_person = mdl_signals._update_person_if_necessary(user=user, person=person, global_id=self.user_infos.get('USER_FGS')) self.assertTrue(updated) assert_person_match_user_infos(self, updated_person, self.user_infos)
def test_unnecessary_update(self): user = get_or_create_user(self.user_infos) person = Person(user=user, first_name=self.user_infos.get('USER_FIRST_NAME'), last_name=self.user_infos.get('USER_LAST_NAME'), email=self.user_infos.get('USER_EMAIL'), global_id=self.user_infos.get('USER_FGS')) updated, updated_person = mdl_signals._update_person_if_necessary(user=user, person=person, global_id=self.user_infos.get('USER_FGS')) self.assertFalse(updated) assert_person_match_user_infos(self, updated_person, self.user_infos)
def get_or_create_person(user=None, first_name=None, global_id=None): person = None created = False if user: person = mdl_person.find_by_user(user) if not person and global_id: person = mdl_person.find_by_global_id(global_id) if not person: person = Person(user=user, first_name=first_name, global_id=global_id) created = True if created: person.user = user person.first_name = first_name person.global_id = global_id person.save() return person
def test_should_give_warning_messages_when_volume_partim_superior_to_volume_parent( self): self.charge_lecturing_1.allocation_charge = 50 self.charge_lecturing_1.save() msgs = get_charge_repartition_warning_messages( self.full_luy.learning_container_year) tutor_name = Person.get_str( self.attribution_full.tutor.person.first_name, self.attribution_full.tutor.person.middle_name, self.attribution_full.tutor.person.last_name) tutor_name_with_function = "{} ({})".format( tutor_name, _(self.attribution_full.get_function_display())) self.assertListEqual(msgs, [ _("The sum of volumes for the partims for professor %(tutor)s is superior to the " "volume of full UE for this professor") % { "tutor": tutor_name_with_function } ])
def get_charge_repartition_warning_messages(learning_container_year): total_charges_by_attribution_and_learning_subtype = AttributionChargeNew.objects \ .filter(attribution__learning_container_year=learning_container_year) \ .order_by("attribution__tutor", "attribution__function", "attribution__start_year") \ .values("attribution__tutor", "attribution__tutor__person__first_name", "attribution__tutor__person__middle_name", "attribution__tutor__person__last_name", "attribution__function", "attribution__start_year", "learning_component_year__learning_unit_year__subtype") \ .annotate(total_volume=Sum("allocation_charge")) charges_by_attribution = itertools.groupby( total_charges_by_attribution_and_learning_subtype, lambda rec: "{}_{}_{}".format(rec["attribution__tutor"], rec[ "attribution__start_year"], rec["attribution__function"])) msgs = [] for attribution_key, charges in charges_by_attribution: charges = list(charges) subtype_key = "learning_component_year__learning_unit_year__subtype" full_total_charges = next( (charge["total_volume"] for charge in charges if charge[subtype_key] == learning_unit_year_subtypes.FULL), 0) partim_total_charges = next( (charge["total_volume"] for charge in charges if charge[subtype_key] == learning_unit_year_subtypes.PARTIM), 0) partim_total_charges = partim_total_charges or 0 full_total_charges = full_total_charges or 0 if partim_total_charges > full_total_charges: tutor_name = Person.get_str( charges[0]["attribution__tutor__person__first_name"], charges[0]["attribution__tutor__person__middle_name"], charges[0]["attribution__tutor__person__last_name"]) tutor_name_with_function = "{} ({})".format( tutor_name, getattr(Functions, charges[0]["attribution__function"]).value) msg = _( "The sum of volumes for the partims for professor %(tutor)s is superior to the " "volume of parent learning unit for this professor") % { "tutor": tutor_name_with_function } msgs.append(msg) return msgs
def get_or_create_person(user=None, first_name=None, global_id=None): person = None created = False if user: person = mdl_person.find_by_user(user) if not person and global_id: person = mdl_person.find_by_global_id(global_id) if not person: person = Person(user=user, first_name=first_name, global_id=global_id) created = True if created: person.user = user person.first_name = first_name person.global_id = global_id person.save() return person
def email_destination_person(): return Person(last_name='Test user', gender='M', email='person@localhost')