コード例 #1
0
ファイル: models.py プロジェクト: jrlv16/mrs
 def password_reset(self):
     created = not self.password
     password = secrets.token_urlsafe(16)
     self.set_password(password)
     self.save()
     password_email_template = template.loader.get_template(
         'mrsuser/user_password_email.txt',
     )
     Caller(
         callback='djcall.django.email_send',
         kwargs=dict(
             subject=(
                 '[MRS] Votre mot de passe'
                 if created else
                 '[MRS] Votre nouveau mot de passe'
             ),
             body=password_email_template.render(dict(
                 created=created,
                 user=self,
                 password=password,
                 BASE_URL=settings.BASE_URL,
             )),
             to=[self.email],
             reply_to=[settings.TEAM_EMAIL],
         )
     ).spool('mail')
コード例 #2
0
    def post(self, request, *args, **kwargs):
        if self.object.status != self.object.STATUS_NEW:
            return http.HttpResponseBadRequest()

        self.object.status = self.object.STATUS_CANCELED
        self.object.status_datetime = datetime.now()
        self.object.save()

        self.object.logentries.create(
            action=MRSRequest.STATUS_CANCELED,
            comment='Annulation',
        )

        body = template.loader.get_template(
            'mrsrequest/cancelation_email.txt'
        ).render(dict(object=self.object, base_url=settings.BASE_URL)).strip()

        Caller(
            callback='djcall.django.email_send',
            kwargs=dict(
                subject=f'MRS: Annulation demande {self.object.display_id}',
                body=body.strip(),
                to=[self.object.insured.email],
                reply_to=[self.object.caisse.liquidation_email],
            )
        ).spool('mail')

        return generic.TemplateView.get(self, request, *args, **kwargs)
コード例 #3
0
def test_call_execute_result():
    call = Caller(
        callback='djcall.test_models.mockito',
        kwargs=dict(id=1),
    ).call()
    assert call.result == 1
    assert call.status == call.STATUS_SUCCESS
    assert call.caller.status == call.STATUS_SUCCESS
コード例 #4
0
ファイル: views.py プロジェクト: sanbox98/mrs
 def form_valid(self, form):
     Caller(
         callback='djcall.django.email_send',
         kwargs=form.get_email_kwargs(),
     ).spool('mail')
     form.save()
     self.success = True
     return generic.TemplateView.get(self, self.request)
コード例 #5
0
ファイル: crudlfap.py プロジェクト: csu-xiao-an/mrs
 def mail_insured(self, mrsrequest=None):
     mrsrequest = mrsrequest or self.object
     Caller(callback='djcall.django.email_send',
            kwargs=dict(
                subject=self.mail_render('title', mrsrequest),
                body=self.mail_render('body', mrsrequest),
                to=[(mrsrequest or self.object).insured.email],
                reply_to=[settings.TEAM_EMAIL],
            )).spool('mail')
コード例 #6
0
ファイル: crudlfap.py プロジェクト: sanbox98/mrs
 def form_valid(self):
     Caller(callback='djcall.django.email_send',
            kwargs=dict(
                subject=self.form.cleaned_data['subject'],
                body=self.form.cleaned_data['body'],
                to=[self.object.insured.email],
                reply_to=[self.object.caisse.liquidation_email],
            )).spool('mail')
     self.form.cleaned_data['template'].counter += 1
     self.form.cleaned_data['template'].save()
     return super().form_valid()
コード例 #7
0
    def save_mrsrequest(self):
        person = self.forms['person'].get_or_create()
        mrsrequest = self.forms['mrsrequest'].instance

        self.forms['transport_formset'].set_confirms(
            person.nir, person.birth_date
        )
        conflicts_resolved = self.conflicts_initial - self.conflicts_count
        mrsrequest.conflicts_accepted = self.conflicts_count
        mrsrequest.conflicts_resolved = conflicts_resolved

        mrsrequest.insured = person
        self.object = self.forms['mrsrequest'].save()

        for form in self.forms['transport_formset'].forms:
            Transport.objects.create(
                date_depart=form.cleaned_data.get('date_depart'),
                date_return=form.cleaned_data.get('date_return'),
                mrsrequest=self.object,
            )

        if self.forms['use_email'].cleaned_data['use_email']:
            person.use_email = True

        person.conflicts_accepted += self.conflicts_count
        person.conflicts_resolved += conflicts_resolved
        person.save()

        mail_context = dict(view=self, base_url=settings.BASE_URL)
        Caller(
            callback='djcall.django.email_send',
            kwargs=dict(
                subject=template.loader.get_template(
                    'mrsrequest/success_mail_title.txt'
                ).render(mail_context).strip(),
                body=template.loader.get_template(
                    'mrsrequest/success_mail_body.txt'
                ).render(mail_context).strip(),
                to=[self.object.insured.email],
                reply_to=[settings.TEAM_EMAIL],
            )
        ).spool('mail')

        return True
コード例 #8
0
def stat_update(sender, instance, **kwargs):
    Caller(
        callback='mrsstat.models.update_stat_for_mrsrequest',
        kwargs=dict(pk=instance.pk),
    ).spool('stat')
コード例 #9
0
ファイル: views.py プロジェクト: betagouv/mrs
    def post_mrsrequest(self, request, *args, **kwargs):
        if not self.has_perm():
            return http.HttpResponseBadRequest()

        self.forms = self.post_get_forms(request)

        self.success = self.confirm = False
        if not self.form_errors():
            confirmed = self.request.POST.get('confirm', False)

            # beware that form_confirms will provision forms with artificial
            # errors: do NOT call it if confirmed was POST-ed
            if confirmed or not self.form_confirms():
                with transaction.atomic():
                    self.save_mrsrequest()
                    self.success = True

                if self.conflicts_count:
                    # also increment the daily stat !
                    Caller(
                        callback='mrsstat.models.increment',
                        kwargs=dict(
                            name='mrsrequest_count_conflicting',
                            count=1,
                            date=today(),
                            caisse=self.forms['mrsrequest'].cleaned_data.get(
                                'caisse').pk,
                            recalculate=['mrsrequest_count_resolved'],
                        ),
                    ).spool('stat')

                if self.rating_show():
                    self.rating_form = RatingForm(
                        prefix='rating',
                        initial=dict(mrsrequest_uuid=self.mrsrequest_uuid),
                    )

            else:
                # will be needed later on by save_mrsrequest to calculate the
                # number of conflicts that the user has resolved on their own
                # for this MRSRequest
                self.session.setdefault(
                    'conflicts_initial',
                    self.conflicts_count,
                )

                # also increment the daily stat if not done already !
                if 'conflicts_initial_incremented' not in self.session:
                    Caller(
                        callback='mrsstat.models.increment',
                        kwargs=dict(
                            name='mrsrequest_count_conflicted',
                            count=1,
                            date=today(),
                            caisse=self.forms['mrsrequest'].cleaned_data.get(
                                'caisse').pk,
                            recalculate=['mrsrequest_count_resolved'],
                        ),
                    ).spool('stat')
                    self.session['conflicts_initial_incremented'] = True

                # trigger session backend write by session middleware
                self.request.session.modified = True
                self.confirm = True

        return generic.TemplateView.get(self, request, *args, **kwargs)
コード例 #10
0
def test_str():
    assert str(Caller(callback='lol')) == 'lol()'
    assert str(Caller(callback='lol', kwargs=dict(a=1,
                                                  b=2))) == 'lol(a=1, b=2)'
コード例 #11
0
def test_python_callback():
    caller = Caller(callback='djcall.models.Caller.objects.all')
    assert caller.python_callback == Caller.objects.all