On 25/01/2019 2:40 am, Matthew Pava wrote:
Hi Mike,
I'm not really seeing why this is throwing errors at you. It seems like you've
done everything right.
That's very generous of you :)
I got it mostly working last night after patching some code which was
throwing errors. There's a bit of robustness to add before I'm properly
confident but it seems within reach now.
Thanks for listening. When I have it all working I'll try and put
together an Admin recipe for the use-case of detecting a required
payment and wheeling in an external payment gateway.
The scenario here is that the m2m record relating Substance to itself to
form mixtures has a save method which detects whether it is free
(essentially open information) or is a revenue raiser for the
information curator. That triggers the Admin change_view() which calls
the payment gateway via a billing system I wrote for another project
(paid online training) and modified for this system. substance.admin.py
is 2500+ LOC and there are 40+ models in the substance app.
Thanks again
Mike
Could you provide the code (or the relevant parts) for the Substance Admin form?
Thanks!
-----Original Message-----
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On
Behalf Of Mike Dewhirst
Sent: Wednesday, January 23, 2019 5:23 PM
To: django-users@googlegroups.com
Subject: Re: Admin form_url breakout problem
On 24/01/2019 9:35 am, Matthew Pava wrote:
Have you tried setting APPEND_SLASH = False in your settings?
Yes. The result is ...
Page not found(404)
Request Method: POST
Request URL:
http://localhost:8000/admin/substance/substance/1442/change/payment
Using the URLconf defined in|ssds.urls|, Django tried these URL
patterns, in this order:
... followed by all the urls the most pertinent one of which is ...
^admin/ ^substance/substance/ ^(.+)/change/$
[name='substance_substance_change']
-----Original Message-----
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On
Behalf Of Mike Dewhirst
Sent: Wednesday, January 23, 2019 3:48 PM
To: django-users@googlegroups.com
Subject: Re: Admin form_url breakout problem
On 24/01/2019 1:08 am, Matthew Pava wrote:
It looks like your second URL is different than the first.
*/admin/substance/substance/1442/change/payment*
*/admin/substance/substance/1442/change/payment/change/*
If you just want to add a slash, then add it.
*/admin/substance/substance/1442/change/payment/*
I’m guessing that Django is interpreting the second URL like so:
*/admin/substance/substance/(pk=1442/change/payment)/change/*
You are right. It looks like Django expects the last element of the url
to be the id and automatically appends 'change' to a modelAdmin url.
That apparently invokes the 'change' form.
My mission (I think) is to find a way to launch a non-Admin url from
inside the Admin. Or perhaps from a model method.
That is what I meant with the word 'breakout' in the subject line.
Derek suggested a modelAdmin wrapper a few days ago ... "Basically you
can create your own view and use that to display data in a template that
inherits from, for example, the Django admin form template. A bit tricky
first time but then it seems straightforward."
I'm finding it a bit tricky for sure!
If you can see a way ...
Thanks
Mike
*From:*django-users@googlegroups.com
[mailto:django-users@googlegroups.com] *On Behalf Of *Mike Dewhirst
*Sent:* Wednesday, January 23, 2019 12:57 AM
*To:* Django users
*Subject:* Admin form_url breakout problem
How can I break out of the Admin to a payment gateway? I've tried
form_url='billing:payment_view' in SubstanceAdmin.change_view()
unsuccessfully.
I can semi-break out of the admin and get the beginning of a payment
happening with the following ...
SubstanceAdmin.change_form_template = payment.html (which has Stripe
js and necessary hidden fields)
or
./templates/admin/substance/substance/change_form.html (identical to
payment.html except it calls block.super at the end to render the rest
of the admin page)
SubstanceAdmin.change_view() which collects the contextual data
required for either template
IngredientsInline.form (inherits admin.StackedInline.form) for all
the hidden fields for each ingredient.
With all that, if an ingredient hasn't been paid for, the
billing.Subscription record won't have a Stripe token so the Admin
will launch the payment page. On entering credit card detail and
pressing the button, Stripe happily takes the money and issues a
token. BUT the Admin then barfs with ...
RuntimeError at /admin/substance/substance/1442/change/payment
You called this URL via POST, but the URL doesn't end in a slash and
you have APPEND_SLASH set. Django can't redirect to the slash URL
while maintaining POST data. Change your form to point to
localhost:8000/admin/substance/substance/1442/change/payment/ (note
the trailing slash), or set APPEND_SLASH=False in your Django settings.
... If I add a slash in the browser address bar and press Enter the
next problem emerges ...
ValueError at /admin/substance/substance/1442/change/payment/change/
invalid literal for int() with base 10: '1442/change/payment'
... which tells me the Admin is hoping for
/admin/substance/substance/1442/
I don't know where to go now.
My preference would be to leave the Admin somehow and handle the
payment externally with my billing.payment_view() and
billing.success_view() then at the end find a way to give that
hoped-for url to the server and expect the substance to come up
normally in the admin.
Any advice will be greatly appreciated. Happy to show any code you
might want to see.
Many thanks
Mike
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/f8061a7d-27b5-c929-c364-d8870829ad3e%40dewhirst.com.au
<https://groups.google.com/d/msgid/django-users/f8061a7d-27b5-c929-c364-d8870829ad3e%40dewhirst.com.au?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/d0ae4053cd254b2bbc982cff3637d0a6%40iss2.ISS.LOCAL
<https://groups.google.com/d/msgid/django-users/d0ae4053cd254b2bbc982cff3637d0a6%40iss2.ISS.LOCAL?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/07926202-7c6b-4486-878c-aacdb9f556e6%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.