def delete_all_learning_units_year(request, learning_unit_year_id): learning_unit_year = get_object_or_404(LearningUnitYear, pk=learning_unit_year_id) learning_unit = learning_unit_year.learning_unit messages_deletion = deletion.check_learning_unit_deletion(learning_unit) if messages_deletion: display_error_messages(request, sorted(messages_deletion.values())) return redirect('learning_unit', learning_unit_year_id=learning_unit_year.id) try: with transaction.atomic(): result = deletion.delete_learning_unit(learning_unit) display_success_messages( request, _("The learning unit %(acronym)s has been successfully deleted for all years." ) % {'acronym': learning_unit.acronym}) display_success_messages(request, sorted(result)) send_mail_after_the_learning_unit_year_deletion([], learning_unit.acronym, None, result) except (ProtectedError, IntegrityError) as e: display_error_messages(request, str(e)) return redirect('learning_units')
def _consolidate_creation_proposal_of_state_refused(proposal): messages_by_level = deletion.check_learning_unit_deletion( proposal.learning_unit_year.learning_unit, check_proposal=False) if messages_by_level: return {ERROR: list(messages_by_level.values())} return { SUCCESS: deletion.delete_learning_unit( proposal.learning_unit_year.learning_unit) }