def _get_special_old_value(key, initial_value): if key in ( entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_2): an_entity = find_by_id(initial_value) if an_entity.organization.type != organization_type.MAIN: return an_entity.most_recent_entity_version.title if an_entity else None else: return an_entity.most_recent_acronym if an_entity else None elif '_ENTITY' in key: an_entity = find_by_id(initial_value) return an_entity.most_recent_acronym if an_entity else None return None
def _get_data_from_initial_data(initial_data): learning_unit_yr = get_by_id(initial_data.get('learning_unit_year')['id']) requirement_entity = find_by_id(initial_data.get('entities')['REQUIREMENT_ENTITY']) allocation_entity = find_by_id(initial_data.get('entities')['ALLOCATION_ENTITY']) add1_requirement_entity = find_by_id(initial_data.get('entities')['ADDITIONAL_REQUIREMENT_ENTITY_1']) add2_requirement_entity = find_by_id(initial_data.get('entities')['ADDITIONAL_REQUIREMENT_ENTITY_2']) campus = find_campus_by_id(initial_data.get('learning_unit_year')['campus']) organization = get_organization_from_learning_unit_year(learning_unit_yr) language = find_language_by_id(initial_data.get('learning_unit_year')['language']) lu_initial = initial_data.get('learning_unit', None) luy_initial = initial_data.get('learning_unit_year', None) lcy_initial = initial_data.get('learning_container_year', None) data = [ str(_('Initial data')), luy_initial['acronym'], learning_unit_yr.academic_year.name, dict(LearningContainerYearType.choices())[lcy_initial['container_type']] if lcy_initial['container_type'] else '-', translate_status(luy_initial['status']), learning_unit_yr.get_subtype_display(), get_translation(luy_initial['internship_subtype']), volume_format(luy_initial['credits']), language.name if language else EMPTY_VALUE, dict(PERIODICITY_TYPES)[luy_initial['periodicity']] if luy_initial['periodicity'] else BLANK_VALUE, get_translation(luy_initial['quadrimester']), get_translation(luy_initial['session']), get_representing_string(lcy_initial['common_title']), get_representing_string(luy_initial['specific_title']), get_representing_string(lcy_initial['common_title_english']), get_representing_string(luy_initial['specific_title_english']), requirement_entity.most_recent_acronym if requirement_entity else BLANK_VALUE, allocation_entity.most_recent_acronym if allocation_entity else BLANK_VALUE, add1_requirement_entity.most_recent_acronym if add1_requirement_entity else BLANK_VALUE, add2_requirement_entity.most_recent_acronym if add2_requirement_entity else BLANK_VALUE, _('Yes') if luy_initial['professional_integration'] else _('No'), organization.name if organization else BLANK_VALUE, campus if campus else BLANK_VALUE, get_representing_string(lu_initial['faculty_remark']), get_representing_string(lu_initial['other_remark']), _('Yes') if lcy_initial.get('team') else _('No'), _('Yes') if lcy_initial.get('is_vacant') else _('No'), dict(vacant_declaration_type.DECLARATION_TYPE)[lcy_initial.get('type_declaration_vacant')] if lcy_initial.get( 'type_declaration_vacant') else BLANK_VALUE, dict(attribution_procedure.ATTRIBUTION_PROCEDURES)[luy_initial.get('attribution_procedure')] if luy_initial.get( 'attribution_procedure') else BLANK_VALUE, ] return _get_data_from_components_initial_data(data, initial_data)
def get_all_entities_comparison_context(initial_data, learning_unit_year): entities_fields = [] for link_type in ENTITY_TYPE_LIST: link = EntityContainerYearLinkTypes[link_type].value new_entity = get_entity_by_type( learning_unit_year, link_type).most_recent_acronym if get_entity_by_type( learning_unit_year, link_type) else None initial_entity = entity.find_by_id( initial_data['entities'] [link_type]).most_recent_acronym if entity.find_by_id( initial_data['entities'][link_type]) else None if initial_entity != new_entity: entities_fields.append([link, initial_entity, new_entity]) return entities_fields
def get_entities_context(initial_data, learning_unit_year): entities_fields = {} for link_type in ENTITY_TYPE_LIST: link = EntityContainerYearLinkTypes[link_type].value if initial_data: entity_data = entity.find_by_id( initial_data['entities'] [link_type]).most_recent_acronym if entity.find_by_id( initial_data['entities'][link_type]) else None else: entity_data = get_entity_by_type( learning_unit_year, link_type).most_recent_acronym if get_entity_by_type( learning_unit_year, link_type) else None entities_fields[link] = entity_data return entities_fields
def add_reviewer_for_structure(request): current_entity = entity.find_by_id(request.POST.get("entity")) year = academic_year.current_academic_year().year if not reviewer.can_delegate_to_entity(reviewer.find_by_person(request.user.person), current_entity): return redirect('assistants_home') form = ReviewerDelegationForm(data=request.POST) if form.is_valid() and request.POST.get('person_id'): new_reviewer = form.save(commit=False) this_person = person.find_by_id(request.POST.get('person_id')) if reviewer.find_by_person(this_person): msg = _("person_already_reviewer_msg") form.add_error(None, msg) return render(request, "reviewer_add_reviewer.html", { 'form': form, 'year': year, 'entity': current_entity, 'reviewer': reviewer.find_by_person(request.user.person) }) new_reviewer.person = this_person new_reviewer.save() html_template_ref = 'assistant_reviewers_startup_html' txt_template_ref = 'assistant_reviewers_startup_txt' send_message(person=this_person, html_template_ref=html_template_ref, txt_template_ref=txt_template_ref) return redirect('reviewer_delegation') else: this_reviewer = reviewer.find_by_person(person=request.user.person) role = this_reviewer.role + '_ASSISTANT' form = ReviewerDelegationForm(initial={'entity': current_entity, 'year': year, 'role': role}) return render(request, "reviewer_add_reviewer.html", { 'form': form, 'year': year, 'entity': current_entity, 'reviewer': reviewer.find_by_person(request.user.person) })
def add_reviewer_for_structure(request): current_entity = entity.find_by_id(request.POST.get("entity")) year = academic_year.starting_academic_year().year current_reviewer = reviewer_eligible_to_delegate( reviewer.find_by_person(request.user.person), current_entity ) if not current_reviewer: return redirect('assistants_home') form = ReviewerDelegationForm(data=request.POST) if form.is_valid() and request.POST.get('person_id'): new_reviewer = form.save(commit=False) new_reviewer.person = person.find_by_id(request.POST.get('person_id')) new_reviewer.save() send_message( person=new_reviewer.person, html_template_ref='assistant_reviewers_startup_html', txt_template_ref='assistant_reviewers_startup_txt' ) return redirect('reviewer_delegation') role = current_reviewer.role + '_ASSISTANT' form = ReviewerDelegationForm(initial={'entity': current_entity, 'year': year, 'role': role}) return render(request, "reviewer_add_reviewer.html", { 'form': form, 'year': year, 'entity': current_entity, 'reviewer': current_reviewer })
def _get_old_value_of_foreign_key(key, initial_value): if key == 'campus': return _get_name_attribute(mdl_base.campus.find_by_id(initial_value)) if key == 'language': return _get_name_attribute(language.find_by_id(initial_value)) if '_ENTITY' in key: an_entity = find_by_id(initial_value) return an_entity.most_recent_acronym if an_entity else None return None
def _get_entity_previous_value(entity_id, entity_type): if entity_id: old_value = entity.find_by_id(entity_id) if old_value: return {entity_type: old_value.most_recent_acronym} return {entity_type: _('entity_not_found')}
def _get_data_from_initial_data(initial_data): learning_unit_yr = get_by_id(initial_data.get('learning_unit_year')['id']) requirement_entity = find_by_id( initial_data.get('entities')['REQUIREMENT_ENTITY']) allocation_entity = find_by_id( initial_data.get('entities')['ALLOCATION_ENTITY']) add1_requirement_entity = find_by_id( initial_data.get('entities')['ADDITIONAL_REQUIREMENT_ENTITY_1']) add2_requirement_entity = find_by_id( initial_data.get('entities')['ADDITIONAL_REQUIREMENT_ENTITY_2']) campus = find_campus_by_id( initial_data.get('learning_unit_year')['campus']) organization = get_organization_from_learning_unit_year(learning_unit_yr) language = find_language_by_id( initial_data.get('learning_unit_year')['language']) lu_initial = initial_data.get('learning_unit', None) luy_initial = initial_data.get('learning_unit_year', None) lcy_initial = initial_data.get('learning_container_year', None) data = [ str(_('Initial data')), luy_initial['acronym'], learning_unit_yr.academic_year.name, dict( LearningContainerYearType.choices())[lcy_initial['container_type']] if lcy_initial['container_type'] else '-', translate_status(luy_initial['status']), learning_unit_yr.get_subtype_display(), get_translation(luy_initial['internship_subtype']), volume_format(luy_initial['credits']), language.name if language else EMPTY_VALUE, dict(PERIODICITY_TYPES)[luy_initial['periodicity']] if luy_initial['periodicity'] else BLANK_VALUE, get_translation(luy_initial['quadrimester']), get_translation(luy_initial['session']), get_representing_string(lcy_initial['common_title']), get_representing_string(luy_initial['specific_title']), get_representing_string(lcy_initial['common_title_english']), get_representing_string(luy_initial['specific_title_english']), requirement_entity.most_recent_acronym if requirement_entity else BLANK_VALUE, allocation_entity.most_recent_acronym if allocation_entity else BLANK_VALUE, add1_requirement_entity.most_recent_acronym if add1_requirement_entity else BLANK_VALUE, add2_requirement_entity.most_recent_acronym if add2_requirement_entity else BLANK_VALUE, _('Yes') if luy_initial['professional_integration'] else _('No'), organization.name if organization else BLANK_VALUE, campus if campus else BLANK_VALUE, get_representing_string(lu_initial['faculty_remark']), get_representing_string(lu_initial['other_remark']), _('Yes') if lcy_initial.get('team') else _('No'), _('Yes') if lcy_initial.get('is_vacant') else _('No'), dict(vacant_declaration_type.DECLARATION_TYPE)[lcy_initial.get( 'type_declaration_vacant')] if lcy_initial.get('type_declaration_vacant') else BLANK_VALUE, dict(attribution_procedure.ATTRIBUTION_PROCEDURES)[luy_initial.get( 'attribution_procedure')] if luy_initial.get('attribution_procedure') else BLANK_VALUE, ] return _get_data_from_components_initial_data(data, initial_data)
def _get_data_from_initial_data(initial_data, proposal_comparison=False): luy_initial = initial_data.get('learning_unit_year', {}) lcy_initial = initial_data.get('learning_container_year', {}) lu_initial = initial_data.get('learning_unit', {}) if luy_initial.get('id'): learning_unit_yr = get_by_id(luy_initial.get('id')) else: learning_unit_yr = None requirement_entity = find_by_id(lcy_initial.get('requirement_entity')) allocation_entity = find_by_id(lcy_initial.get('allocation_entity')) add1_requirement_entity = find_by_id(lcy_initial.get('additional_entity_1')) add2_requirement_entity = find_by_id(lcy_initial.get('additional_entity_2')) campus = find_campus_by_id(luy_initial.get('campus')) organization = None if learning_unit_yr: organization = get_organization_from_learning_unit_year(learning_unit_yr) language = find_language_by_id(luy_initial.get('language')) if proposal_comparison: academic_year = _format_academic_year(learning_unit_yr.academic_year.name, find_academic_year_by_id(lu_initial.get('end_year')) if lu_initial.get('end_year') else None) else: academic_year = learning_unit_yr.academic_year.name data = [ str(_('Initial data')), luy_initial.get('acronym', ''), academic_year, dict(LearningContainerYearType.choices())[lcy_initial.get('container_type')] if lcy_initial.get('container_type') else BLANK_VALUE, translate_status(luy_initial.get('status')), learning_unit_yr.get_subtype_display() if learning_unit_yr and learning_unit_yr.get_subtype_display() else BLANK_VALUE, get_translation(luy_initial.get('internship_subtype')), volume_format(Decimal(luy_initial['credits'])) if luy_initial.get('credits') else BLANK_VALUE, language.name if language else BLANK_VALUE, dict(PERIODICITY_TYPES)[luy_initial['periodicity']] if luy_initial.get('periodicity') else BLANK_VALUE, get_translation(luy_initial.get('quadrimester')), get_translation(luy_initial.get('session')), get_representing_string(lcy_initial.get('common_title')), get_representing_string(luy_initial.get('specific_title')), get_representing_string(lcy_initial.get('common_title_english')), get_representing_string(luy_initial.get('specific_title_english')), requirement_entity.most_recent_acronym if requirement_entity else BLANK_VALUE, allocation_entity.most_recent_acronym if allocation_entity else BLANK_VALUE, add1_requirement_entity.most_recent_acronym if add1_requirement_entity else BLANK_VALUE, add2_requirement_entity.most_recent_acronym if add2_requirement_entity else BLANK_VALUE, _('Yes') if luy_initial.get('professional_integration') else _('No'), organization.name if organization else BLANK_VALUE, campus if campus else BLANK_VALUE, get_representing_string(lu_initial.get('faculty_remark')), get_representing_string(lu_initial.get('other_remark')), _('Yes') if lcy_initial.get('team') else _('No'), _('Yes') if lcy_initial.get('is_vacant') else _('No'), dict(vacant_declaration_type.DECLARATION_TYPE)[lcy_initial.get('type_declaration_vacant')] if lcy_initial.get( 'type_declaration_vacant') else BLANK_VALUE, dict(attribution_procedure.ATTRIBUTION_PROCEDURES)[luy_initial.get('attribution_procedure')] if luy_initial.get( 'attribution_procedure') else BLANK_VALUE, ] return _get_data_from_components_initial_data(data, initial_data)