Changeset - fcf4e5cffb54
[Not reviewed]
0 3 0
Christopher Neugebauer - 7 years ago 2016-12-07 00:19:30
chrisjrn@gmail.com
Adds forms for nag_unpaid
3 files changed with 46 insertions and 0 deletions:
0 comments (0 inline, 0 general)
registrasion/forms.py
Show inline comments
 
from registrasion.controllers.product import ProductController
 
from registrasion.models import commerce
 
from registrasion.models import inventory
 

	
 
from django import forms
 
from django.core.exceptions import ValidationError
 
from django.db.models import Q
 

	
 

	
 
class ApplyCreditNoteForm(forms.Form):
 

	
 
    def __init__(self, user, *a, **k):
 
        ''' User: The user whose invoices should be made available as
 
        choices. '''
 
        self.user = user
...
 
@@ -389,8 +390,35 @@ def staff_products_form_factory(user):
 
        )
 

	
 
    return StaffProductsForm
 

	
 
def staff_products_formset_factory(user):
 
    ''' Creates a formset of StaffProductsForm for the given user. '''
 
    form_type = staff_products_form_factory(user)
 
    return forms.formset_factory(form_type)
 

	
 

	
 
class InvoiceNagForm(forms.Form):
 
    invoice = forms.ModelMultipleChoiceField(
 
        widget=forms.CheckboxSelectMultiple,
 
        queryset=commerce.Invoice.objects.all(),
 
    )
 

	
 
    def __init__(self, *a, **k):
 
        category = k.pop('category', None) or []
 
        product = k.pop('product', None) or []
 

	
 
        category = [int(i) for i in category]
 
        product = [int(i) for i in product]
 

	
 
        super(InvoiceNagForm, self).__init__(*a, **k)
 

	
 
        print repr(category), repr(product)
 

	
 
        qs = commerce.Invoice.objects.filter(
 
            status=commerce.Invoice.STATUS_UNPAID,
 
        ).filter(
 
            Q(lineitem__product__category__in=category) |
 
            Q(lineitem__product__in=product)
 
        )
 

	
 
        self.fields['invoice'].queryset = qs
registrasion/urls.py
Show inline comments
...
 
@@ -8,16 +8,17 @@ from .views import (
 
    checkout,
 
    credit_note,
 
    edit_profile,
 
    extend_reservation,
 
    guided_registration,
 
    invoice,
 
    invoice_access,
 
    manual_payment,
 
    nag_unpaid,
 
    product_category,
 
    refund,
 
    review,
 
)
 

	
 

	
 
public = [
 
    url(r"^amend/([0-9]+)$", amend_registration, name="amend_registration"),
...
 
@@ -29,16 +30,17 @@ public = [
 
    url(r"^invoice/([0-9]+)$", invoice, name="invoice"),
 
    url(r"^invoice/([0-9]+)/([A-Z0-9]+)$", invoice, name="invoice"),
 
    url(r"^invoice/([0-9]+)/manual_payment$",
 
        manual_payment, name="manual_payment"),
 
    url(r"^invoice/([0-9]+)/refund$",
 
        refund, name="refund"),
 
    url(r"^invoice_access/([A-Z0-9]+)$", invoice_access,
 
        name="invoice_access"),
 
    url(r"^nag_unpaid$", nag_unpaid, name="nag_unpaid"),
 
    url(r"^profile$", edit_profile, name="attendee_edit"),
 
    url(r"^register$", guided_registration, name="guided_registration"),
 
    url(r"^review$", review, name="review"),
 
    url(r"^register/([0-9]+)$", guided_registration,
 
        name="guided_registration"),
 
]
 

	
 

	
registrasion/views.py
Show inline comments
...
 
@@ -911,8 +911,24 @@ def extend_reservation(request, user_id, days=7):
 
    ''' Allows staff to extend the reservation on a given user's cart.
 
    '''
 

	
 
    user = User.objects.get(id=int(user_id))
 
    cart = CartController.for_user(user)
 
    cart.extend_reservation(datetime.timedelta(days=days))
 

	
 
    return redirect(request.META["HTTP_REFERER"])
 

	
 

	
 
@user_passes_test(_staff_only)
 
def nag_unpaid(request):
 
    ''' Allows staff to nag users with unpaid invoices. '''
 

	
 
    category = request.GET.getlist("category", [])
 
    product  = request.GET.getlist("product", [])
 

	
 
    form = forms.InvoiceNagForm(
 
        request.POST or None,
 
        category=category,
 
        product=product,
 
    )
 

	
 
    print form.fields['invoice'].queryset
0 comments (0 inline, 0 general)