コード例 #1
0
ファイル: delete.py プロジェクト: makinacorpus/osis
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')
コード例 #2
0
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)
コード例 #3
0
 def test_send_mail_after_the_learning_unit_year_deletion(
         self, mock_send_messages):
     send_mail.send_mail_after_the_learning_unit_year_deletion(
         self.persons, self.learning_unit_year.acronym, self.academic_year,
         self.msg_list)
     args = mock_send_messages.call_args[0][0]
     self.assertEqual(self.learning_unit_year.acronym,
                      args.get('subject_data').get('learning_unit_acronym'))
     self.assertEqual(len(args.get('receivers')), 2)
     self.assertIsNone(args.get('attachment'))
コード例 #4
0
ファイル: test_send_mail.py プロジェクト: kelvinninja1/osis
 def test_send_mail_after_the_learning_unit_year_deletion(self, mock_class):
     mock_class.send.return_value = None
     self.assertIsInstance(mock_class, EmailMultiAlternatives)
     send_mail.send_mail_after_the_learning_unit_year_deletion(
         self.persons, self.learning_unit_year.acronym, self.academic_year,
         self.msg_list)
     call_args = mock_class.call_args
     subject = call_args[0][0]
     recipients = call_args[0][3]
     attachments = call_args[1]
     self.assertIn(self.learning_unit_year.acronym, subject)
     self.assertEqual(len(recipients), 2)
     self.assertIsNone(attachments['attachments'])
コード例 #5
0
def delete_from_given_learning_unit_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 can_delete_learning_unit_year(learning_unit_year, person):
        return HttpResponseForbidden()

    messages_deletion = learning_unit_deletion.check_learning_unit_year_deletion(
        learning_unit_year)
    if not messages_deletion and request.method == 'POST':
        try:
            result = learning_unit_deletion.delete_from_given_learning_unit_year(
                learning_unit_year)
            success_msg = _("You asked the deletion of the learning unit %(acronym)s from the year %(year)s") \
                          % {'acronym': learning_unit_year.acronym,
                             'year': learning_unit_year.academic_year}
            messages.add_message(request, messages.SUCCESS, success_msg)

            for msg in sorted(result):
                messages.add_message(request, messages.SUCCESS, msg)

            send_mail_after_the_learning_unit_year_deletion(
                [], learning_unit_year.acronym,
                learning_unit_year.academic_year, 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_year") % {
                    'learning_unit': learning_unit_year.acronym,
                    'year': learning_unit_year.academic_year
                },
                'messages_deletion': sorted(messages_deletion.values())
            }
        else:
            learning_units_to_delete = learning_unit_year.find_gte_learning_units_year(
            )

            context = {
                'title':
                _("msg_warning_delete_learning_unit") % learning_unit_year,
                'learning_units_to_delete': learning_units_to_delete
            }

        return layout.render(request, "learning_unit/deletion.html", context)