Adds “badges” view, which lets us render multiple users’ badges into a zipfile.
This commit is contained in:
parent
4fc494783d
commit
66dedfc101
3 changed files with 41 additions and 0 deletions
|
@ -442,6 +442,8 @@ class InvoicesWithProductAndStatusForm(forms.Form):
|
||||||
id__in=qs,
|
id__in=qs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
qs = qs.select_related("user__attendee__attendeeprofilebase")
|
||||||
|
|
||||||
self.fields['invoice'].queryset = qs
|
self.fields['invoice'].queryset = qs
|
||||||
self.fields['invoice'].initial = [i.id for i in qs]
|
self.fields['invoice'].initial = [i.id for i in qs]
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ from django.conf.urls import url
|
||||||
from .views import (
|
from .views import (
|
||||||
amend_registration,
|
amend_registration,
|
||||||
badge,
|
badge,
|
||||||
|
badges,
|
||||||
checkout,
|
checkout,
|
||||||
credit_note,
|
credit_note,
|
||||||
edit_profile,
|
edit_profile,
|
||||||
|
@ -24,6 +25,7 @@ from .views import (
|
||||||
public = [
|
public = [
|
||||||
url(r"^amend/([0-9]+)$", amend_registration, name="amend_registration"),
|
url(r"^amend/([0-9]+)$", amend_registration, name="amend_registration"),
|
||||||
url(r"^badge/([0-9]+)$", badge, name="badge"),
|
url(r"^badge/([0-9]+)$", badge, name="badge"),
|
||||||
|
url(r"^badges$", badges, name="badges"),
|
||||||
url(r"^category/([0-9]+)$", product_category, name="product_category"),
|
url(r"^category/([0-9]+)$", product_category, name="product_category"),
|
||||||
url(r"^checkout$", checkout, name="checkout"),
|
url(r"^checkout$", checkout, name="checkout"),
|
||||||
url(r"^checkout/([0-9]+)$", checkout, name="checkout"),
|
url(r"^checkout/([0-9]+)$", checkout, name="checkout"),
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import datetime
|
import datetime
|
||||||
import sys
|
import sys
|
||||||
import util
|
import util
|
||||||
|
import zipfile
|
||||||
|
|
||||||
from registrasion import forms
|
from registrasion import forms
|
||||||
from registrasion import util
|
from registrasion import util
|
||||||
|
@ -985,6 +986,42 @@ def badge(request, user_id):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
def badges(request):
|
||||||
|
''' Either displays a form containing a list of users with badges to
|
||||||
|
render, or returns a .zip file containing their badges. '''
|
||||||
|
|
||||||
|
category = request.GET.getlist("category", [])
|
||||||
|
product = request.GET.getlist("product", [])
|
||||||
|
status = request.GET.get("status")
|
||||||
|
|
||||||
|
form = forms.InvoicesWithProductAndStatusForm(
|
||||||
|
request.POST or None,
|
||||||
|
category=category,
|
||||||
|
product=product,
|
||||||
|
status=status,
|
||||||
|
)
|
||||||
|
|
||||||
|
if form.is_valid():
|
||||||
|
response = HttpResponse()
|
||||||
|
response["Content-Type"] = "application.zip"
|
||||||
|
response["Content-Disposition"] = 'attachment; filename="badges.zip"'
|
||||||
|
|
||||||
|
z = zipfile.ZipFile(response, "w")
|
||||||
|
|
||||||
|
for invoice in form.cleaned_data["invoice"]:
|
||||||
|
user = invoice.user
|
||||||
|
badge = render_badge(user)
|
||||||
|
z.writestr("badge_%d.svg" % user.id, badge.encode("utf-8"))
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"form": form,
|
||||||
|
}
|
||||||
|
|
||||||
|
return render(request, "registrasion/badges.html", data)
|
||||||
|
|
||||||
|
|
||||||
def render_badge(user):
|
def render_badge(user):
|
||||||
''' Renders a single user's badge. '''
|
''' Renders a single user's badge. '''
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue