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.  Could you provide the code (or the relevant parts) for the Substance Admin form?
Thanks!

Matthew

I'm still in trouble and including some code. I'm not being precious about it just hoping not to overwhelm you. Please ask for the next instalment ...

class SubstanceAdmin(admin.ModelAdmin):

    def subscribe(self, sm2mi, fee_type, fullyear=False):
        """
        sm2mi is the substance<-ingredient m2m through record
        fee_type determines the subscription fee amount
        fullyear=False means calculate the fee pro-rata to 30 September

        We don't need a request here so this can be imported from elsewhere.
        Only called if a fee is payable. Only returns a subscription if no token or
        fullyear == True meaning a subscription renewal is due
        """
        subscription, new = Subscription.objects.get_or_create(
            licensee=sm2mi.substance.division.company,
            ingredient=sm2mi.ingredient,
            fee_type=fee_type,
        )
        if not subscription.token or fullyear:
            return subscription

    def change_view(self, request, object_id, form_url='', extra_context=None):
        """
        For the billing system we want to include all the context data so the
        change_form populates itself properly. See collect_content
        self = SubstanceAdmin
        request = wsgi request object
        object_id = substance
        form_url = no idea!
        extra_context = no_idea
        """
        sm2mis = Substance_Ingredients.objects.filter(substance_id=object_id)
        for sm2mi in sm2mis:
            payable, fee_type = sm2mi.fee_payable()  # eg., True, PAID_DATA
            if payable:
                subscription = self.subscribe(sm2mi, fee_type)
                if subscription:    # we need to collect money for the owner
                    self.change_form_template = 'payment.html'
                    content = collect_content(
                        sm2mi,
                        subscription,
                    )
                    return payment_view(
                        request,
                        sm2mi,
                        subscription,
                        content=content
                    )

        return super(SubstanceAdmin, self).change_view(
            request, object_id, form_url, extra_context=extra_context,
        )

Here is the payment form ... which is further down in admin.py

    class IngredientsInline(admin.StackedInline):

        class PaymentForm(admin.StackedInline.form):
            sm2mi_id = forms.CharField(widget=forms.HiddenInput, required=False)
            ingredient_id = forms.CharField(widget=forms.HiddenInput, required=False)
            subscription_id = forms.CharField(widget=forms.HiddenInput, required=False)
            licensee_id = forms.CharField(widget=forms.HiddenInput, required=False)

            stripeToken = forms.CharField(widget=forms.HiddenInput, required=False)
            stripeEmail = forms.CharField(widget=forms.HiddenInput, required=False)
            stripeBillingName = forms.CharField(widget=forms.HiddenInput, required=False)
            stripeBillingAddressLine1 = forms.CharField(widget=forms.HiddenInput, required=False)
            stripeBillingAddressZip = forms.CharField(widget=forms.HiddenInput, required=False)
            stripeBillingAddressState = forms.CharField(widget=forms.HiddenInput, required=False)
            stripeBillingAddressCity = forms.CharField(widget=forms.HiddenInput, required=False)
            stripeBillingAddressCountry = forms.CharField(widget=forms.HiddenInput, required=False)

        form = PaymentForm

All of the above is working so far as launching the Stripe _javascript_ popup and generating the receipt record correctly and so on but does not return to the admin nor render the success page.

The try/except block in payment_view() barfs as follows ...

            content['sm2mi'] = sm2mi
            content['receipt'] = receipt
            content['subscription'] = subscription
            content['message'] = mark_safe(display_message)
            content['link'] = '/admin/substance/substance/{0}/change/'.format(
                sm2mi.substance.id
            )
            # report success to the card payer
            try:
                return render(
                    template_name='success.html',
                    context=content,
                    request=request,
                )
            except Exception as err:
                print('\n327 billing.views %s' % err)


327 billing.views Reverse for 'admin' not found. 'admin' is not a valid view function or pattern name.


Thanks for looking at it

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.
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/c70b8afa-6c7b-07b8-3f5d-ec2da8047951%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

Reply via email to