Changeset - 9da41c06de54
[Not reviewed]
0 3 0
Christopher Neugebauer - 7 years ago 2017-01-09 07:57:49
chrisjrn@gmail.com
Adds first badge support
3 files changed with 31 insertions and 0 deletions:
0 comments (0 inline, 0 general)
registrasion/templatetags/registrasion_tags.py
Show inline comments
...
 
@@ -50,59 +50,70 @@ def available_credit(context):
 
    ''' Calculates the sum of unclaimed credit from this user's credit notes.
 

	
 
    Returns:
 
        Decimal: the sum of the values of unclaimed credit notes for the
 
            current user.
 

	
 
    '''
 

	
 
    notes = commerce.CreditNote.unclaimed().filter(
 
        invoice__user=user_for_context(context),
 
    )
 
    ret = notes.values("amount").aggregate(Sum("amount"))["amount__sum"] or 0
 
    return 0 - ret
 

	
 

	
 
@register.assignment_tag(takes_context=True)
 
def invoices(context):
 
    '''
 

	
 
    Returns:
 
        [models.commerce.Invoice, ...]: All of the current user's invoices. '''
 
    return commerce.Invoice.objects.filter(user=user_for_context(context))
 

	
 

	
 
@register.assignment_tag(takes_context=True)
 
def items_pending(context):
 
    ''' Gets all of the items that the user from this context has reserved.
 

	
 
    The user will be either `context.user`, and `context.request.user` if
 
    the former is not defined.
 
    '''
 

	
 
    return ItemController(user_for_context(context)).items_pending()
 

	
 

	
 
@register.assignment_tag(takes_context=True)
 
def items_purchased(context, category=None):
 
    ''' Returns the items purchased for this user.
 

	
 
    The user will be either `context.user`, and `context.request.user` if
 
    the former is not defined.
 
    '''
 

	
 
    return ItemController(user_for_context(context)).items_purchased(
 
        category=category
 
    )
 

	
 

	
 
@register.assignment_tag(takes_context=True)
 
def total_items_purchased(context, category=None):
 
    ''' Returns the number of items purchased for this user (sum of quantities).
 

	
 
    The user will be either `context.user`, and `context.request.user` if
 
    the former is not defined.
 
    '''
 

	
 
    return sum(i.quantity for i in items_purchased(context, category))
 

	
 

	
 
@register.assignment_tag(takes_context=True)
 
def report_as_csv(context, section):
 

	
 
    old_query = context.request.META["QUERY_STRING"]
 
    query = dict([("section", section), ("content_type", "text/csv")])
 
    querystring = urlencode(query)
 

	
 
    if old_query:
 
        querystring = old_query + "&" + querystring
 

	
 
    return context.request.path + "?" + querystring
registrasion/urls.py
Show inline comments
 
from reporting import views as rv
 

	
 
from django.conf.urls import include
 
from django.conf.urls import url
 

	
 
from .views import (
 
    amend_registration,
 
    badge,
 
    checkout,
 
    credit_note,
 
    edit_profile,
 
    extend_reservation,
 
    guided_registration,
 
    invoice,
 
    invoice_access,
 
    invoice_mailout,
 
    manual_payment,
 
    product_category,
 
    refund,
 
    review,
 
)
 

	
 

	
 
public = [
 
    url(r"^amend/([0-9]+)$", amend_registration, name="amend_registration"),
 
    url(r"^badge/([0-9]+)$", badge, name="badge"),
 
    url(r"^category/([0-9]+)$", product_category, name="product_category"),
 
    url(r"^checkout$", checkout, name="checkout"),
 
    url(r"^checkout/([0-9]+)$", checkout, name="checkout"),
 
    url(r"^credit_note/([0-9]+)$", credit_note, name="credit_note"),
 
    url(r"^extend/([0-9]+)$", extend_reservation, name="extend_reservation"),
 
    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"^invoice_mailout$", invoice_mailout, name="invoice_mailout"),
 
    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"),
 
]
 

	
 

	
 
reports = [
 
    url(r"^$", rv.reports_list, name="reports_list"),
 
    url(r"^attendee/?$", rv.attendee, name="attendee"),
 
    url(r"^attendee_data/?$", rv.attendee_data, name="attendee_data"),
 
    url(r"^attendee/([0-9]*)$", rv.attendee, name="attendee"),
 
    url(r"^credit_notes/?$", rv.credit_notes, name="credit_notes"),
 
    url(r"^discount_status/?$", rv.discount_status, name="discount_status"),
 
    url(r"^invoices/?$", rv.invoices, name="invoices"),
 
    url(
 
        r"^paid_invoices_by_date/?$",
 
        rv.paid_invoices_by_date,
 
        name="paid_invoices_by_date"
 
    ),
 
    url(r"^product_status/?$", rv.product_status, name="product_status"),
 
    url(r"^reconciliation/?$", rv.reconciliation, name="reconciliation"),
 
    url(
 
        r"^speaker_registrations/?$",
 
        rv.speaker_registrations,
 
        name="speaker_registrations",
 
    ),
 
]
 

	
 

	
 
urlpatterns = [
 
    url(r"^reports/", include(reports)),
 
    url(r"^", include(public))  # This one must go last.
registrasion/views.py
Show inline comments
...
 
@@ -923,48 +923,66 @@ def extend_reservation(request, user_id, days=7):
 
Email = namedtuple(
 
    "Email",
 
    ("subject", "body", "from_email", "recipient_list"),
 
)
 

	
 
@user_passes_test(_staff_only)
 
def invoice_mailout(request):
 
    ''' Allows staff to send emails to users based on their invoice status. '''
 

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

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

	
 
    emails = []
 

	
 
    if form.is_valid():
 
        emails = []
 
        for invoice in form.cleaned_data["invoice"]:
 
            # datatuple = (subject, message, from_email, recipient_list)
 
            from_email = form.cleaned_data["from_email"]
 
            subject = form.cleaned_data["subject"]
 
            body = Template(form.cleaned_data["body"]).render(
 
                Context({
 
                    "invoice" : invoice,
 
                    "user" : invoice.user,
 
                })
 
            )
 
            recipient_list = [invoice.user.email]
 
            emails.append(Email(subject, body, from_email, recipient_list))
 

	
 
        if form.cleaned_data["action"] == forms.InvoiceEmailForm.ACTION_SEND:
 
            # Send e-mails *ONLY* if we're sending.
 
            send_mass_mail(emails)
 
            messages.info(request, "The e-mails have been sent.")
 

	
 
    data = {
 
        "form": form,
 
        "emails": emails,
 
    }
 

	
 
    return render(request, "registrasion/invoice_mailout.html", data)
 

	
 

	
 
@user_passes_test(_staff_only)
 
def badge(request, user_id):
 
    ''' Renders a single user's badge (SVG). '''
 

	
 
    user_id = int(user_id)
 

	
 
    data = {
 
        "user": User.objects.get(pk=user_id),
 
    }
 

	
 
    print User.objects.get(pk=user_id)
 

	
 
    response = render(request, "registrasion/badge.svg", data)
 
    response["Content-Type"] = "image/svg+xml"
 
    response["Content-Disposition"] = 'inline; filename="badge.svg"'
 
    return response
0 comments (0 inline, 0 general)