def edit_learning_unit_pedagogy(request, learning_unit_year_id, redirect_url): if request.method == 'POST': _post_learning_unit_pedagogy_form(request) return redirect(redirect_url) context = get_common_context_learning_unit_year( learning_unit_year_id, get_object_or_404(Person, user=request.user)) label_name = request.GET.get('label') language = request.GET.get('language') text_lb = TextLabel.objects.prefetch_related( Prefetch('translatedtextlabel_set', to_attr="translated_text_labels")).get(label=label_name) form = LearningUnitPedagogyEditForm( **{ 'learning_unit_year': context['learning_unit_year'], 'language': language, 'text_label': text_lb }) form.load_initial() # Load data from database context['form'] = form user_language = mdl.person.get_user_interface_language(request.user) context['text_label_translated'] = get_text_label_translated( text_lb, user_language) context['language_translated'] = find_language_in_settings(language) context['cms_label_pedagogy_fr_only'] = CMS_LABEL_PEDAGOGY_FR_ONLY context['label_name'] = label_name return render(request, "learning_unit/pedagogy_edit.html", context)
def learning_unit_specifications_edit(request, learning_unit_year_id): if request.method == 'POST': form = LearningUnitSpecificationsEditForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect( reverse("learning_unit_specifications", kwargs={'learning_unit_year_id': learning_unit_year_id})) context = get_common_context_learning_unit_year( learning_unit_year_id, get_object_or_404(Person, user=request.user)) label_name = request.GET.get('label') text_lb = text_label.get_by_name(label_name) language = request.GET.get('language') form = LearningUnitSpecificationsEditForm( **{ 'learning_unit_year': context['learning_unit_year'], 'language': language, 'text_label': text_lb }) form.load_initial() # Load data from database context['form'] = form user_language = mdl.person.get_user_interface_language(request.user) context['text_label_translated'] = get_text_label_translated( text_lb, user_language) context['language_translated'] = find_language_in_settings(language) return render(request, "learning_unit/specifications_edit.html", context)
def learning_class_year_edit(request, learning_unit_year_id): context = get_common_context_learning_unit_year( learning_unit_year_id, get_object_or_404(Person, user=request.user)) context.update({ 'learning_class_year': mdl.learning_class_year.find_by_id( request.GET.get('learning_class_year_id')), 'learning_component_year': mdl.learning_component_year.find_by_id( request.GET.get('learning_component_year_id')) }) if request.method == 'POST': form = LearningClassEditForm( request.POST, instance=context['learning_class_year'], learning_unit_year=context['learning_unit_year'], learning_component_year=context['learning_component_year']) if form.is_valid(): form.save() return HttpResponseRedirect( reverse("learning_unit_components", kwargs={'learning_unit_year_id': learning_unit_year_id})) form = LearningClassEditForm( instance=context['learning_class_year'], learning_unit_year=context['learning_unit_year'], learning_component_year=context['learning_component_year']) form.load_initial() # Load data from database context['form'] = form return layout.render(request, "learning_unit/class_edit.html", context)
def learning_unit_volumes_management(request, learning_unit_year_id, form_type): person = get_object_or_404(Person, user=request.user) context = get_common_context_learning_unit_year(learning_unit_year_id, person) context['learning_units'] = _get_learning_units_for_context(luy=context['learning_unit_year'], with_family=form_type == "full") volume_edition_formset_container = VolumeEditionFormsetContainer(request, context['learning_units'], person) if volume_edition_formset_container.is_valid() and not request.is_ajax(): _save_form_and_display_messages(request, volume_edition_formset_container) if form_type == "full": return HttpResponseRedirect(reverse(learning_unit_components, args=[learning_unit_year_id])) else: return HttpResponseRedirect(reverse("learning_unit", args=[learning_unit_year_id])) context['formsets'] = volume_edition_formset_container.formsets context['tab_active'] = 'components' context['entity_types_volume'] = REQUIREMENT_ENTITIES context['luy_url'] = 'learning_unit_components' if form_type == "full" else 'learning_unit' context['experimental_phase'] = True if request.is_ajax(): return JsonResponse({'errors': volume_edition_formset_container.errors}) return render(request, "learning_unit/volumes_management.html", context)
def learning_unit_formations(request, learning_unit_year_id): context = get_common_context_learning_unit_year(learning_unit_year_id, get_object_or_404(Person, user=request.user)) learn_unit_year = context["learning_unit_year"] group_elements_years = learn_unit_year.child_leaf.select_related( "parent", "child_leaf", "parent__education_group_type" ).order_by('parent__partial_acronym') education_groups_years = [group_element_year.parent for group_element_year in group_elements_years] formations_by_educ_group_year = mdl.group_element_year.find_learning_unit_roots( education_groups_years, return_result_params={ 'parents_as_instances': True, 'with_parents_of_parents': True }, luy=learn_unit_year ) context['formations_by_educ_group_year'] = formations_by_educ_group_year context['group_elements_years'] = group_elements_years context['root_formations'] = education_group_year.find_with_enrollments_count(learn_unit_year) context['total_formation_enrollments'] = 0 context['total_learning_unit_enrollments'] = 0 for root_formation in context['root_formations']: context['total_formation_enrollments'] += root_formation.count_formation_enrollments context['total_learning_unit_enrollments'] += root_formation.count_learning_unit_enrollments context['tab_active'] = "learning_unit_formations" # Corresponds to url_name return render(request, "learning_unit/formations.html", context)
def learning_unit_specifications(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) learning_unit_year = context['learning_unit_year'] user_language = mdl.person.get_user_interface_language(request.user) context['cms_labels_translated'] = get_cms_label_data( CMS_LABEL_SPECIFICATIONS, user_language) fr_language = find_language_in_settings(settings.LANGUAGE_CODE_FR) en_language = find_language_in_settings(settings.LANGUAGE_CODE_EN) context.update({ 'form_french': LearningUnitSpecificationsForm(learning_unit_year, fr_language), 'form_english': LearningUnitSpecificationsForm(learning_unit_year, en_language) }) context.update(get_achievements_group_by_language(learning_unit_year)) context.update({ 'LANGUAGE_CODE_FR': settings.LANGUAGE_CODE_FR, 'LANGUAGE_CODE_EN': settings.LANGUAGE_CODE_EN }) context[ 'can_update_learning_achievement'] = can_update_learning_achievement( learning_unit_year, person) context['experimental_phase'] = True return layout.render(request, "learning_unit/specifications.html", context)
def read_learning_unit_pedagogy(request, learning_unit_year_id, context, template): person = get_object_or_404(Person, user=request.user) context.update( get_common_context_learning_unit_year(learning_unit_year_id, person)) learning_unit_year = context['learning_unit_year'] perm_to_edit = is_eligible_to_update_learning_unit_pedagogy( learning_unit_year, person) user_language = mdl.person.get_user_interface_language(request.user) context['cms_labels_translated'] = get_cms_label_data( CMS_LABEL_PEDAGOGY, user_language) context['form_french'] = LearningUnitPedagogyForm( learning_unit_year=learning_unit_year, language_code=settings.LANGUAGE_CODE_FR) context['form_english'] = LearningUnitPedagogyForm( learning_unit_year=learning_unit_year, language_code=settings.LANGUAGE_CODE_EN) context[ 'teaching_materials'] = teaching_material.find_by_learning_unit_year( learning_unit_year) context['can_edit_information'] = perm_to_edit context[ 'can_edit_summary_locked_field'] = perms.can_edit_summary_locked_field( learning_unit_year, person) context[ 'summary_responsibles'] = find_all_summary_responsibles_by_learning_unit_year( learning_unit_year) context['other_teachers'] = get_no_summary_responsible_teachers( learning_unit_year, context['summary_responsibles']) context['cms_label_pedagogy_fr_only'] = CMS_LABEL_PEDAGOGY_FR_ONLY return render(request, template, context)
def learning_unit_specifications_edit(request, learning_unit_year_id): if request.method == 'POST': form = LearningUnitSpecificationsEditForm(request.POST) if form.is_valid(): field_label, last_academic_year = form.save() display_success_messages( request, build_success_message(last_academic_year, learning_unit_year_id, form.postponement) ) return HttpResponse() else: context = get_common_context_learning_unit_year(learning_unit_year_id, get_object_or_404(Person, user=request.user)) label_name = request.GET.get('label') text_lb = TextLabel.objects.prefetch_related( Prefetch('translatedtextlabel_set', to_attr="translated_text_labels") ).get(label=label_name) form = LearningUnitSpecificationsEditForm(**{ 'learning_unit_year': context['learning_unit_year'], 'text_label': text_lb }) form.load_initial() # Load data from database context['form'] = form context['text_label_translated'] = get_text_label_translated(text_lb, get_language()) return render(request, "learning_unit/specifications_edit.html", context)
def learning_unit_attributions(request, learning_unit_year_id): context = get_common_context_learning_unit_year( learning_unit_year_id, get_object_or_404(Person, user=request.user)) context['attribution_charge_news'] = \ attribution_charge_new.find_attribution_charge_new_by_learning_unit_year( learning_unit_year=learning_unit_year_id) context['experimental_phase'] = True return layout.render(request, "learning_unit/attributions.html", context)
def learning_unit_specifications(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) learning_unit_year = context['learning_unit_year'] context.update(get_specifications_context(learning_unit_year, request)) context.update(get_achievements_group_by_language(learning_unit_year)) context.update(get_languages_settings()) context['can_update_learning_achievement'] = can_update_learning_achievement(learning_unit_year, person) return render(request, "learning_unit/specifications.html", context)
def learning_unit_components(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) learning_unit_year = context['learning_unit_year'] context['warnings'] = learning_unit_year.warnings data_components = get_same_container_year_components(context['learning_unit_year']) context['components'] = data_components.get('components') context['REQUIREMENT_ENTITY'] = data_components.get('REQUIREMENT_ENTITY') context['ADDITIONAL_REQUIREMENT_ENTITY_1'] = data_components.get('ADDITIONAL_REQUIREMENT_ENTITY_1') context['ADDITIONAL_REQUIREMENT_ENTITY_2'] = data_components.get('ADDITIONAL_REQUIREMENT_ENTITY_2') context['tab_active'] = 'components' context['can_manage_volume'] = business_perms.is_eligible_for_modification(context["learning_unit_year"], person) return render(request, "learning_unit/components.html", context)
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 learning_unit_specifications(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) learning_unit_year = context['learning_unit_year'] context.update(get_specifications_context(learning_unit_year, request)) context.update(get_achievements_group_by_language(learning_unit_year)) context.update(get_languages_settings()) context["achievements"] = list(itertools.zip_longest( context.get("achievements_FR", []), context.get("achievements_EN", []) )) context['can_update_learning_achievement'] = can_update_learning_achievement(learning_unit_year, person) context['tab_active'] = 'learning_unit_specifications' # Corresponds to url_name return render(request, "learning_unit/specifications.html", 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 learning_unit_formations(request, learning_unit_year_id): context = get_common_context_learning_unit_year(learning_unit_year_id, get_object_or_404(Person, user=request.user)) learn_unit_year = context["learning_unit_year"] group_elements_years = learn_unit_year.child_leaf.select_related( "parent", "child_leaf", "parent__education_group_type" ).order_by('parent__partial_acronym') education_groups_years = [group_element_year.parent for group_element_year in group_elements_years] formations_by_educ_group_year = mdl.group_element_year.find_learning_unit_formations( education_groups_years, parents_as_instances=True, with_parents_of_parents=True ) context['formations_by_educ_group_year'] = formations_by_educ_group_year context['group_elements_years'] = group_elements_years context['root_formations'] = education_group_year.find_with_enrollments_count(learn_unit_year) return render(request, "learning_unit/formations.html", context)
def read_learning_unit_pedagogy(request, learning_unit_year_id, context, template): person = get_object_or_404(Person, user=request.user) context.update( get_common_context_learning_unit_year(learning_unit_year_id, person)) learning_unit_year = context['learning_unit_year'] perm_to_edit = is_eligible_to_update_learning_unit_pedagogy( learning_unit_year, person) user_language = mdl.person.get_user_interface_language(request.user) translated_labels_with_text = TranslatedTextLabel.objects.filter( language=user_language, text_label__label__in=CMS_LABEL_PEDAGOGY).prefetch_related( Prefetch("text_label__translatedtext_set", queryset=TranslatedText.objects.filter( language=settings.LANGUAGE_CODE_FR, entity=LEARNING_UNIT_YEAR, reference=learning_unit_year_id), to_attr="text_fr"), Prefetch( "text_label__translatedtext_set", queryset=TranslatedText.objects.filter( language=settings.LANGUAGE_CODE_EN, entity=LEARNING_UNIT_YEAR, reference=learning_unit_year_id), to_attr="text_en")).annotate( label_ordering=Case(*[ When(text_label__label=label, then=Value(i)) for i, label in enumerate(CMS_LABEL_PEDAGOGY) ], default=Value(len(CMS_LABEL_PEDAGOGY)), output_field=IntegerField()) ).select_related("text_label").order_by("label_ordering") teaching_materials = TeachingMaterial.objects.filter( learning_unit_year=learning_unit_year).order_by('order') attributions = Attribution.objects.filter( learning_unit_year=learning_unit_year).select_related( "tutor__person").order_by("tutor__person") translated_text_ids = itertools.chain.from_iterable( (*translated_label.text_label.text_fr, *translated_label.text_label.text_en) for translated_label in translated_labels_with_text) reversion = Version.objects.filter( Q(content_type=ContentType.objects.get_for_model(TranslatedText), object_id__in=map(lambda obj: obj.id, translated_text_ids)) | Q(content_type=ContentType.objects.get_for_model(TeachingMaterial), object_id__in=map(lambda obj: obj.id, teaching_materials)) ).select_related("revision", "revision__user").prefetch_related( Prefetch( "revision__user__person", to_attr="author")).order_by("-revision__date_created").first() context['cms_labels_translated'] = translated_labels_with_text context['teaching_materials'] = teaching_materials context['can_edit_information'] = perm_to_edit context[ 'can_edit_summary_locked_field'] = perms.can_edit_summary_locked_field( learning_unit_year, person) context['cms_label_pedagogy_fr_only'] = CMS_LABEL_PEDAGOGY_FR_ONLY context['attributions'] = attributions context["version"] = reversion return render(request, template, context)