def proposition_dissertation_edit(request, pk): proposition = proposition_dissertation.find_by_id(pk) if proposition is None: return redirect('proposition_dissertations') adv = get_current_adviser(request) offer_propositions = offer_proposition.find_all_ordered_by_acronym() offer_propositions_group = offer_proposition_group.find_all_ordered_by_name_short() offer_propositions_error = None proposition_offers = proposition_offer.find_by_proposition_dissertation(proposition) if proposition.author == adv or proposition.creator == adv.person: if request.method == "POST": form = PropositionDissertationForm(request.POST, instance=proposition) if is_valid(request, form): proposition = edit_proposition(form, proposition_offers, request) return redirect('proposition_dissertation_detail', pk=proposition.pk) if not detect_in_request(request, 'txt_checkbox_', 'on'): offer_propositions_error = 'select_at_least_one_item' proposition_offers = None form = PropositionDissertationForm(instance=proposition) return layout.render(request, 'proposition_dissertation_edit.html', {'prop_dissert': proposition, 'form': form, 'types_choices': PropositionDissertation.TYPES_CHOICES, 'levels_choices': PropositionDissertation.LEVELS_CHOICES, 'collaborations_choices': PropositionDissertation.COLLABORATION_CHOICES, 'offer_propositions': offer_propositions, 'offer_propositions_error': offer_propositions_error, 'proposition_offers': proposition_offers, 'offer_proposition_group': offer_propositions_group }) else: return redirect('proposition_dissertation_detail', pk=proposition.pk)
def proposition_dissertation_new(request): person = mdl.person.find_by_user(request.user) offer_propositions = offer_proposition.find_all_ordered_by_acronym() offer_propositions_group = offer_proposition_group.find_all_ordered_by_name_short( ) offer_propositions_error = None if request.method == "POST": form = PropositionDissertationForm(request.POST) if is_valid(request, form): proposition = create_proposition(form, person, request) return redirect('proposition_dissertation_detail', pk=proposition.pk) else: offer_propositions_error = 'select_at_least_one_item' else: form = PropositionDissertationForm( initial={ 'author': get_current_adviser(request), 'active': True }) return layout.render( request, 'proposition_dissertation_new.html', { 'form': form, 'types_choices': PropositionDissertation.TYPES_CHOICES, 'levels_choices': PropositionDissertation.LEVELS_CHOICES, 'collaborations_choices': PropositionDissertation.COLLABORATION_CHOICES, 'offer_propositions_error': offer_propositions_error, 'offer_propositions': offer_propositions, 'offer_proposition_group': offer_propositions_group })
def proposition_dissertation_new(request): current_ac_year = academic_year.current_academic_year() perso = request.user.person offer_propositions = OfferProposition.objects.exclude( education_group=None).annotate(last_acronym=Subquery( EducationGroupYear.objects.filter( education_group__offer_proposition=OuterRef('pk'), academic_year=current_ac_year).values('acronym')[:1] )).select_related('offer_proposition_group').order_by('last_acronym') offer_propositions_group = offer_proposition_group.find_all_ordered_by_name_short( ) offer_propositions_error = None if request.method == "POST": form = PropositionDissertationForm(request.POST) if is_valid(request, form): proposition = create_proposition(form, perso, request) return redirect('proposition_dissertation_detail', pk=proposition.pk) else: offer_propositions_error = 'select_at_least_one_item' else: form = PropositionDissertationForm( initial={ 'author': get_current_adviser(request), 'active': True }) return render( request, 'proposition_dissertation_new.html', { 'form': form, 'types_choices': PropositionDissertation.TYPES_CHOICES, 'levels_choices': PropositionDissertation.LEVELS_CHOICES, 'collaborations_choices': PropositionDissertation.COLLABORATION_CHOICES, 'offer_propositions_error': offer_propositions_error, 'offer_propositions': offer_propositions, 'offer_proposition_group': offer_propositions_group })