Mercurial > public > sg101
comparison gpp/bio/views.py @ 471:d83296cac940
For #227: only enqueue user profiles if the user has changed the content we have in the search index.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 17 Aug 2011 02:02:20 +0000 |
parents | 000c006fee97 |
children | 98b373ca09f3 |
comparison
equal
deleted
inserted
replaced
470:d9b6c4ec1977 | 471:d83296cac940 |
---|---|
1 """ | 1 """ |
2 Views for the bio application. | 2 Views for the bio application. |
3 | |
3 """ | 4 """ |
4 | |
5 from django.shortcuts import render_to_response | 5 from django.shortcuts import render_to_response |
6 from django.shortcuts import get_object_or_404 | 6 from django.shortcuts import get_object_or_404 |
7 from django.template import RequestContext | 7 from django.template import RequestContext |
8 from django.contrib import messages | 8 from django.contrib import messages |
9 from django.contrib.auth.models import User | 9 from django.contrib.auth.models import User |
25 from bio.models import BadgeOwnership | 25 from bio.models import BadgeOwnership |
26 from bio.forms import UploadAvatarForm | 26 from bio.forms import UploadAvatarForm |
27 from bio.forms import EditUserForm | 27 from bio.forms import EditUserForm |
28 from bio.forms import EditUserProfileForm | 28 from bio.forms import EditUserProfileForm |
29 from bio.forms import SearchUsersForm | 29 from bio.forms import SearchUsersForm |
30 from bio.signals import notify_profile_content_update | |
30 from core.paginator import DiggPaginator | 31 from core.paginator import DiggPaginator |
31 from core.functions import email_admins | 32 from core.functions import email_admins |
32 from core.functions import get_page | 33 from core.functions import get_page |
33 | 34 |
34 ####################################################################### | 35 ####################################################################### |
76 profile = request.user.get_profile() | 77 profile = request.user.get_profile() |
77 badge_collection = BadgeOwnership.objects.filter( | 78 badge_collection = BadgeOwnership.objects.filter( |
78 profile=profile).select_related("badge") | 79 profile=profile).select_related("badge") |
79 | 80 |
80 return render_to_response('bio/view_profile.html', { | 81 return render_to_response('bio/view_profile.html', { |
81 'subject': request.user, | 82 'subject': request.user, |
82 'profile': profile, | 83 'profile': profile, |
83 'hide_email': False, | 84 'hide_email': False, |
84 'this_is_me': True, | 85 'this_is_me': True, |
85 'badge_collection': badge_collection, | 86 'badge_collection': badge_collection, |
86 }, | 87 }, |
87 context_instance = RequestContext(request)) | 88 context_instance = RequestContext(request)) |
88 | 89 |
89 ####################################################################### | 90 ####################################################################### |
90 | 91 |
91 @login_required | 92 @login_required |
98 profile = user.get_profile() | 99 profile = user.get_profile() |
99 hide_email = profile.hide_email | 100 hide_email = profile.hide_email |
100 | 101 |
101 badge_collection = BadgeOwnership.objects.filter( | 102 badge_collection = BadgeOwnership.objects.filter( |
102 profile=profile).select_related("badge") | 103 profile=profile).select_related("badge") |
103 | 104 |
104 return render_to_response('bio/view_profile.html', { | 105 return render_to_response('bio/view_profile.html', { |
105 'subject': user, | 106 'subject': user, |
106 'profile': profile, | 107 'profile': profile, |
107 'hide_email': hide_email, | 108 'hide_email': hide_email, |
108 'this_is_me': False, | 109 'this_is_me': False, |
109 'badge_collection': badge_collection, | 110 'badge_collection': badge_collection, |
110 }, | 111 }, |
111 context_instance = RequestContext(request)) | 112 context_instance = RequestContext(request)) |
112 | 113 |
113 ####################################################################### | 114 ####################################################################### |
114 | 115 |
115 @login_required | 116 @login_required |
123 if user_form.is_valid() and profile_form.is_valid(): | 124 if user_form.is_valid() and profile_form.is_valid(): |
124 user_form.save() | 125 user_form.save() |
125 profile = profile_form.save(commit=False) | 126 profile = profile_form.save(commit=False) |
126 profile.user = request.user | 127 profile.user = request.user |
127 profile.save() | 128 profile.save() |
129 notify_profile_content_update(profile) | |
128 return HttpResponseRedirect(reverse('bio.views.my_profile')) | 130 return HttpResponseRedirect(reverse('bio.views.my_profile')) |
129 else: | 131 else: |
130 profile = request.user.get_profile() | 132 profile = request.user.get_profile() |
131 user_form = EditUserForm(instance=request.user) | 133 user_form = EditUserForm(instance=request.user) |
132 profile_form = EditUserProfileForm(instance=profile) | 134 profile_form = EditUserProfileForm(instance=profile) |
133 | 135 |
134 return render_to_response('bio/edit_profile.html', { | 136 return render_to_response('bio/edit_profile.html', { |
135 'user_form': user_form, | 137 'user_form': user_form, |
136 'profile_form': profile_form, | 138 'profile_form': profile_form, |
137 }, | 139 }, |
138 context_instance = RequestContext(request)) | 140 context_instance = RequestContext(request)) |
139 | 141 |
140 ####################################################################### | 142 ####################################################################### |
141 | 143 |
142 @login_required | 144 @login_required |
166 else: | 168 else: |
167 form = UploadAvatarForm() | 169 form = UploadAvatarForm() |
168 | 170 |
169 return render_to_response('bio/avatar.html', { | 171 return render_to_response('bio/avatar.html', { |
170 'form': form, | 172 'form': form, |
171 }, | 173 }, |
172 context_instance = RequestContext(request)) | 174 context_instance = RequestContext(request)) |
173 | 175 |
174 ####################################################################### | 176 ####################################################################### |
175 | 177 |
176 @require_POST | 178 @require_POST |
226 | 228 |
227 if form.is_valid(): | 229 if form.is_valid(): |
228 profile = form.save(commit=False) | 230 profile = form.save(commit=False) |
229 profile.user = request.user | 231 profile.user = request.user |
230 profile.save() | 232 profile.save() |
233 notify_profile_content_update(request.user.get_profile()) | |
231 return HttpResponseRedirect(request.path) | 234 return HttpResponseRedirect(request.path) |
232 | 235 |
233 # Delete forms | 236 # Delete forms |
234 elif new_data.get('delete-sn-form') or new_data.get('delete-im-form') or new_data.get('delete-w-form'): | 237 elif new_data.get('delete-sn-form') or new_data.get('delete-im-form') or new_data.get('delete-w-form'): |
235 delete_id = request.POST['delete_id'] | 238 delete_id = request.POST['delete_id'] |
236 | 239 |
240 update_occurred = True | |
237 if new_data.get('delete-sn-form'): | 241 if new_data.get('delete-sn-form'): |
238 request.user.social_network_profiles.get(id=delete_id).delete() | 242 request.user.social_network_profiles.get(id=delete_id).delete() |
239 elif new_data.get('delete-im-form'): | 243 elif new_data.get('delete-im-form'): |
240 request.user.instant_messenger_profiles.get(id=delete_id).delete() | 244 request.user.instant_messenger_profiles.get(id=delete_id).delete() |
241 elif new_data.get('delete-w-form'): | 245 elif new_data.get('delete-w-form'): |
242 request.user.website_profiles.get(id=delete_id).delete() | 246 request.user.website_profiles.get(id=delete_id).delete() |
247 else: | |
248 update_occurred = False | |
249 | |
250 if update_occurred: | |
251 notify_profile_content_update(request.user.get_profile()) | |
243 | 252 |
244 return HttpResponseRedirect(request.path) | 253 return HttpResponseRedirect(request.path) |
245 | 254 |
246 # WTF? | 255 # WTF? |
247 else: | 256 else: |
252 sn_form = SocialNetworkForm() | 261 sn_form = SocialNetworkForm() |
253 im_form = InstantMessengerForm(auto_id=im_id) | 262 im_form = InstantMessengerForm(auto_id=im_id) |
254 w_form = WebsiteForm() | 263 w_form = WebsiteForm() |
255 | 264 |
256 return render_to_response('bio/edit_elsewhere.html', { | 265 return render_to_response('bio/edit_elsewhere.html', { |
257 'sn_form': sn_form, | 266 'sn_form': sn_form, |
258 'im_form': im_form, | 267 'im_form': im_form, |
259 'w_form': w_form, | 268 'w_form': w_form, |
260 }, | 269 }, |
261 context_instance=RequestContext(request)) | 270 context_instance=RequestContext(request)) |
262 | 271 |
263 ####################################################################### | 272 ####################################################################### |
264 | 273 |
265 @login_required | 274 @login_required |
266 def member_search(request): | 275 def member_search(request): |
267 if request.method == "POST": | 276 if request.method == "POST": |
268 form = SearchUsersForm(request.POST) | 277 form = SearchUsersForm(request.POST) |
269 if form.is_valid(): | 278 if form.is_valid(): |
270 username = form.cleaned_data['username'] | 279 username = form.cleaned_data['username'] |
271 return HttpResponseRedirect(reverse("bio-view_profile", | 280 return HttpResponseRedirect(reverse("bio-view_profile", |
272 kwargs={'username': username})) | 281 kwargs={'username': username})) |
273 else: | 282 else: |
274 form = SearchUsersForm() | 283 form = SearchUsersForm() |
275 | 284 |
276 return render_to_response('bio/member_search.html', { | 285 return render_to_response('bio/member_search.html', { |
277 'form': form, | 286 'form': form, |
278 }, | 287 }, |
279 context_instance=RequestContext(request)) | 288 context_instance=RequestContext(request)) |
280 | 289 |