16 from django.contrib.auth.decorators import login_required |
16 from django.contrib.auth.decorators import login_required |
17 from django.contrib.auth.forms import AuthenticationForm |
17 from django.contrib.auth.forms import AuthenticationForm |
18 from django.contrib.auth.models import User |
18 from django.contrib.auth.models import User |
19 from django.core.exceptions import ObjectDoesNotExist |
19 from django.core.exceptions import ObjectDoesNotExist |
20 |
20 |
21 #kiwipycon |
21 from project.scipycon.utils import set_message_cookie |
22 from project.kiwipycon.utils import set_message_cookie |
22 from project.scipycon.utils import slugify |
23 from project.kiwipycon.utils import slugify |
23 from project.scipycon.user.models import UserProfile |
24 from project.kiwipycon.user.models import UserProfile |
24 from project.scipycon.user.utils import scipycon_createregistrant |
25 from project.kiwipycon.user.utils import kiwipycon_createregistrant |
25 from project.scipycon.user.forms import RegistrantForm |
26 from project.kiwipycon.user.forms import RegistrantForm |
26 from project.scipycon.talk.models import Talk |
27 from project.kiwipycon.sponsor.models import Sponsor |
|
28 from project.kiwipycon.talk.models import Talk |
|
29 |
27 |
30 from .models import Registration |
28 from .models import Registration |
31 from .models import Wifi |
29 from .models import Wifi |
32 from .forms import RegistrationSubmitForm |
30 from .forms import RegistrationSubmitForm |
33 from .forms import RegistrationEditForm |
31 from .forms import RegistrationEditForm |
43 def download_csv(request, |
41 def download_csv(request, |
44 template_name = 'registration/download-csv.html'): |
42 template_name = 'registration/download-csv.html'): |
45 """ |
43 """ |
46 """ |
44 """ |
47 if not request.user.is_staff: |
45 if not request.user.is_staff: |
48 redirect_to = reverse('kiwipycon_login') |
46 redirect_to = reverse('scipycon_login') |
49 if request.method == "POST": |
47 if request.method == "POST": |
50 form = RegistrationAdminSelectForm(request.POST) |
48 form = RegistrationAdminSelectForm(request.POST) |
51 if form.is_valid(): |
49 if form.is_valid(): |
52 conference = form.cleaned_data['by_conference'] |
50 conference = form.cleaned_data['by_conference'] |
53 tutorial = form.cleaned_data['by_tutorial'] |
51 tutorial = form.cleaned_data['by_tutorial'] |
116 @login_required |
114 @login_required |
117 def invoice(request, template_name='registration/invoice.html'): |
115 def invoice(request, template_name='registration/invoice.html'): |
118 user = request.user |
116 user = request.user |
119 registration = get_object_or_404(Registration, registrant=user) |
117 registration = get_object_or_404(Registration, registrant=user) |
120 if registration.sponsor: |
118 if registration.sponsor: |
121 redirect_to = reverse('kiwipycon_account') |
119 redirect_to = reverse('scipycon_account') |
122 return set_message_cookie(redirect_to, |
120 return set_message_cookie(redirect_to, |
123 msg = u'You are a sponsored guest, no payment required.') |
121 msg = u'You are a sponsored guest, no payment required.') |
124 return render_to_response(template_name, RequestContext(request, |
122 return render_to_response(template_name, RequestContext(request, |
125 {'registration' : registration, 'user': user})) |
123 {'registration' : registration, 'user': user})) |
126 |
124 |
127 @login_required |
125 @login_required |
128 def pdf_invoice(request, template_name='registration/invoice.html'): |
126 def pdf_invoice(request, template_name='registration/invoice.html'): |
129 user = request.user |
127 user = request.user |
130 registration = get_object_or_404(Registration, registrant=user) |
128 registration = get_object_or_404(Registration, registrant=user) |
131 if registration.sponsor: |
129 if registration.sponsor: |
132 redirect_to = reverse('kiwipycon_account') |
130 redirect_to = reverse('scipycon_account') |
133 return set_message_cookie(redirect_to, |
131 return set_message_cookie(redirect_to, |
134 msg = u'You are a sponsored guest, no payment required.') |
132 msg = u'You are a sponsored guest, no payment required.') |
135 content = render_to_string(template_name, |
133 content = render_to_string(template_name, |
136 {'registration' : registration, 'user': user}) |
134 {'registration' : registration, 'user': user}) |
137 result = StringIO.StringIO() |
135 result = StringIO.StringIO() |
159 '''Allows users that submitted a registration to edit it. |
157 '''Allows users that submitted a registration to edit it. |
160 ''' |
158 ''' |
161 reg = Registration.objects.get(pk=id) |
159 reg = Registration.objects.get(pk=id) |
162 |
160 |
163 if reg.registrant != request.user: |
161 if reg.registrant != request.user: |
164 redirect_to = reverse('kiwipycon_account') |
162 redirect_to = reverse('scipycon_account') |
165 return set_message_cookie(redirect_to, |
163 return set_message_cookie(redirect_to, |
166 msg = u'Redirected because the registration you selected' \ |
164 msg = u'Redirected because the registration you selected' \ |
167 + ' is not your own.') |
165 + ' is not your own.') |
168 |
166 |
169 if request.method == 'POST': |
167 if request.method == 'POST': |
177 reg.conference = form.data.get('conference') and True or False |
175 reg.conference = form.data.get('conference') and True or False |
178 reg.tutorial = form.data.get('tutorial') and True or False |
176 reg.tutorial = form.data.get('tutorial') and True or False |
179 reg.sprint = form.data.get('sprint') and True or False |
177 reg.sprint = form.data.get('sprint') and True or False |
180 reg.save() |
178 reg.save() |
181 # Saved.. redirect |
179 # Saved.. redirect |
182 redirect_to = reverse('kiwipycon_account') |
180 redirect_to = reverse('scipycon_account') |
183 return set_message_cookie(redirect_to, |
181 return set_message_cookie(redirect_to, |
184 msg = u'Your changes have been saved.') |
182 msg = u'Your changes have been saved.') |
185 else: |
183 else: |
186 form = RegistrationEditForm(initial={ |
184 form = RegistrationEditForm(initial={ |
187 'id' : id, |
185 'id' : id, |
212 if new: |
210 if new: |
213 profile.save() |
211 profile.save() |
214 try: |
212 try: |
215 registration = Registration.objects.get(registrant=user) |
213 registration = Registration.objects.get(registrant=user) |
216 if registration: |
214 if registration: |
217 redirect_to = reverse('kiwipycon_account') |
215 redirect_to = reverse('scipycon_account') |
218 return set_message_cookie(redirect_to, |
216 return set_message_cookie(redirect_to, |
219 msg = u'You have already been registered.') |
217 msg = u'You have already been registered.') |
220 |
218 |
221 except ObjectDoesNotExist: |
219 except ObjectDoesNotExist: |
222 pass |
220 pass |
233 if login_form.is_valid(): |
231 if login_form.is_valid(): |
234 |
232 |
235 from django.contrib.auth import login |
233 from django.contrib.auth import login |
236 login(request, login_form.get_user()) |
234 login(request, login_form.get_user()) |
237 |
235 |
238 redirect_to = reverse('kiwipycon_submit_registration') |
236 redirect_to = reverse('scipycon_submit_registration') |
239 return set_message_cookie(redirect_to, |
237 return set_message_cookie(redirect_to, |
240 msg = u'You have been logged in please continue' + \ |
238 msg = u'You have been logged in please continue' + \ |
241 'with registration.') |
239 'with registration.') |
242 |
240 |
243 newuser = None |
241 newuser = None |
244 passwd = None |
242 passwd = None |
245 if not user.is_authenticated(): |
243 if not user.is_authenticated(): |
246 if registrant_form.is_valid(): |
244 if registrant_form.is_valid(): |
247 newuser = kiwipycon_createregistrant(request, registrant_form.data) |
245 newuser = scipycon_createregistrant(request, registrant_form.data) |
248 # Log in user |
246 # Log in user |
249 passwd = User.objects.make_random_password() |
247 passwd = User.objects.make_random_password() |
250 newuser.set_password(passwd) |
248 newuser.set_password(passwd) |
251 newuser.save() |
249 newuser.save() |
252 from django.contrib.auth import authenticate |
250 from django.contrib.auth import authenticate |
311 send_confirmation(registrant, slug, password=passwd) |
309 send_confirmation(registrant, slug, password=passwd) |
312 else: |
310 else: |
313 # 2. send user email with registration id |
311 # 2. send user email with registration id |
314 send_confirmation(registrant, slug) |
312 send_confirmation(registrant, slug) |
315 |
313 |
316 redirect_to = reverse('kiwipycon_registrations') |
314 redirect_to = reverse('scipycon_registrations') |
317 return set_message_cookie(redirect_to, |
315 return set_message_cookie(redirect_to, |
318 msg = u'Thank you, your registration has been submitted '\ |
316 msg = u'Thank you, your registration has been submitted '\ |
319 'and an email has been sent with payment details.') |
317 'and an email has been sent with payment details.') |
320 |
318 |
321 else: |
319 else: |