diff options
Diffstat (limited to 'project/kiwipycon/registration')
-rw-r--r-- | project/kiwipycon/registration/__init__.py | 0 | ||||
-rw-r--r-- | project/kiwipycon/registration/admin.py | 44 | ||||
-rw-r--r-- | project/kiwipycon/registration/forms.py | 179 | ||||
-rw-r--r-- | project/kiwipycon/registration/labels.py | 7 | ||||
-rw-r--r-- | project/kiwipycon/registration/migrations/0001_initial.py | 62 | ||||
-rw-r--r-- | project/kiwipycon/registration/migrations/0002_create_wifi.py | 56 | ||||
-rw-r--r-- | project/kiwipycon/registration/migrations/__init__.py | 0 | ||||
-rw-r--r-- | project/kiwipycon/registration/models.py | 68 | ||||
-rw-r--r-- | project/kiwipycon/registration/pdf.py | 20 | ||||
-rw-r--r-- | project/kiwipycon/registration/tests.py | 19 | ||||
-rw-r--r-- | project/kiwipycon/registration/utils.py | 190 | ||||
-rw-r--r-- | project/kiwipycon/registration/views.py | 336 |
12 files changed, 0 insertions, 981 deletions
diff --git a/project/kiwipycon/registration/__init__.py b/project/kiwipycon/registration/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/project/kiwipycon/registration/__init__.py +++ /dev/null diff --git a/project/kiwipycon/registration/admin.py b/project/kiwipycon/registration/admin.py deleted file mode 100644 index 50acd43..0000000 --- a/project/kiwipycon/registration/admin.py +++ /dev/null @@ -1,44 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import - -#django.contrib -from django.contrib import admin - -#kiwipycon -from .models import Registration -from .models import Wifi - -class RegistrationAdmin(admin.ModelAdmin): - list_display = ('registrant', 'full_name', 'laptop', 'slug', - 'email', 'city', 'organisation', 'occupation', - 'postcode', 'tshirt', 'conference', 'tutorial', - 'sprint', 'allow_contact') - fieldsets = ( - ('Details', { - 'fields': ('slug', 'registrant', 'organisation', 'occupation', - 'city', 'tshirt') - }), - ('Information', { - 'fields': ('allow_contact',), - }), - ) - - search_fields = ['registrant__username', 'registrant__email'] - - def email(self, obj): - return obj.registrant.email - - def full_name(self, obj): - return obj.registrant.get_full_name() - - def laptop(self, obj): - return obj.registrant.wifi_set.values()[0]['wifi'] - -admin.site.register(Registration, RegistrationAdmin) - -class WifiAdmin(admin.ModelAdmin): - list_display = ('user', 'wifi',) - list_filter = ('wifi',) - -admin.site.register(Wifi, WifiAdmin) - diff --git a/project/kiwipycon/registration/forms.py b/project/kiwipycon/registration/forms.py deleted file mode 100644 index 8d366c6..0000000 --- a/project/kiwipycon/registration/forms.py +++ /dev/null @@ -1,179 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import - -#django -from django import forms -from django.core.exceptions import ObjectDoesNotExist - -#django.contrib -from django.contrib.auth.models import User - -from .models import SIZE_CHOICES -from .models import Registration -from .models import Wifi -from project.kiwipycon.sponsor.models import Sponsor - -class RegistrationSubmitForm(forms.Form): - """PyCon registration form - """ - tshirt = forms.ChoiceField(choices=SIZE_CHOICES, required=True, - label=u'T-shirt size', help_text=u'Yes, we all get a t-shirt!') -# beverage = forms.CharField(required=True, label=u'Beverage', -# help_text=u'Your beverage of choice - coffee, tea etc', -# max_length=255, -# widget=forms.TextInput(attrs={'size':'50'})) -# diet = forms.CharField(required=False, label=u'Dietary', -# help_text=u'Special dietary requirements - vegetarian etc', -# max_length=255, -# widget=forms.TextInput(attrs={'size':'50'})) - organisation = forms.CharField(required=True, label=u'Organisation', - help_text=u'The primary organisation that you are a member of.', - max_length=255, - widget=forms.TextInput(attrs={'size':'50'})) - occupation = forms.CharField(required=True, label=u'Occupation', - help_text=u'Title of your occupation', - max_length=255, - widget=forms.TextInput(attrs={'size':'50'})) - city = forms.CharField(required=True, label=u'City', - help_text=u'City of residence', - max_length=255, - widget=forms.TextInput(attrs={'size':'50'})) - postcode = forms.CharField(required=False, label=u'Postcode', - help_text=u'This field is optional', - max_length=10, - widget=forms.TextInput(attrs={'size':'10'})) - allow_contact = forms.BooleanField(required=False, label=u'Contact', - help_text=u'May organizers of SciPy.in contact you after the event?') - conference = forms.BooleanField(required=False, label=u'Conference', - help_text=u"""Do you intend to attend the SciPy conference? - Note: Only conference has an registration fee of Rs.200 which you will - pay on the spot.""") - tutorial = forms.BooleanField(required=False, label=u'Tutorial', - help_text=u'Do you intend to attend the tutorials?') - sprint = forms.BooleanField(required=False, label=u'Sprint', - help_text=u'Do you intend to attend the sprints?') -# party = forms.BooleanField(required=False, label=u'Pre-con party', -# help_text=u'Do you intend to attend the pre-conference party on Friday?') -# discount = forms.BooleanField(required=False, label=u'Student/Unwaged?', -# help_text=u'You will be required to present your Community Services '\ -# 'Card or Student ID on arrival.') -# sponsor = forms.CharField(required=False, label=u'Sponsor code', -# help_text=u'If attending as a sponsor please enter your sponsor code.', -# max_length=50, -# widget=forms.TextInput(attrs={'size':'20'})) - - def demographic_fields(self): - return (self['organisation'], - self['occupation'], - self['city'], - self['postcode']) - - def personal_fields(self): - return (self['tshirt'], - self['conference'], - self['tutorial'], - self['sprint'], - self['allow_contact']) - -# def other_fields(self): -# return (self['sponsor'],) -# -# def clean_sponsor(self): -# """Validates that the entered sponsor code is valid and within limits -# of allowed guests -# """ -# sponsorcode = self.cleaned_data.get("sponsor") -# if sponsorcode: -# try: -# sponsor = Sponsor.objects.get(slug=sponsorcode) -# except ObjectDoesNotExist: -# raise forms.ValidationError( -# u"The sponsor code you entered is not valid.") -# if sponsor: -# guests = sponsor.guests -# if guests == 0: -# raise forms.ValidationError( -# u"The sponsor code you entered is not valid.") -# count = Registration.objects.filter( -# sponsor=sponsorcode).count() -# if count >= guests: -# raise forms.ValidationError( -# u"That sponsor has reached limit of guests.") -# -# -# return sponsorcode - - -class RegistrationEditForm(RegistrationSubmitForm): - id = forms.CharField(widget=forms.HiddenInput) - sponsor = forms.CharField(required=False, widget=forms.HiddenInput) - -class WifiForm(forms.ModelForm): - """PyCon wifi form - """ - - def save(self, user): - wifi = Wifi(user=user, wifi=self.cleaned_data['wifi']) - wifi.save() - return wifi - - class Meta: - model = Wifi - fields = ('wifi',) - -PC = ( - ('all', 'all'), - ('paid', 'paid'), - ('not paid', 'not paid') - ) -HC = ( - ('all', 'all'), - ('party', 'party'), - ('no party', 'no party') - ) -AC = ( - ('all', 'all'), - ('0', '0'), - ('10', '10'), - ('20', '20'), - ('40', '40'), - ) -OC = ( - ('email', 'email'), - ('amount', 'amount'), - ) - -IC = ( - ('Name', 'name'), - ('Email', 'email'), - ('Amount', 'amount'), - ('Organisation', 'organisation'), - ('Conference', 'conference'), - ('Tutorial', 'tutorial'), - ('Sprint', 'sprint'), - ('T-size', 'tshirt'), - ) - -SC = ( - ('all', 'all'), - ('S', 'S'), - ('M', 'M'), - ('L', 'L'), - ('XL', 'XL'), - ) -class RegistrationAdminSelectForm(forms.Form): - """ - Used to make selection for csv download - """ - by_payment = forms.ChoiceField(choices=PC, required=False, - label=u'By payment') - by_amount = forms.MultipleChoiceField(choices=AC, required=False, - label=u'By amount') - by_party = forms.ChoiceField(choices=HC, required=False, - label=u'by party') - by_tshirt = forms.ChoiceField(choices=SC, required=False, - label=u'by tshirt size') - order_by = forms.ChoiceField(choices=OC, required=False, - label=u'order results') - include = forms.MultipleChoiceField(choices=IC, required=False, - label=u'Include fields') diff --git a/project/kiwipycon/registration/labels.py b/project/kiwipycon/registration/labels.py deleted file mode 100644 index c465f2c..0000000 --- a/project/kiwipycon/registration/labels.py +++ /dev/null @@ -1,7 +0,0 @@ - -WIFI_CHOICES = ( - ("0", "Yes"), - ('1', 'No'), - ) - -WIFI_HELP = """Are you bringing a laptop to the event?""" diff --git a/project/kiwipycon/registration/migrations/0001_initial.py b/project/kiwipycon/registration/migrations/0001_initial.py deleted file mode 100644 index 5393708..0000000 --- a/project/kiwipycon/registration/migrations/0001_initial.py +++ /dev/null @@ -1,62 +0,0 @@ -# -*- coding: utf-8 -*- - -from south.db import db -from django.db import models -from project.kiwipycon.registration.models import * - -class Migration: - - def forwards(self, orm): - - # Adding model 'Registration' - db.create_table('registration_registration', ( - ('slug', models.SlugField()), - ('registrant', models.ForeignKey(orm['auth.User'])), - ('organisation', models.CharField(max_length=255, blank=True)), - ('occupation', models.CharField(max_length=255, blank=True)), - ('city', models.CharField(max_length=255, blank=True)), - ('postcode', models.CharField(max_length=255, blank=True)), - ('tshirt', models.CharField(max_length=2)), - ('conference', models.BooleanField(default=False)), - ('tutorial', models.BooleanField(default=False)), - ('sprint', models.BooleanField(default=False)), - ('submitted', models.DateTimeField(auto_now_add=True)), - ('allow_contact', models.BooleanField(default=False)), - ('last_mod', models.DateTimeField(auto_now=True)), - ('id', models.AutoField(primary_key=True)), - )) - db.send_create_signal('registration', ['Registration']) - - - - def backwards(self, orm): - - # Deleting model 'Registration' - db.delete_table('registration_registration') - - - - models = { - 'auth.user': { - '_stub': True, - 'id': ('models.AutoField', [], {'primary_key': 'True'}) - }, - 'registration.registration': { - 'allow_contact': ('models.BooleanField', [], {'default': 'False'}), - 'city': ('models.CharField', [], {'max_length': '255', 'blank': 'True'}), - 'id': ('models.AutoField', [], {'primary_key': 'True'}), - 'last_mod': ('models.DateTimeField', [], {'auto_now': 'True'}), - 'occupation': ('models.CharField', [], {'max_length': '255', 'blank': 'True'}), - 'organisation': ('models.CharField', [], {'max_length': '255', 'blank': 'True'}), - 'conference': ('models.BooleanField', [], {'default': 'False'}), - 'tutorial': ('models.BooleanField', [], {'default': 'False'}), - 'sprint': ('models.BooleanField', [], {'default': 'False'}), - 'postcode': ('models.CharField', [], {'max_length': '255', 'blank': 'True'}), - 'registrant': ('models.ForeignKey', ['User'], {}), - 'slug': ('models.SlugField', [], {}), - 'submitted': ('models.DateTimeField', [], {'auto_now_add': 'True'}), - 'tshirt': ('models.CharField', [], {'max_length': '2'}) - } - } - - complete_apps = ['registration'] diff --git a/project/kiwipycon/registration/migrations/0002_create_wifi.py b/project/kiwipycon/registration/migrations/0002_create_wifi.py deleted file mode 100644 index 55e5a17..0000000 --- a/project/kiwipycon/registration/migrations/0002_create_wifi.py +++ /dev/null @@ -1,56 +0,0 @@ -# -*- coding: utf-8 -*- - -from south.db import db -from django.db import models -from project.kiwipycon.registration.models import * - -class Migration: - - def forwards(self, orm): - - # Adding model 'Wifi' - db.create_table('registration_wifi', ( - ('wifi', models.CharField(max_length=50)), - ('user', models.ForeignKey(orm['auth.User'])), - ('id', models.AutoField(primary_key=True)), - )) - db.send_create_signal('registration', ['Wifi']) - - - - def backwards(self, orm): - - # Deleting model 'Wifi' - db.delete_table('registration_wifi') - - - - models = { - 'auth.user': { - '_stub': True, - 'id': ('models.AutoField', [], {'primary_key': 'True'}) - }, - 'registration.wifi': { - 'id': ('models.AutoField', [], {'primary_key': 'True'}), - 'user': ('models.ForeignKey', ['User'], {}), - 'wifi': ('models.CharField', [], {'max_length': '50'}) - }, - 'registration.registration': { - 'allow_contact': ('models.BooleanField', [], {'default': 'False'}), - 'city': ('models.CharField', [], {'max_length': '255', 'blank': 'True'}), - 'id': ('models.AutoField', [], {'primary_key': 'True'}), - 'last_mod': ('models.DateTimeField', [], {'auto_now': 'True'}), - 'occupation': ('models.CharField', [], {'max_length': '255', 'blank': 'True'}), - 'organisation': ('models.CharField', [], {'max_length': '255', 'blank': 'True'}), - 'conference': ('models.BooleanField', [], {'default': 'False'}), - 'tutorial': ('models.BooleanField', [], {'default': 'False'}), - 'sprint': ('models.BooleanField', [], {'default': 'False'}), - 'postcode': ('models.CharField', [], {'max_length': '255', 'blank': 'True'}), - 'registrant': ('models.ForeignKey', ['User'], {}), - 'slug': ('models.SlugField', [], {}), - 'submitted': ('models.DateTimeField', [], {'auto_now_add': 'True'}), - 'tshirt': ('models.CharField', [], {'max_length': '2'}) - } - } - - complete_apps = ['registration'] diff --git a/project/kiwipycon/registration/migrations/__init__.py b/project/kiwipycon/registration/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/project/kiwipycon/registration/migrations/__init__.py +++ /dev/null diff --git a/project/kiwipycon/registration/models.py b/project/kiwipycon/registration/models.py deleted file mode 100644 index 4ef5356..0000000 --- a/project/kiwipycon/registration/models.py +++ /dev/null @@ -1,68 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import - -#django -from django.db import models -from django.contrib.auth.models import User - -from .utils import send_confirmation_payment_email -from .utils import send_banking_fix_email - -from .labels import WIFI_CHOICES -from .labels import WIFI_HELP - -SIZE_CHOICES = ( - ('S', 'S'), - ('M', 'M'), - ('L', 'L'), - ('XL', 'XL'), - ) - -class Wifi(models.Model): - """Defines wifi options at *PyCon""" - user = models.ForeignKey(User) - wifi = models.CharField(max_length=50, choices=WIFI_CHOICES, - help_text=WIFI_HELP, verbose_name="Laptop") - -class Registration(models.Model): - """Defines registration at *PyCon""" - slug = models.SlugField() - registrant = models.ForeignKey(User) - organisation = models.CharField(max_length=255, blank=True) - occupation = models.CharField(max_length=255, blank=True) - city = models.CharField(max_length=255, blank=True) - postcode = models.CharField(max_length=255, blank=True) -# beverage = models.CharField(max_length=255, blank=True) -# diet = models.CharField(max_length=255, blank=True) -# sponsor = models.CharField(max_length=255, blank=True) - tshirt = models.CharField(max_length=2, choices=SIZE_CHOICES) -# party = models.BooleanField(default=False) -# discount = models.BooleanField(default=False) - - # scipy.in specific - conference = models.BooleanField(default=False) - # scipy.in specific - tutorial = models.BooleanField(default=False) - # scipy.in specific - sprint = models.BooleanField(default=False) - -# amount = models.IntegerField(default=0) - allow_contact = models.BooleanField(default=False) -# payment = models.BooleanField(default=False) - submitted = models.DateTimeField(auto_now_add=True) - last_mod = models.DateTimeField(auto_now=True) - - def __unicode__(self): - return 'Registration for user: <%s %s> %s' % (self.registrant.first_name, - self.registrant.last_name, self.registrant.email) - -# def save(self, *args, **kwargs): -# if(self.id): -# old_reg = Registration.objects.get(pk=self.id) -# if(old_reg.payment == False and self.payment == True \ -# and not self.sponsor): -# send_confirmation_payment_email(self.registrant) -# if(old_reg.slug.startswith('NZ') and self.slug.startswith('KPC') \ -# and not self.sponsor): -# send_banking_fix_email(self.registrant, self.slug) -# super(Registration, self).save(args, kwargs) diff --git a/project/kiwipycon/registration/pdf.py b/project/kiwipycon/registration/pdf.py deleted file mode 100644 index 7fec07a..0000000 --- a/project/kiwipycon/registration/pdf.py +++ /dev/null @@ -1,20 +0,0 @@ -import os - -from django.conf import settings -from django.template.loader import render_to_string - -def save_invoice(user, registration, template_name): - content = render_to_string(template_name, - {'registration' : registration, 'user': user}) - filename = '%s.html' % registration.slug - filepath = os.path.join(settings.USER_MEDIA_PDF, filename) - save_to_file(content, filepath) - -def save_to_pdf(content, filepath): - import pisa - pisa.CreatePDF(str(content), file(filepath, 'wb')) - -def save_to_file(content, filepath): - fout = file(filepath, 'wb') - fout.write(content) - fout.close() diff --git a/project/kiwipycon/registration/tests.py b/project/kiwipycon/registration/tests.py deleted file mode 100644 index 0ea28b2..0000000 --- a/project/kiwipycon/registration/tests.py +++ /dev/null @@ -1,19 +0,0 @@ - - -def test_save_to_pdf(): - """ - >>> from .pdf import save_invoice - >>> from django.db.models.loading import get_model - >>> userModel = get_model('auth', 'user') - >>> user = userModel(username='joe', email='joe@gmail.com', - ... first_name='Joe', last_name='Bloggs') - >>> user.save() - >>> regModel = get_model('registration', 'registration') - >>> registration = regModel(registrant=user, amount=40, - ... slug='NZPYCON-0001') - >>> registration.save() - - >>> save_invoice(user, registration, 'registration/invoice.html') - - """ - pass diff --git a/project/kiwipycon/registration/utils.py b/project/kiwipycon/registration/utils.py deleted file mode 100644 index dac9d6f..0000000 --- a/project/kiwipycon/registration/utils.py +++ /dev/null @@ -1,190 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import - -# django -from django.core.mail import EmailMessage - -def send_confirmation(registrant, invoice, password=None, sponsor=None, - amount=None): - - message = EmailMessage() - message.subject = u'Registration to SciPy.in 2009' - message.from_email = u'admin@scipy.in' - message.to = [registrant.email] - name = '%s %s' % (registrant.first_name, registrant.last_name) - if name.strip() == '': - name = registrant.username - - username = registrant.username - all = {'name': name, - 'password': password, - 'username': username} - - if password: - message.body = confirmation_newuser % all - else: - message.body = confirmation_currentuser % all - - message.send() - -def send_confirmation_payment_email(registrant): - message = EmailMessage() - message.subject = u'Registration payment to SciPy.in 2009' - message.from_email = u'admin@scipy.in' - message.to = [registrant.email] - name = '%s %s' % (registrant.first_name, registrant.last_name) - username = registrant.username - if name.strip() == '': - name = registrant.username - message.body = confirmation_payment % dict(name=name, - username=username) - message.send() - -def send_banking_fix_email(registrant, invoicenum): - message = EmailMessage() - message.subject = u'Registration invoice update to SciPy.in 2009' - message.from_email = u'admin@scipy.in' - message.to = [registrant.email] - name = '%s %s' % (registrant.first_name, registrant.last_name) - username = registrant.username - if name.strip() == '': - name = registrant.username - message.body = banking_fix % dict(name=name, - username=username, invoice=invoicenum) - message.send() - -banking_fix = """ -Dear %(name)s, - -Invoice update to Kiwi Pycon 2009. - -Ooops. We made the invoice number too long to be entered for internet banking. -We have therefore changed the prefix and your new invoice number is: -%(invoice)s - -You will find that your online invoice has been updated. Thanks for your -patience. - -http://nz.pycon.org/invoice -A pdf version here: -http://nz.pycon.org/pdf_invoice - -Regards, -The Kiwi Pycon 2009 Team - -Your username, in case you've forgotten: %(username)s. - -If you have lost your password to the website please visit: -http://nz.pycon.org/password-reset - - """ - -confirmation_payment = """ -Dear %(name)s, - -Welcome to Kiwi Pycon 2009. - -Your payment has been received and your attendence confirmed. - -Many thanks! - -You can view your invoice at: -http://nz.pycon.org/invoice -And a pdf version here: -http://nz.pycon.org/pdf_invoice - -Regards, -The Kiwi Pycon 2009 Team - -Your username, in case you've forgotten: %(username)s. - -If you have lost your password to the website please visit: -http://nz.pycon.org/password-reset - - """ - -confirmation_newuser = """ -Dear %(name)s, - -Welcome to SciPy.in 2009. You may log in to -http://scipy.in/login using the following credentials: - -Username: %(username)s -Password: %(password)s - -There is an entry fee for the SciPy conference only. However -the sprint and tutorials don't have any entry fee. The entry -fee for the conference can be paid on the spot on the first -day of the conference. - -Thanks for your registration! - -Regards, -The SciPy.in Team - -If you lose your password to the website please visit: -http://scipy.in/password-reset - """ - -confirmation_sponsoreduser = """ -Dear %(name)s, - -Welcome to Kiwi Pycon 2009. - -Your username is: %(username)s - -Your registration has been accepted as a guest of %(stype)s -sponsor %(sname)s. - -Thanks! - -Regards, -The Kiwi Pycon 2009 Team - -If you have lost your password to the website please visit: -http://nz.pycon.org/password-reset - - """ - -confirmation_sponsorednewuser = """ -Dear %(name)s, - -Welcome to Kiwi Pycon 2009. - -Your username is: %(username)s -Your password is: %(password)s - -Your registration has been accepted as a guest of %(stype)s sponsor %(sname)s. - -Thanks! - -Regards, -The Kiwi Pycon 2009 Team - -If you lose your password to the website please visit: -http://nz.pycon.org/password-reset - - """ - -confirmation_currentuser = """ -Dear %(name)s, - -Welcome to SciPy.in 2009. You may log in to -http://scipy.in/login using the following credentials: - -Username: %(username)s -Password: %(password)s - -There is an entry fee for the SciPy conference only. However -the sprint and tutorials don't have any entry fee. The entry -fee for the conference can be paid on the spot on the first -day of the conference. - -Thanks for your registration! - -Regards, -The SciPy.in Team - -If you lose your password to the website please visit: -http://scipy.in/password-reset - """ diff --git a/project/kiwipycon/registration/views.py b/project/kiwipycon/registration/views.py deleted file mode 100644 index 754dc15..0000000 --- a/project/kiwipycon/registration/views.py +++ /dev/null @@ -1,336 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import - -import cStringIO as StringIO -import csv - -# django -from django.conf import settings -from django.shortcuts import render_to_response -from django.template.loader import render_to_string -from django.shortcuts import get_object_or_404 -from django.template import RequestContext -from django.core.urlresolvers import reverse -from django.http import HttpResponse - -from django.contrib.auth.decorators import login_required -from django.contrib.auth.forms import AuthenticationForm -from django.contrib.auth.models import User -from django.core.exceptions import ObjectDoesNotExist - -#kiwipycon -from project.kiwipycon.utils import set_message_cookie -from project.kiwipycon.utils import slugify -from project.kiwipycon.user.models import UserProfile -from project.kiwipycon.user.utils import kiwipycon_createregistrant -from project.kiwipycon.user.forms import RegistrantForm -from project.kiwipycon.sponsor.models import Sponsor -from project.kiwipycon.talk.models import Talk - -from .models import Registration -from .models import Wifi -from .forms import RegistrationSubmitForm -from .forms import RegistrationEditForm -from .forms import RegistrationAdminSelectForm -from .forms import WifiForm -from .utils import send_confirmation - -from .forms import IC - -REG_TOTAL = 1000 - -@login_required -def download_csv(request, - template_name = 'registration/download-csv.html'): - """ - """ - if not request.user.is_staff: - redirect_to = reverse('kiwipycon_login') - if request.method == "POST": - form = RegistrationAdminSelectForm(request.POST) - if form.is_valid(): - conference = form.cleaned_data['by_conference'] - tutorial = form.cleaned_data['by_tutorial'] - sprint = form.cleaned_data['by_sprint'] - amount = form.cleaned_data['by_amount'] - tshirt = form.cleaned_data['by_tshirt'] - order_by = form.cleaned_data['order_by'] - include = form.cleaned_data['include'] - q = Registration.objects.all() - if conference == 'conference': - q = q.filter(conference=True) - elif conference == 'no conference': - q = q.filter(conference=False) - elif tutorial == 'tutorial': - q = q.filter(tutorial=True) - elif tutorial == 'no tutorial': - q = q.filter(tutorial=False) - if sprint == 'sprint': - q = q.filter(sprint=True) - if sprint == 'no sprint': - q = q.filter(sprint=False) - elif tshirt != 'all': - q = q.filter(tshirt=tshirt) - q = q.order_by('registrant__email') - query = q.query - results = list(q) - if include == []: - # default to include all fields - include = [i[0] for i in IC] - if results: - response = HttpResponse(mimetype='text/csv') - response['Content-Disposition'] = 'attachment; filename=registrations.csv' - output = csv.writer(response) - output.writerow([h for h in include]) - for row in results: - conference = row.conference == True and 'yes' or 'no' - tutorial = row.tutorial == True and 'yes' or 'no' - sprint = row.sprint == True and 'yes' or 'no' - wrow = [] - if 'Name' in include: - wrow.append( - row.registrant.get_full_name().encode('utf-8')) - if 'Email' in include: - wrow.append(row.registrant.email.encode('utf-8')) - if 'Organisation' in include: - wrow.append(row.organisation.encode('utf-8')) - if 'Conference' in include: - wrow.append(conference) - if 'Tutorial' in include: - wrow.append(tutorial) - if 'Sprint' in include: - wrow.append(sprint) - if 'T-size' in include: - wrow.append(row.tshirt) - output.writerow(wrow) - return response - else: - no_results = u'No results found for the query' - - else: - form = RegistrationAdminSelectForm() - return render_to_response(template_name, RequestContext(request, - locals())) - -# NOT REQUIRED FOR SciPy.in -@login_required -def invoice(request, template_name='registration/invoice.html'): - user = request.user - registration = get_object_or_404(Registration, registrant=user) - if registration.sponsor: - redirect_to = reverse('kiwipycon_account') - return set_message_cookie(redirect_to, - msg = u'You are a sponsored guest, no payment required.') - return render_to_response(template_name, RequestContext(request, - {'registration' : registration, 'user': user})) - -@login_required -def pdf_invoice(request, template_name='registration/invoice.html'): - user = request.user - registration = get_object_or_404(Registration, registrant=user) - if registration.sponsor: - redirect_to = reverse('kiwipycon_account') - return set_message_cookie(redirect_to, - msg = u'You are a sponsored guest, no payment required.') - content = render_to_string(template_name, - {'registration' : registration, 'user': user}) - result = StringIO.StringIO() - import ho.pisa - pdf = ho.pisa.pisaDocument(StringIO.StringIO(content.encode("UTF-8")),result) - if not pdf.err: - return HttpResponse(result.getvalue(), mimetype='application/pdf') - return HttpResponse("Gremlins ate your invoice, please try html" \ - " version") - - -def registrations(request, - template_name='registration/registrations.html'): - """Simple page to count registrations""" - #registrations = Registration.objects.filter(payment=True).count() - registrations = Registration.objects.all().count() - return render_to_response(template_name, RequestContext(request, - { - 'over_reg' : registrations >= REG_TOTAL and True or False, - 'registrations' : registrations})) - -@login_required -def edit_registration(request, id, - template_name='registration/edit-registration.html'): - '''Allows users that submitted a registration to edit it. - ''' - reg = Registration.objects.get(pk=id) - - if reg.registrant != request.user: - redirect_to = reverse('kiwipycon_account') - return set_message_cookie(redirect_to, - msg = u'Redirected because the registration you selected' \ - + ' is not your own.') - - if request.method == 'POST': - form = RegistrationEditForm(data=request.POST) - if form.is_valid(): - reg.organisation = form.data.get('organisation') - reg.occupation = form.data.get('occupation') - reg.city = form.data.get('city') - reg.tshirt = form.data.get('tshirt') - reg.allow_contact = form.data.get('allow_contact') and True or False - reg.conference = form.data.get('conference') and True or False - reg.tutorial = form.data.get('tutorial') and True or False - reg.sprint = form.data.get('sprint') and True or False - reg.save() - # Saved.. redirect - redirect_to = reverse('kiwipycon_account') - return set_message_cookie(redirect_to, - msg = u'Your changes have been saved.') - else: - form = RegistrationEditForm(initial={ - 'id' : id, - 'organisation' : reg.organisation, - 'occupation' : reg.occupation, - 'city' : reg.city, - 'tshirt' : reg.tshirt, - 'conference': reg.conference, - 'tutorial': reg.tutorial, - 'postcode' : reg.postcode, - 'sprint' : reg.sprint, - 'allow_contact' : reg.allow_contact, - }) - - return render_to_response(template_name, RequestContext(request, locals())) - -def submit_registration(request, - template_name='registration/submit-registration.html'): - '''Allows user to edit registration - ''' - user = request.user - reg_count = Registration.objects.all().count() - if user.is_authenticated(): - try: - profile = user.get_profile() - except: - profile, new = UserProfile.objects.get_or_create(user=user) - if new: - profile.save() - try: - registration = Registration.objects.get(registrant=user) - if registration: - redirect_to = reverse('kiwipycon_account') - return set_message_cookie(redirect_to, - msg = u'You have already been registered.') - - except ObjectDoesNotExist: - pass - - message = None - - if request.method == 'POST': - registration_form = RegistrationSubmitForm(data=request.POST) - registrant_form = RegistrantForm(data=request.POST) - wifi_form = WifiForm(data=request.POST) - - if request.POST.get('action', None) == 'login': - login_form = AuthenticationForm(data=request.POST) - if login_form.is_valid(): - - from django.contrib.auth import login - login(request, login_form.get_user()) - - redirect_to = reverse('kiwipycon_submit_registration') - return set_message_cookie(redirect_to, - msg = u'You have been logged in please continue' + \ - 'with registration.') - - newuser = None - passwd = None - if not user.is_authenticated(): - if registrant_form.is_valid(): - newuser = kiwipycon_createregistrant(request, registrant_form.data) - # Log in user - passwd = User.objects.make_random_password() - newuser.set_password(passwd) - newuser.save() - from django.contrib.auth import authenticate - user = authenticate(username=newuser.username, password=passwd) - - from django.contrib.auth import login - login(request, user) - - newuser = user - - else: - newuser = user - - if registration_form.is_valid() and newuser: - allow_contact = registration_form.data.get('allow_contact') and \ - True or False - conference = registration_form.data.get('conference') and \ - True or False - tutorial = registration_form.data.get('tutorial') and \ - True or False - sprint = registration_form.data.get('sprint') and \ - True or False - - registrant = User.objects.get(pk=newuser.id) - - presenter = None - talks = Talk.objects.filter( - speaker=registrant).filter(approved=True) - if talks: - for talk in talks: - if talk.duration == '30': - presenter = True - elif talk.duration == '60': - presenter = True - - reg = Registration( - # slug = newuser.username, - registrant = registrant, - organisation = registration_form.data.get('organisation'), - occupation = registration_form.data.get('occupation'), - city = registration_form.data.get('city'), - tshirt = registration_form.data.get('tshirt'), - postcode = registration_form.cleaned_data.get('postcode'), - allow_contact = allow_contact, - conference = conference, - tutorial = tutorial, - sprint = sprint) - reg.save() - - # get id and use as slug and invoice number - id = reg.id - slug = 'KPC09%03d' % id - reg.slug = slug - reg.save() - - # additional tasks: - if wifi_form.is_valid(): - wifi = wifi_form.save(registrant) - - # 1. include random password if we are a new user - if passwd: - send_confirmation(registrant, slug, password=passwd) - else: - # 2. send user email with registration id - send_confirmation(registrant, slug) - - redirect_to = reverse('kiwipycon_registrations') - return set_message_cookie(redirect_to, - msg = u'Thank you, your registration has been submitted '\ - 'and an email has been sent with payment details.') - - else: - registration_form = RegistrationSubmitForm() - registrant_form = RegistrantForm() - wifi_form = WifiForm() - - login_form = AuthenticationForm() - - - return render_to_response(template_name, RequestContext(request, { - 'registration_form': registration_form, - 'registrant_form' : registrant_form, - 'over_reg' : reg_count >= REG_TOTAL and True or False, - 'wifi_form' : wifi_form, - 'message' : message, - 'login_form' : login_form - })) |