def test_search_by_title(self): common_part = "commun" a_common_title = "Titre {}".format(common_part) a_specific_title = "Specific title {}".format(common_part) lunit_container_yr = LearningContainerYearFactory(academic_year=self.academic_year, common_title=a_common_title) luy = LearningUnitYearFactory(academic_year=self.academic_year, specific_title=a_specific_title, learning_container_year=lunit_container_yr) self.assertEqual(learning_unit_year.search(title="{} en plus".format(a_common_title)).count(), 0) self.assertEqual(learning_unit_year.search(title=a_common_title)[0], luy) self.assertEqual(learning_unit_year.search(title=common_part)[0], luy) self.assertEqual(learning_unit_year.search(title=a_specific_title)[0], luy)
def check_learning_unit_deletion(learning_unit, check_proposal=True): msg = {} for learning_unit_year in learn_unit_year_model.search(learning_unit=learning_unit).order_by('academic_year__year'): msg.update(check_learning_unit_year_deletion(learning_unit_year, check_proposal=check_proposal)) return msg
def get_with_context(**learning_unit_year_data): entity_version_prefetch = Entity.objects.all().prefetch_related( Prefetch('entityversion_set', to_attr='entity_versions')) requirement_entity_prefetch = models.Prefetch( 'learning_container_year__requirement_entity', queryset=entity_version_prefetch) additional_entity_1_prefetch = models.Prefetch( 'learning_container_year__additional_entity_1', queryset=entity_version_prefetch) additional_entity_2_prefetch = models.Prefetch( 'learning_container_year__additional_entity_2', queryset=entity_version_prefetch) learning_unit_years = learning_unit_year.search(**learning_unit_year_data) \ .select_related('academic_year', 'learning_container_year') \ .prefetch_related(requirement_entity_prefetch) \ .prefetch_related(additional_entity_1_prefetch) \ .prefetch_related(additional_entity_2_prefetch) \ .prefetch_related(get_learning_component_prefetch()) \ .order_by('academic_year__year', 'acronym') learning_unit_years = [ append_latest_entities(luy) for luy in learning_unit_years ] learning_unit_years = [ append_components(luy) for luy in learning_unit_years ] return learning_unit_years
def check_learning_unit_deletion(learning_unit, check_proposal=True): msg = {} for learning_unit_year in learn_unit_year_model.search(learning_unit=learning_unit).order_by('academic_year__year'): msg.update(check_learning_unit_year_deletion(learning_unit_year, check_proposal=check_proposal)) return msg
def instance(self): if self.learning_unit_instance: return learning_unit_year.search( academic_year_id=self.academic_year.id, learning_unit=self.learning_unit_instance, subtype=self.subtype).get() return None
def delete_all_learning_units_year(request, learning_unit_year_id): person = get_object_or_404(Person, user=request.user) learning_unit_year = mdl.learning_unit_year.get_by_id(learning_unit_year_id) if not learning_unit_deletion.can_delete_learning_unit_year(person, learning_unit_year): return HttpResponseForbidden() learning_unit = learning_unit_year.learning_unit messages_deletion = learning_unit_deletion.check_learning_unit_deletion(learning_unit) if not messages_deletion and request.method == 'POST': try: result = learning_unit_deletion.delete_learning_unit(learning_unit) messages.add_message(request, messages.SUCCESS, _("The learning unit %(acronym)s has been successfully deleted for all years.") % {'acronym': learning_unit.acronym}) for message_deletion in sorted(result): messages.add_message(request, messages.SUCCESS, message_deletion) send_mail_after_the_learning_unit_year_deletion([], learning_unit.acronym, None, result) except ProtectedError as e: messages.add_message(request, messages.ERROR, str(e)) return redirect('learning_units') else: if messages_deletion: context = {'title': _('cannot_delete_learning_unit') % {'learning_unit': learning_unit.acronym}, 'messages_deletion': sorted(messages_deletion.values())} else: context = {'title': _('msg_warning_delete_learning_unit') % learning_unit, 'learning_units_to_delete': learning_unit_year_mdl.search(learning_unit=learning_unit) .order_by('academic_year__year')} return layout.render(request, "learning_unit/deletion.html", context)
def _get_acronym_as_href(prerequisite_item, academic_yr): luy = learning_unit_year.search( academic_year_id=academic_yr.id, learning_unit=prerequisite_item.learning_unit, ).first() if luy: return "<a href='/learning_units/{}/'>{}</a>".format( luy.id, prerequisite_item.learning_unit.acronym) return ''
def delete_learning_unit(learning_unit): msg = [] first_learning_unit_year_to_delete = learn_unit_year_model.search(learning_unit=learning_unit) \ .order_by('academic_year__year').first() if first_learning_unit_year_to_delete: msg.extend(delete_from_given_learning_unit_year(first_learning_unit_year_to_delete)) learning_unit.delete() return msg
def delete_learning_unit(learning_unit): msg = [] first_learning_unit_year_to_delete = learn_unit_year_model.search(learning_unit=learning_unit) \ .order_by('academic_year__year').first() if first_learning_unit_year_to_delete: msg.extend(delete_from_given_learning_unit_year(first_learning_unit_year_to_delete)) learning_unit.delete() return msg
def check_learning_unit_deletion(learning_unit): msg = {} for learning_unit_year in learn_unit_year_model.search( learning_unit=learning_unit).order_by('academic_year__year'): msg.update(check_learning_unit_year_deletion(learning_unit_year)) for speciality in internship_speciality.search( learning_unit=learning_unit): msg.update(_check_internship_speciality(speciality)) return msg
def _get_acronym_as_href(learning_unit_year_parent, prerequisite_item, academic_yr): luy = learning_unit_year.search( academic_year_id=academic_yr.id, learning_unit=prerequisite_item.learning_unit, ).first() if luy: return "<a href='/learning_units/{}/' title=\"{}\">{}</a>".format( luy.id, _get_acronym_tooltip(luy, learning_unit_year_parent), prerequisite_item.learning_unit.acronym ) return ''
def get_list_entity_learning_unit_yr(an_entity_version, current_academic_yr): entity_ids = get_entities_ids(an_entity_version.entity.most_recent_acronym, False) entities_id_list = get_entity_container_list( [], entity_ids, entity_container_year_link_type.REQUIREMENT_ENTITY) return learning_unit_year.search(**{'learning_container_year_id': entities_id_list, 'academic_year_id': current_academic_yr, 'status': True}) \ .select_related('academic_year', 'learning_container_year', 'learning_container_year__academic_year') \ .prefetch_related(build_entity_container_prefetch()) \ .order_by('academic_year__year', 'acronym')
def get_learning_units_year(request): if request.is_ajax() and 'term' in request.GET: q = request.GET.get('term') learning_units_year = search(acronym=q)[:50] response_data = [] for learning_unit_year in learning_units_year: response_data.append({'value': learning_unit_year.acronym, 'title': learning_unit_year.complete_title, 'academic_year': str(learning_unit_year.academic_year), 'id': learning_unit_year.id }) else: response_data = [] return JsonResponse(response_data, safe=False)
def get_learning_units_year(request): if request.is_ajax() and 'term' in request.GET: q = request.GET.get('term') learning_units_year = search(acronym=q)[:50] response_data = [] for learning_unit_year in learning_units_year: response_data.append({'value': learning_unit_year.acronym, 'title': learning_unit_year.complete_title, 'academic_year': str(learning_unit_year.academic_year), 'id': learning_unit_year.id }) else: response_data = [] return JsonResponse(response_data, safe=False)
def get_with_context(**learning_unit_year_data): entity_container_prefetch = models.Prefetch( 'learning_container_year__entitycontaineryear_set', queryset=entity_container_year.search( link_type=REQUIREMENT_ENTITIES ).prefetch_related( models.Prefetch('entity__entityversion_set', to_attr='entity_versions') ), to_attr='entity_containers_year' ) learning_unit_years = learning_unit_year.search(**learning_unit_year_data) \ .select_related('academic_year', 'learning_container_year') \ .prefetch_related(entity_container_prefetch) \ .prefetch_related(get_learning_component_prefetch()) \ .order_by('academic_year__year', 'acronym') learning_unit_years = [append_latest_entities(luy) for luy in learning_unit_years] learning_unit_years = [append_components(luy) for luy in learning_unit_years] return learning_unit_years
def search(entity_folder_id=None, folder_id=None, proposal_type=None, proposal_state=None, **kwargs): learning_unit_year_qs = learning_unit_year.search(**kwargs) queryset = ProposalLearningUnit.objects.filter( learning_unit_year__in=learning_unit_year_qs) if entity_folder_id: queryset = queryset.filter(entity_id=entity_folder_id) if folder_id: queryset = queryset.filter(folder_id=folder_id) if proposal_type: queryset = queryset.filter(type=proposal_type) if proposal_state: queryset = queryset.filter(state=proposal_state) return queryset.select_related('learning_unit_year')
def get_with_context(**learning_unit_year_data): entity_container_prefetch = models.Prefetch( 'learning_container_year__entitycontaineryear_set', queryset=entity_container_year.search( link_type=ENTITY_TYPES_VOLUME).prefetch_related( models.Prefetch('entity__entityversion_set', to_attr='entity_versions')), to_attr='entity_containers_year') learning_component_prefetch = models.Prefetch( 'learningunitcomponent_set', queryset=learning_unit_component. LearningUnitComponent.objects.all().order_by( 'learning_component_year__type', 'learning_component_year__acronym').select_related( 'learning_component_year').prefetch_related( models.Prefetch( 'learning_component_year__entitycomponentyear_set', queryset=entity_component_year.EntityComponentYear. objects.all().select_related('entity_container_year'), to_attr='entity_components_year')), to_attr='learning_unit_components') learning_unit_years = learning_unit_year.search(**learning_unit_year_data) \ .select_related('academic_year', 'learning_container_year') \ .prefetch_related(entity_container_prefetch) \ .prefetch_related(learning_component_prefetch) \ .order_by('academic_year__year', 'acronym') learning_unit_years = [ append_latest_entities(luy) for luy in learning_unit_years ] learning_unit_years = [ _append_components(luy) for luy in learning_unit_years ] return learning_unit_years
def test_search_acronym_by_regex(self): regex_valid = '^LD.+1+' query_result_valid = learning_unit_year.search(acronym=regex_valid) self.assertEqual(len(query_result_valid), 1) self.assertEqual(self.learning_unit_year.acronym, query_result_valid[0].acronym)
def learning_unit_year_full(self): return learning_unit_year.search( academic_year_id=self.academic_year.id, learning_unit=self.learning_unit_full_instance.id, subtype=learning_unit_year_subtypes.FULL).get()
def get_partims_related(self): return learning_unit_year.search(learning_container_year_id=self, subtype=learning_unit_year_subtypes.PARTIM).order_by('acronym')
def get_partims_related(self): return learning_unit_year.search( learning_container_year_id=self, subtype=learning_unit_year_subtypes.PARTIM).order_by('acronym')