250 'over_reg' : reg_count >= REG_TOTAL and True or False, |
250 'over_reg' : reg_count >= REG_TOTAL and True or False, |
251 'wifi_form' : wifi_form, |
251 'wifi_form' : wifi_form, |
252 'message' : message, |
252 'message' : message, |
253 'login_form' : login_form |
253 'login_form' : login_form |
254 })) |
254 })) |
|
255 |
|
256 |
|
257 @login_required |
|
258 def regstats(request, scope, |
|
259 template_name='registration/regstats.html'): |
|
260 """View that gives the statistics of registrants. |
|
261 """ |
|
262 from project.scipycon.registration.forms import RegistrationAdminSelectForm |
|
263 if not request.user.is_staff: |
|
264 redirect_to = reverse('scipycon_login', kwargs={'scope': scope}) |
|
265 |
|
266 if request.method == "POST": |
|
267 form = RegistrationAdminSelectForm(request.POST) |
|
268 if form.is_valid(): |
|
269 conference = form.cleaned_data['by_conference'] |
|
270 tutorial = form.cleaned_data['by_tutorial'] |
|
271 sprint = form.cleaned_data['by_sprint'] |
|
272 include = form.cleaned_data['include'] |
|
273 |
|
274 q = Registration.objects.all() |
|
275 q = q.filter(conference=conference) |
|
276 q = q.filter(tutorial=tutorial) |
|
277 q = q.filter(sprint=sprint) |
|
278 |
|
279 q = q.order_by('registrant__email') |
|
280 |
|
281 query = q.query |
|
282 results = list(q) |
|
283 |
|
284 if include == []: |
|
285 # default to include all fields |
|
286 include = [i[0] for i in IC] |
|
287 if results: |
|
288 response = HttpResponse(mimetype='text/csv') |
|
289 response['Content-Disposition'] = 'attachment; filename=registrations.csv' |
|
290 output = csv.writer(response) |
|
291 output.writerow([h for h in include]) |
|
292 for row in results: |
|
293 conference = row.conference == True and 'yes' or 'no' |
|
294 tutorial = row.tutorial == True and 'yes' or 'no' |
|
295 sprint = row.sprint == True and 'yes' or 'no' |
|
296 wrow = [] |
|
297 if 'Name' in include: |
|
298 wrow.append( |
|
299 row.registrant.get_full_name().encode('utf-8')) |
|
300 if 'Email' in include: |
|
301 wrow.append(row.registrant.email.encode('utf-8')) |
|
302 if 'Organisation' in include: |
|
303 wrow.append(row.organisation.encode('utf-8')) |
|
304 if 'Conference' in include: |
|
305 wrow.append(conference) |
|
306 if 'Tutorial' in include: |
|
307 wrow.append(tutorial) |
|
308 if 'Sprint' in include: |
|
309 wrow.append(sprint) |
|
310 output.writerow(wrow) |
|
311 return response |
|
312 else: |
|
313 no_results = u'No results found for the query' |
|
314 |
|
315 else: |
|
316 form = RegistrationAdminSelectForm() |
|
317 return render_to_response(template_name, RequestContext(request, |
|
318 locals())) |