Projet

Général

Profil

0001-lingo-show-backend-callback-URL-in-update-views-4914.patch

Benjamin Dauvergne, 05 décembre 2020 08:17

Télécharger (4,58 ko)

Voir les différences:

Subject: [PATCH] lingo: show backend callback URL in update views (#49145)

 combo/apps/lingo/manager_views.py                    | 12 ++++++++++++
 combo/apps/lingo/models.py                           |  7 +++++++
 .../lingo/templates/lingo/paymentbackend_form.html   |  4 ++++
 combo/apps/lingo/templates/lingo/regie_form.html     |  4 ++++
 combo/apps/lingo/views.py                            |  7 ++-----
 5 files changed, 29 insertions(+), 5 deletions(-)
combo/apps/lingo/manager_views.py
54 54
    form_class = RegieForm
55 55
    success_url = reverse_lazy('lingo-manager-regie-list')
56 56

  
57
    def get_context_data(self, **kwargs):
58
        ctx = super().get_context_data(**kwargs)
59
        ctx['callback_url'] = self.request.build_absolute_uri(
60
            self.object.get_callback_url())
61
        return ctx
62

  
57 63

  
58 64
class RegieDeleteView(DeleteView):
59 65
    model = Regie
......
78 84
    form_class = PaymentBackendForm
79 85
    success_url = reverse_lazy('lingo-manager-paymentbackend-list')
80 86

  
87
    def get_context_data(self, **kwargs):
88
        ctx = super().get_context_data(**kwargs)
89
        ctx['callback_url'] = self.request.build_absolute_uri(
90
            self.object.get_callback_url())
91
        return ctx
92

  
81 93

  
82 94
class PaymentBackendDeleteView(DeleteView):
83 95
    model = PaymentBackend
combo/apps/lingo/models.py
168 168
        backend = next(serializers.deserialize('json', json.dumps([json_backend]), ignorenonexistent=True))
169 169
        backend.save()
170 170

  
171
    def get_callback_url(self):
172
        return reverse('lingo-callback-payment-backend', kwargs={
173
            'payment_backend_pk': self.pk})
174

  
171 175

  
172 176
@python_2_unicode_compatible
173 177
class Regie(models.Model):
......
469 473
        regie = next(serializers.deserialize('json', json.dumps([json_regie]), ignorenonexistent=True))
470 474
        regie.save()
471 475

  
476
    def get_callback_url(self):
477
        return self.payment_backend.get_callback_url()
478

  
472 479

  
473 480
class BasketItem(models.Model):
474 481
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True)
combo/apps/lingo/templates/lingo/paymentbackend_form.html
11 11

  
12 12
{% block content %}
13 13

  
14
{% if object.id and callback_url %}
15
    <p class="info">{% trans "Callback URL:" %} <a href="{{ callback_url }}">{{ callback_url }}</a></p>
16
{% endif %}
17

  
14 18
<form method="post" enctype="multipart/form-data">
15 19
  {% csrf_token %}
16 20
  {{ form.as_p }}
combo/apps/lingo/templates/lingo/regie_form.html
11 11

  
12 12
{% block content %}
13 13

  
14
{% if object.id and callback_url %}
15
    <p class="info">{% trans "Callback URL:" %} <a href="{{ callback_url }}">{{ callback_url }}</a></p>
16
{% endif %}
17

  
14 18
<form method="post" enctype="multipart/form-data">
15 19
  {% csrf_token %}
16 20
  {{ form.as_p }}
combo/apps/lingo/views.py
68 68
    if isinstance(regie_or_payment_backend, Regie):
69 69
        payment_backend = regie_or_payment_backend.payment_backend
70 70
    options = payment_backend.service_options
71
    options.update({
72
        'automatic_return_url': request.build_absolute_uri(
73
                reverse('lingo-callback-payment-backend',
74
                        kwargs={'payment_backend_pk': payment_backend.id})),
75
    })
71
    options['automatic_return_url'] = request.build_absolute_uri(
72
            payment_backend.get_callback_url())
76 73

  
77 74
    if transaction_id:
78 75
        options['normal_return_url'] = request.build_absolute_uri(
79
-