15 from django.shortcuts import render_to_response |
15 from django.shortcuts import render_to_response |
16 from django.template import RequestContext |
16 from django.template import RequestContext |
17 |
17 |
18 from PIL import Image |
18 from PIL import Image |
19 |
19 |
|
20 from project.scipycon.base.models import Event |
20 from project.scipycon.registration.models import Registration |
21 from project.scipycon.registration.models import Registration |
21 from project.scipycon.registration.models import Wifi |
22 from project.scipycon.registration.models import Wifi |
22 from project.scipycon.registration.forms import WifiForm |
23 from project.scipycon.registration.forms import WifiForm |
23 from project.scipycon.talk.models import Talk |
24 from project.scipycon.talk.models import Talk |
24 from project.scipycon.user.forms import EditProfileForm |
25 from project.scipycon.user.forms import EditProfileForm |
36 |
37 |
37 user = request.user |
38 user = request.user |
38 profile = user.get_profile() |
39 profile = user.get_profile() |
39 |
40 |
40 talks = Talk.objects.filter(speaker=user) |
41 talks = Talk.objects.filter(speaker=user) |
|
42 |
41 try: |
43 try: |
42 registration = Registration.objects.get(registrant=user) |
44 registration = Registration.objects.get(registrant=user) |
43 except ObjectDoesNotExist: |
45 except ObjectDoesNotExist: |
44 registration = None |
46 registration = None |
|
47 |
45 try: |
48 try: |
46 wifiobj = Wifi.objects.get(user=user) |
49 wifiobj = Wifi.objects.get(user=user) |
47 except ObjectDoesNotExist: |
50 except ObjectDoesNotExist: |
48 wifiobj = None |
51 wifiobj = None |
49 |
52 |
|
53 event = Event.objects.get(scope=scope) |
|
54 |
50 if profile.photo: |
55 if profile.photo: |
51 photo = os.path.join(settings.USER_MEDIA_URL, profile.photo) |
56 photo = os.path.join(settings.USER_MEDIA_URL, profile.photo) |
52 else: |
57 else: |
53 photo = '/img/user-default.png' |
58 photo = '/img/user-default.png' |
54 |
59 |
55 wifi_comment = None |
60 return render_to_response(template_name, RequestContext(request, { |
56 if wifiobj: |
61 'params': {'scope': scope}, |
57 wifi_form = False |
62 'user' : user, |
58 else: |
63 'profile' : profile, |
59 if request.method == "POST": |
64 'photo' : photo, |
60 wifi_form = WifiForm(request.POST) |
65 'talks' : talks, |
61 if wifi_form.is_valid(): |
66 'registration' : registration, |
62 wifi_form.save(user) |
67 'event': event})) |
63 wifi_comment = 'Thanks, your wifi preference has been saved' |
|
64 wifi_form = None |
|
65 else: |
|
66 wifi_form = WifiForm() |
|
67 |
|
68 return render_to_response(template_name, RequestContext(request, { |
|
69 'params': {'scope': scope}, |
|
70 'form' : wifi_form, 'comment': wifi_comment, |
|
71 'user' : user, 'profile' : profile, 'photo' : photo, |
|
72 'talks' : talks, 'registration' : registration, |
|
73 })) |
|
74 |
68 |
75 @login_required |
69 @login_required |
76 def edit_profile(request, scope, template_name="user/editprofile.html"): |
70 def edit_profile(request, scope, template_name="user/editprofile.html"): |
77 """Allows user to edit profile |
71 """Allows user to edit profile |
78 """ |
72 """ |