Skip to content

Commit

Permalink
#209 new user view
Browse files Browse the repository at this point in the history
  • Loading branch information
tonylampada committed Aug 29, 2014
1 parent 7ec182a commit 3c89562
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
5 changes: 3 additions & 2 deletions djangoproject/core/urls/user_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

urlpatterns = patterns('core.views.user_views',
url(r'^$', 'listUsers'),
url(r'^(?P<user_id>\d+)/$', 'viewUser'),
url(r'^(?P<user_id>\d+)/(?P<user_slug>.*)$', 'viewUser'),
url(r'^(?P<user_id>\d+)/$', 'viewUserById'),
url(r'^(?P<user_id>\d+)/(?P<user_slug>.*)$', 'viewUserById'),
url(r'^(?P<username>\w+)/$', 'viewUserByUsername'),
url(r'^edit$', 'editUserForm'),
url(r'^edit/submit$', 'editUser'),
url(r'^cancel_account$', 'cancel_account'),
Expand Down
26 changes: 18 additions & 8 deletions djangoproject/core/views/user_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@
from django.conf import settings


def viewUserById(request, user_id, user_slug=None):
try:
user = User.objects.get(pk=user_id)
except:
return HttpResponse(status=404, content='User not found')

def _view_user(request, user):
if not user.is_active and not request.user.is_superuser:
return render_to_response(
'core2/user_inactive.html',
{'le_user': user},
context_instance=RequestContext(request)
)

unconnectedSocialAccounts = None
if user.id == request.user.id:
unconnectedSocialAccounts = user.getUnconnectedSocialAccounts()
Expand All @@ -34,7 +28,6 @@ def viewUserById(request, user_id, user_slug=None):
)
for alert in alert_strings:
messages.info(request, alert)

context = {
'le_user': user,
'stats': user.getStats(),
Expand All @@ -46,6 +39,23 @@ def viewUserById(request, user_id, user_slug=None):
context_instance=RequestContext(request)
)


def viewUserById(request, user_id, user_slug=None):
try:
user = User.objects.get(pk=user_id)
except:
return HttpResponse(status=404, content='User not found')

return _view_user(request, user)

def viewUserByUsername(request, username):
try:
user = User.objects.get(username=username)
except:
return HttpResponse(status=404, content='User not found')

return _view_user(request, user)

@login_required
def editUserForm(request):
userinfo = request.user.getUserInfo()
Expand Down

0 comments on commit 3c89562

Please sign in to comment.