Mercurial > public > sg101
comparison gpp/bio/views.py @ 29:74f04122295e
Initial integration of django-elsewhere.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 03 May 2009 20:14:04 +0000 |
parents | dbd703f7d63a |
children | 08cd19c1ee50 |
comparison
equal
deleted
inserted
replaced
28:04377c5bf912 | 29:74f04122295e |
---|---|
7 from django.template import RequestContext | 7 from django.template import RequestContext |
8 from django.contrib import auth | 8 from django.contrib import auth |
9 from django.http import HttpResponseRedirect | 9 from django.http import HttpResponseRedirect |
10 from django.core.urlresolvers import reverse | 10 from django.core.urlresolvers import reverse |
11 from django.contrib.auth.decorators import login_required | 11 from django.contrib.auth.decorators import login_required |
12 | |
13 from elsewhere.models import SocialNetworkForm | |
14 from elsewhere.models import InstantMessengerForm | |
15 from elsewhere.models import WebsiteForm | |
12 | 16 |
13 from bio.models import UserProfile | 17 from bio.models import UserProfile |
14 from bio.forms import UploadAvatarForm | 18 from bio.forms import UploadAvatarForm |
15 from bio.forms import EditUserForm | 19 from bio.forms import EditUserForm |
16 from bio.forms import EditUserProfileForm | 20 from bio.forms import EditUserProfileForm |
132 return render_to_response('bio/avatar.html', { | 136 return render_to_response('bio/avatar.html', { |
133 'form': form, | 137 'form': form, |
134 }, | 138 }, |
135 context_instance = RequestContext(request)) | 139 context_instance = RequestContext(request)) |
136 | 140 |
137 | 141 ####################################################################### |
138 # vim: ts=4 sw=4 | 142 |
143 @login_required | |
144 def edit_elsewhere(request): | |
145 im_id = 'id_im_%s' # to prevent duplicate ID in HTML output | |
146 if request.method == 'POST': | |
147 new_data = request.POST.copy() | |
148 | |
149 # Add forms | |
150 if new_data.get('sn-form') or new_data.get('im-form') or new_data.get('w-form'): | |
151 | |
152 if new_data.get('sn-form'): | |
153 sn_form = SocialNetworkForm(new_data) | |
154 im_form = InstantMessengerForm(auto_id=im_id) | |
155 w_form = WebsiteForm() | |
156 form = sn_form | |
157 elif new_data.get('im-form'): | |
158 sn_form = SocialNetworkForm() | |
159 im_form = InstantMessengerForm(new_data, auto_id=im_id) | |
160 w_form = WebsiteForm() | |
161 form = im_form | |
162 elif new_data.get('w-form'): | |
163 sn_form = SocialNetworkForm() | |
164 im_form = InstantMessengerForm(auto_id=im_id) | |
165 w_form = WebsiteForm(new_data) | |
166 form = w_form | |
167 | |
168 if form.is_valid(): | |
169 profile = form.save(commit=False) | |
170 profile.user = request.user | |
171 profile.save() | |
172 return HttpResponseRedirect(request.path) | |
173 | |
174 # Delete forms | |
175 elif new_data.get('delete-sn-form') or new_data.get('delete-im-form') or new_data.get('delete-w-form'): | |
176 delete_id = request.POST['delete_id'] | |
177 | |
178 if new_data.get('delete-sn-form'): | |
179 request.user.social_network_profiles.get(id=delete_id).delete() | |
180 elif new_data.get('delete-im-form'): | |
181 request.user.instant_messenger_profiles.get(id=delete_id).delete() | |
182 elif new_data.get('delete-w-form'): | |
183 request.user.website_profiles.get(id=delete_id).delete() | |
184 | |
185 return HttpResponseRedirect(request.path) | |
186 | |
187 # WTF? | |
188 else: | |
189 return HttpResponseServerError | |
190 | |
191 else: | |
192 # Create blank forms | |
193 sn_form = SocialNetworkForm() | |
194 im_form = InstantMessengerForm(auto_id=im_id) | |
195 w_form = WebsiteForm() | |
196 | |
197 return render_to_response('bio/edit_elsewhere.html', { | |
198 'sn_form': sn_form, | |
199 'im_form': im_form, | |
200 'w_form': w_form, | |
201 }, | |
202 context_instance=RequestContext(request)) | |
203 |