def _display_adapted_ucl_registration_message(admission, request): if admission.ucl_registration_complete == UCLRegistrationState.SENDED.name: display_warning_messages( request, _('Folder sended to EPC : waiting for response')) elif admission.ucl_registration_complete == UCLRegistrationState.REJECTED.name: display_error_messages( request, mark_safe( _('Folder injection into EPC failed : %(reasons)s') % {'reasons': admission.get_ucl_registration_error_display()})) elif admission.ucl_registration_complete == UCLRegistrationState.DEMANDE.name: display_info_messages( request, _('Folder injection into EPC succeeded : UCLouvain registration on demand' )) elif admission.ucl_registration_complete == UCLRegistrationState.INSCRIT.name: display_success_messages( request, _('Folder injection into EPC succeeded : UCLouvain registration completed' )) elif admission.ucl_registration_complete != UCLRegistrationState.INIT_STATE.name: display_info_messages( request, _('Folder injection into EPC succeeded : UCLouvain registration status : %(status)s' ) % {'status': admission.get_ucl_registration_complete_display()})
def get_form_kwargs(self): """ For the creation, the group_element_year needs a parent and a child """ kwargs = super().get_form_kwargs() try: cached_data = extract_child_from_cache(self.education_group_year, self.request.user) kwargs.update({ 'parent': self.education_group_year, 'child_branch': cached_data.get('child_branch'), 'child_leaf': cached_data.get('child_leaf') }) child = kwargs['child_branch'] if kwargs[ 'child_branch'] else kwargs['child_leaf'] strategy = AttachEducationGroupYearStrategy if isinstance(child, EducationGroupYear) else \ AttachLearningUnitYearStrategy strategy(parent=self.education_group_year, child=child).is_valid() except ObjectDoesNotExist: warning_msg = _("Please select an item before attach it") display_warning_messages(self.request, warning_msg) except ValidationError as e: display_error_messages(self.request, e.messages) except IntegrityError as e: warning_msg = str(e) display_warning_messages(self.request, warning_msg) return kwargs
def _common_success_redirect(request, form, root): education_group_year = form.save() success_msgs = [] if not education_group_year.education_group.end_year or \ education_group_year.education_group.end_year >= education_group_year.academic_year.year: success_msgs = [ _get_success_message_for_update_education_group_year( root.pk, education_group_year) ] if hasattr(form, 'education_group_year_postponed'): success_msgs += [ _get_success_message_for_update_education_group_year(egy.id, egy) for egy in form.education_group_year_postponed ] if hasattr(form, 'education_group_year_deleted'): success_msgs += [ _get_success_message_for_deleted_education_group_year(egy) for egy in form.education_group_year_deleted ] url = _get_success_redirect_url(root, education_group_year) display_success_messages(request, success_msgs, extra_tags='safe') if hasattr(form, "warnings"): display_warning_messages(request, form.warnings) return redirect(url)
def _common_success_redirect(request, form, root, groupelementyear_form=None): groupelementyear_changed = [] if groupelementyear_form: groupelementyear_form.save() groupelementyear_changed = groupelementyear_form.changed_forms() education_group_year = form.save() success_msgs = [] if not education_group_year.education_group.end_year or \ education_group_year.education_group.end_year.year >= education_group_year.academic_year.year: success_msgs = [ _get_success_message_for_update_education_group_year( root.pk, education_group_year) ] if hasattr(form, 'education_group_year_postponed'): success_msgs += [ _get_success_message_for_update_education_group_year(egy.id, egy) for egy in form.education_group_year_postponed ] if hasattr(form, 'education_group_year_deleted'): success_msgs += [ _get_success_message_for_deleted_education_group_year(egy) for egy in form.education_group_year_deleted ] if groupelementyear_changed: anac = str(education_group_year.academic_year) if len(groupelementyear_changed) > 1: success_msgs += [ "{} : <ul><li>{}</li></ul>".format( _("The following links has been updated"), "</li><li>".join([ " - ".join([ gey.instance.child_branch.partial_acronym, gey.instance.child_branch.acronym, anac ]) if gey.instance.child_branch else " - ".join( [gey.instance.child_leaf.acronym, anac]) for gey in groupelementyear_changed ])) ] else: gey = groupelementyear_changed[0].instance success_msgs += [ _("The link of %(acronym)s has been updated") % { 'acronym': " - ".join([ gey.child_branch.partial_acronym, gey.child_branch.acronym, anac ]) if gey.child_branch else " - ".join( [gey.child_leaf.acronym, anac]) } ] url = _get_success_redirect_url(root, education_group_year) display_success_messages(request, success_msgs, extra_tags='safe') if hasattr(form, "warnings"): display_warning_messages(request, form.warnings) return redirect(url)
def get(self, request, *args, **kwargs): # Get does not need to fetch self.object again context = self.get_context_data(object=self.object) if proposal_learning_unit.is_learning_unit_year_in_proposal(self.object) and \ self.object.get_partims_related().exists(): display_warning_messages(request, _("The learning unit have partim")) return self.render_to_response(context)
def _attach(request, group_element_year, *args, **kwargs): parent = get_object_or_404(EducationGroupYear, pk=kwargs['education_group_year_id']) try: group_element_years.management.attach_from_cache(parent) success_msg = _("Attached to %(acronym)s") % {'acronym': parent} display_success_messages(request, success_msg) except ObjectDoesNotExist: warning_msg = _("Please Select or Move an item before Attach it") display_warning_messages(request, warning_msg)
def learning_units_summary_list(request): a_user_person = request.user.person found_learning_units = LearningUnitYear.objects.none() initial_academic_year = current_academic_year() if academic_calendar.is_academic_calendar_has_started( initial_academic_year, SUMMARY_COURSE_SUBMISSION): initial_academic_year = initial_academic_year.next() search_form = LearningUnitYearForm(request.GET or None, initial={ 'academic_year_id': initial_academic_year, 'with_entity_subordinated': True }) try: if search_form.is_valid(): found_learning_units = search_form.get_learning_units_and_summary_status( requirement_entities=a_user_person.find_main_entities_version, ) check_if_display_message(request, found_learning_units) except TooManyResultsException: display_error_messages(request, 'too_many_results') responsible_and_learning_unit_yr_list = get_responsible_and_learning_unit_yr_list( found_learning_units) for luy in found_learning_units: luy.errors = can_learning_unit_year_educational_information_be_udpated( learning_unit_year_id=luy) if request.GET.get('xls_status') == "xls_teaching_material": try: return generate_xls_teaching_material(request.user, found_learning_units) except ObjectDoesNotExist: display_warning_messages( request, _("the list to generate is empty.").capitalize()) form_comparison = SelectComparisonYears( academic_year=get_academic_year_of_reference(found_learning_units)) context = { 'form': search_form, 'formset': _get_formset(request, responsible_and_learning_unit_yr_list), 'learning_units_count': found_learning_units.count(), 'search_type': SUMMARY_LIST, 'is_faculty_manager': a_user_person.is_faculty_manager, 'form_comparison': form_comparison, 'page_obj': paginate_queryset(found_learning_units, request.GET), } return render(request, "learning_units.html", context)
def learning_units_summary_list(request): a_user_person = find_by_user(request.user) learning_units_found = [] initial_academic_year = current_academic_year() if academic_calendar.is_academic_calendar_has_started( initial_academic_year, SUMMARY_COURSE_SUBMISSION): initial_academic_year = initial_academic_year.next() search_form = LearningUnitYearForm( request.GET or None, initial={'academic_year_id': initial_academic_year}) try: if search_form.is_valid(): learning_units_found_search = search_form.get_learning_units( requirement_entities=a_user_person.find_main_entities_version, luy_status=True) # TODO refactoring : too many queries learning_units_found = get_learning_units_and_summary_status( learning_units_found_search) check_if_display_message(request, learning_units_found_search) except TooManyResultsException: display_error_messages(request, 'too_many_results') responsible_and_learning_unit_yr_list = get_responsible_and_learning_unit_yr_list( learning_units_found) learning_units = sorted(learning_units_found, key=lambda learning_yr: learning_yr.acronym) errors = [ can_learning_unit_year_educational_information_be_udpated( learning_unit_year_id=luy.id) for luy in learning_units ] if request.GET.get('xls_status') == "xls_teaching_material": try: return generate_xls_teaching_material(request.user, learning_units_found) except ObjectDoesNotExist: display_warning_messages( request, _("the list to generate is empty.").capitalize()) form_comparison = SelectComparisonYears( academic_year=get_academic_year_of_reference(learning_units_found)) context = { 'form': search_form, 'formset': _get_formset(request, responsible_and_learning_unit_yr_list), 'learning_units_with_errors': list(zip(learning_units, errors)), 'search_type': SUMMARY_LIST, 'is_faculty_manager': a_user_person.is_faculty_manager(), 'form_comparison': form_comparison } return layout.render(request, "learning_units.html", context)
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) if self.strategy.is_valid(): context['confirmation_message'] = _( "Are you sure you want to detach %(acronym)s ?") % { "acronym": self.object.child.acronym } display_warning_messages(self.request, self.strategy.warnings) else: display_error_messages(self.request, self.strategy.errors) return context
def add_warning_messages(self, context): root = context["root"] prerequisite = context["prerequisite"] learning_unit_year = context["learning_unit_year"] learning_unit_inconsistent = get_prerequisite_acronyms_which_are_outside_of_education_group(root, prerequisite)\ if prerequisite else [] if learning_unit_inconsistent: display_warning_messages( self.request, _("The prerequisites %s for the learning unit %s are not inside the selected formation %s") % (", ".join(learning_unit_inconsistent), learning_unit_year, root))
def _update_or_create_suppression_proposal(request, learning_unit_year, proposal=None): person = get_object_or_404(Person, user=request.user) proposal_type = ProposalType.SUPPRESSION.name initial = _get_initial(learning_unit_year, proposal, person, proposal_type=proposal_type) max_year = _get_max_year(learning_unit_year, proposal) form_end_date = LearningUnitEndDateForm(request.POST or None, learning_unit_year, max_year=max_year) form_proposal = ProposalLearningUnitForm(request.POST or None, person=person, instance=proposal, initial=initial) if form_end_date.is_valid() and form_proposal.is_valid(): with transaction.atomic(): form_proposal.save() # For the proposal, we do not update learning_unit_year form_end_date.save(update_learning_unit_year=False) display_success_messages( request, _("You proposed a modification of type {} for the learning unit {}." ).format(_(proposal_type), learning_unit_year.acronym)) return redirect('learning_unit', learning_unit_year_id=learning_unit_year.id) context = get_learning_unit_identification_context(learning_unit_year.id, person) context.update({ 'person': person, 'form_end_date': form_end_date, 'form_proposal': form_proposal, 'experimental_phase': True }) if learning_unit_year.get_partims_related().exists(): display_warning_messages(request, _("The learning unit have partim")) if proposal: return render(request, 'learning_unit/proposal/update_suppression.html', context) return render(request, 'learning_unit/proposal/create_suppression.html', context)
def get_form_class(self): elements_to_attach = fetch_elements_selected(self.request.GET, self.request.user) if not elements_to_attach: display_warning_messages( self.request, _("Please cut or copy an item before attach it")) return modelformset_factory( model=GroupElementYear, form=GroupElementYearForm, formset=BaseGroupElementYearFormset, extra=len(elements_to_attach), )
def learning_unit_attributions(request, learning_unit_year_id): context = get_common_context_learning_unit_year(learning_unit_year_id, request.user.person) context['attributions'] = attribution_charge_new.find_attributions_with_charges(learning_unit_year_id) context["can_manage_charge_repartition"] = business_perms.is_eligible_to_manage_charge_repartition( context["learning_unit_year"], request.user.person ) context["can_manage_attribution"] = business_perms.is_eligible_to_manage_attributions( context["learning_unit_year"], request.user.person ) warning_msgs = get_charge_repartition_warning_messages(context["learning_unit_year"].learning_container_year) display_warning_messages(request, warning_msgs) return render(request, "learning_unit/attributions.html", context)
def get(self, request, *args, **kwargs): if SEARCH_URL_PART in self.request.META.get('HTTP_REFERER', ''): add_to_session(request, 'search_url', self.request.META.get('HTTP_REFERER')) # Get does not need to fetch self.object again context = self.get_context_data(object=self.object) if proposal_learning_unit.is_learning_unit_year_in_proposal(self.object) and \ self.object.get_partims_related().exists(): display_warning_messages(request, _("The learning unit have partim")) return self.render_to_response(context)
def _save_form_and_display_messages(request, form): records = None try: records = form.save() display_warning_messages(request, getattr(form, 'warnings', [])) display_success_messages(request, _('The learning unit has been updated.')) except ConsistencyError as e: error_list = e.error_list error_list.insert(0, _('The learning unit has been updated until %(year)s.') % {'year': e.last_instance_updated.academic_year}) display_error_messages(request, e.error_list) return records
def get_form_kwargs(self): kwargs = super().get_form_kwargs() try: perms.can_change_education_group(self.request.user, self.get_object().parent) except PermissionDenied as e: msg = "{}: {}".format(str(self.get_object().parent), str(e)) display_warning_messages(self.request, msg) if not self.detach_strategy.is_valid(): display_error_messages(self.request, self.detach_strategy.errors) return kwargs
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) try: cached_data = extract_child_from_cache(self.education_group_year, self.request.user) child = cached_data['child_branch'] if cached_data.get( 'child_branch') else cached_data.get('child_leaf') context['object_to_attach'] = child context['source_link'] = cached_data.get('source_link') context['education_group_year_parent'] = self.education_group_year except ObjectDoesNotExist: warning_msg = _("Please select an item before attach it") display_warning_messages(self.request, warning_msg) return context
def add_warning_messages(self, context): root = context["root"] prerequisite = context["prerequisite"] learning_unit_year = context["learning_unit_year"] learning_unit_inconsistent = get_prerequisite_acronyms_which_are_outside_of_education_group(root, prerequisite)\ if prerequisite else [] if learning_unit_inconsistent: display_warning_messages( self.request, _("The prerequisites %(prerequisites)s for the learning unit %(learning_unit)s " "are not inside the selected training %(root)s") % { "prerequisites": ", ".join(learning_unit_inconsistent), "learning_unit": learning_unit_year, "root": root, })
def _save_form_and_display_messages(request, form): records = None try: records = form.save() display_warning_messages(request, getattr(form, 'warnings', [])) if bool(int(request.POST.get('postponement', 0))): display_success_messages(request, _('The learning unit has been updated (with report).')) else: display_success_messages(request, _('The learning unit has been updated (without report).')) except ConsistencyError as e: error_list = e.error_list error_list.insert(0, _('The learning unit has been updated until %(year)s.') % {'year': e.last_instance_updated.academic_year}) display_error_messages(request, e.error_list) return records
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) msg = "%(acronym)s" % {"acronym": self.object.child.acronym} if hasattr(self.object.child, 'partial_acronym'): msg = "%(partial_acronym)s - %(acronym)s" % { "acronym": msg, "partial_acronym": self.object.child.partial_acronym } if self.strategy.is_valid(): context['confirmation_message'] = _("Are you sure you want to detach %(acronym)s ?") % { "acronym": msg } display_warning_messages(self.request, self.strategy.warnings) else: display_error_messages(self.request, self.strategy.errors) return context
def learning_unit_attributions(request, learning_unit_year_id): person = get_object_or_404(Person, user=request.user) context = get_common_context_learning_unit_year(learning_unit_year_id, person) context[ 'attributions'] = attribution_charge_new.find_attributions_with_charges( learning_unit_year_id) context["can_manage_charge_repartition"] = \ business_perms.is_eligible_to_manage_charge_repartition(context["learning_unit_year"], person) context["can_manage_attribution"] = \ business_perms.is_eligible_to_manage_attributions(context["learning_unit_year"], person) context['experimental_phase'] = True warning_msgs = get_charge_repartition_warning_messages( context["learning_unit_year"].learning_container_year) display_warning_messages(request, warning_msgs) return render(request, "learning_unit/attributions.html", context)
def get_redirect_url(self, *args, **kwargs): self.pattern_name = 'group_element_year_create' try: perms.can_change_education_group(self.request.user, self.education_group_year) except PermissionDenied as e: display_warning_messages(self.request, str(e)) cached_data = ElementCache(self.request.user).cached_data if cached_data: action_from_cache = cached_data.get('action') if action_from_cache == ElementCache.ElementCacheAction.CUT.value: kwargs['group_element_year_id'] = fetch_source_link( self.request.GET, self.request.user).id self.pattern_name = 'group_element_year_move' return super().get_redirect_url(*args, **kwargs)
def post(self, request, **kwargs): try: postponer = PostponeContent(self.root.previous_year()) postponer.postpone() success = _( "%(count_elements)s OF(s) and %(count_links)s link(s) have been postponed with success." ) % { 'count_elements': postponer.number_elements_created, 'count_links': postponer.number_links_created } display_success_messages(request, success) display_warning_messages(request, postponer.warnings) except NotPostponeError as e: display_error_messages(request, str(e)) return JsonResponse({ 'success_url': reverse( "education_group_read", args=[kwargs["root_id"], kwargs["education_group_year_id"]]) })
def post(self, request, **kwargs): try: postponer = PostponeContent(self.get_root().previous_year()) postponer.postpone() count = len(postponer.result) success = ngettext( "%(count)d education group has been postponed with success.", "%(count)d education groups have been postponed with success.", count) % { 'count': count } display_success_messages(request, success) display_warning_messages(request, postponer.warnings) except NotPostponeError as e: display_error_messages(request, str(e)) return JsonResponse({ 'success_url': reverse( "education_group_read", args=[kwargs["root_id"], kwargs["education_group_year_id"]]) })
def get_form_kwargs(self): """ For the creation, the group_element_year needs a parent and a child """ kwargs = super().get_form_kwargs() try: cached_data = extract_child_from_cache(self.education_group_year, self.request.user) if not cached_data: raise ObjectDoesNotExist kwargs.update({ 'parent': self.education_group_year, 'child_branch': cached_data.get('child_branch'), 'child_leaf': cached_data.get('child_leaf') }) except ObjectDoesNotExist: warning_msg = _("Please Select or Move an item before Attach it") display_warning_messages(self.request, warning_msg) except IntegrityError as e: warning_msg = str(e) display_warning_messages(self.request, warning_msg) return kwargs
def _save_form_and_display_messages(request, form, learning_unit_year): records = None existing_proposal = ProposalLearningUnit.objects.filter( learning_unit_year__learning_unit=learning_unit_year.learning_unit ).order_by('learning_unit_year__academic_year__year') try: records = form.save() display_warning_messages(request, getattr(form, 'warnings', [])) is_postponement = bool(int(request.POST.get('postponement', 0))) if is_postponement and existing_proposal: display_success_messages( request, _('The learning unit has been updated (the report has not been done from %(year)s because the learning ' 'unit is in proposal).') % { 'year': existing_proposal[0].learning_unit_year.academic_year }) elif is_postponement: display_success_messages( request, _('The learning unit has been updated (with report).')) else: display_success_messages( request, _('The learning unit has been updated (without report).')) except ConsistencyError as e: error_list = e.error_list error_list.insert( 0, _('The learning unit has been updated until %(year)s.') % {'year': e.last_instance_updated.academic_year}) display_error_messages(request, e.error_list) return records
def _attach(request, group_element_year, *args, **kwargs): parent = kwargs['element'] try: group_element_years.management.attach_from_cache(parent) success_msg = _("Attached to \"%(acronym)s\"") % {'acronym': parent} display_success_messages(request, success_msg) except ObjectDoesNotExist: warning_msg = _("Please Select or Move an item before Attach it") display_warning_messages(request, warning_msg) except IncompatiblesTypesException as e: warning_msg = e.errors display_warning_messages(request, warning_msg) except IntegrityError as e: warning_msg = _(str(e)) display_warning_messages(request, warning_msg)