コード例 #1
0
ファイル: members.py プロジェクト: lemoer/byro
    def end_membership(self, ms, form, active_buttons):
        if form.instance.end:
            if not getattr(form.instance, "member", False):
                form.instance.member = self.get_object()

            form.save()
            form.instance.log(self, ".ended")
            messages.success(
                self.request,
                _("The membership has been terminated. Please check the outbox for the notifications."
                  ),
            )

            form.instance.member.update_liabilites()

            responses = leave_member.send_robust(sender=form.instance)
            for module, response in responses:
                if isinstance(response, Exception):
                    messages.warning(
                        self.request,
                        _("Some post processing steps could not be completed: "
                          ) + str(response),
                    )

            config = Configuration.get_solo()
            if config.leave_member_template:
                context = {
                    "name": config.name,
                    "contact": config.mail_from,
                    "number": form.instance.member.number,
                    "member_name": form.instance.member.name,
                    "end": form.instance.end,
                }
                responses = [
                    r[1] for r in leave_member_mail_information.send_robust(
                        sender=form.instance) if r
                ]
                context["additional_information"] = "\n".join(
                    responses).strip()
                config.leave_member_template.to_mail(
                    email=form.instance.member.email, context=context)
            if config.leave_office_template:
                context = {
                    "member_name": form.instance.member.name,
                    "end": form.instance.end,
                }
                responses = [
                    r[1]
                    for r in leave_member_office_mail_information.send_robust(
                        sender=form.instance) if r
                ]
                context["additional_information"] = "\n".join(
                    responses).strip()
                config.leave_office_template.to_mail(
                    email=config.backoffice_mail, context=context)
コード例 #2
0
    def post(self, *args, **kwargs):
        for form in self.get_forms():
            if form.is_valid() and form.has_changed() and form.instance.end:
                if not getattr(form.instance, 'member', False):
                    form.instance.member = self.get_object()

                form.save()
                form.instance.log(self, '.ended')
                messages.success(self.request, _('The membership has been terminated. Please check the outbox for the notifications.'))

                form.instance.member.update_liabilites()

                responses = leave_member.send_robust(sender=form.instance)
                for module, response in responses:
                    if isinstance(response, Exception):
                        messages.warning(self.request, _('Some post processing steps could not be completed: ') + str(response))

                config = Configuration.get_solo()
                if config.leave_member_template:
                    context = {
                        'name': config.name,
                        'contact': config.mail_from,
                        'number': form.instance.member.number,
                        'member_name': form.instance.member.name,
                        'end': form.instance.end,
                    }
                    responses = [r[1] for r in leave_member_mail_information.send_robust(sender=form.instance) if r]
                    context['additional_information'] = '\n'.join(responses).strip()
                    config.leave_member_template.to_mail(email=form.instance.member.email, context=context)
                if config.leave_office_template:
                    context = {
                        'member_name': form.instance.member.name,
                        'end': form.instance.end,
                    }
                    responses = [r[1] for r in leave_member_office_mail_information.send_robust(sender=form.instance) if r]
                    context['additional_information'] = '\n'.join(responses).strip()
                    config.leave_office_template.to_mail(email=config.backoffice_mail, context=context)
        return redirect(reverse('office:members.leave', kwargs=self.kwargs))