Commits

The Dod committed 3cb1390 Draft

"Self awareness"

* User can view self's profile even if not public
* If self's profile not found, details redirect to create (not 404)
* Add view (and url) that redirects to self's profile details
(handy as settings.LOGIN_REDIRECT_URL)

Comments (0)

Files changed (3)

profiles/.gitignore

+*.pyc
                        url(r'^edit/$',
                            views.edit_profile,
                            name='profiles_edit_profile'),
+                       url(r'^me/$',
+                           views.self_detail,
+                           name='profiles_self_detail'),
+                       #Use something like url(r'^u/(?P<username>\w+)/$',
+                       #to allow users like 'me' or 'edit' :)
                        url(r'^(?P<username>\w+)/$',
                            views.profile_detail,
                            name='profiles_profile_detail'),

profiles/views.py

     try:
         profile_obj = user.get_profile()
     except ObjectDoesNotExist:
+        if user == request.user:
+            return HttpResponseRedirect(reverse('profiles_create_profile'))
         raise Http404
-    if public_profile_field is not None and \
+    if user != request.user and \
+       public_profile_field is not None and \
        not getattr(profile_obj, public_profile_field):
         profile_obj = None
     
                               { 'profile': profile_obj },
                               context_instance=context)
 
+def self_detail(request):
+    return HttpResponseRedirect(reverse('profiles_profile_detail',
+        kwargs={ 'username': request.user.username }))
+
 def profile_list(request, public_profile_field=None,
                  template_name='profiles/profile_list.html', **kwargs):
     """