From 6e7e656d0fc14e41fe106c5a97e9d8a8392b3e5c Mon Sep 17 00:00:00 2001 From: root Date: Wed, 12 Dec 2012 12:20:16 -0500 Subject: Profile handler --- backend/views.py | 1 + frontend/templates/profile.html | 155 ++++++++++++++++++++++++++++++++++++++++ frontend/views.py | 59 ++++++++++++++- scannerjammer/urls.py | 1 + 4 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 frontend/templates/profile.html diff --git a/backend/views.py b/backend/views.py index 992b273..26c5c88 100644 --- a/backend/views.py +++ b/backend/views.py @@ -164,6 +164,7 @@ def videos_response_list(videos): v.user.username, s['url'], s['title'], + v.sjlike_set.count() ] retval.append(l) return retval diff --git a/frontend/templates/profile.html b/frontend/templates/profile.html new file mode 100644 index 0000000..c277207 --- /dev/null +++ b/frontend/templates/profile.html @@ -0,0 +1,155 @@ +{% load static %} +{% get_static_prefix as STATIC_PREFIX %} + + + +scanners jammed by {{NAME}} + + + + + + + + + + + + + + + + +
+ +
+ +
+
+
+
+
+
+ +
+ +
+
+ + +
+ +
+ +

+ +
+ +
+ +
+ +
+
EDIT YOUR PROFILE
+
+ Top Videos . + Directory +
+
+ + +
+
+ +
+
X
+
EDITING {{UCNAME}}
+
+ + +
+ + +
+
+ + +
+
+ +
+
+
+
+ +
+
+
+ +
+
+ please enable javascript +
+ +
Hit Escape to exit fullscreen mode
+ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/frontend/views.py b/frontend/views.py index e2354fe..a391c0a 100644 --- a/frontend/views.py +++ b/frontend/views.py @@ -21,7 +21,7 @@ from backend.views import is_image from backend.views import videos_response_list from backend.views import ROOM_VIDEO_LOG_SIZE -from django.db.models import Q +from django.db.models import Q, Count LIMIT = 40 @@ -115,3 +115,60 @@ def directory(request): response['Pragma'] = 'no-cache' return response +def get_thumbnail(user): + STOCK_THUMBNAIL = 'http://scannerjammer.fm/img/runner.gif' + """ + FIXME + if user.access and 'http' in user.access: # what was those fields? + linez = user.access.split("\n") + for l in linez: + if "avatar" in l: + pair = l.split("\t") + if pair[1] is not None and "http" in pair[1]: + if db.is_image(pair[1]): + return pair[1] + if user[8] and 'http' in user[8]: + linez = user[8].split("\n") + for l in linez: + if "http" in l: + wordz = l.split(" ") + for word in wordz: + if "http" in word: + if db.is_image(word): + return word + """ + return STOCK_THUMBNAIL + + +def profile(request, username): + """ Directory view + """ + + userprofile = SJUserProfile.objects.filter(user__username=username)[0]; + thumbnail = get_thumbnail(userprofile) + + topz = SJContent.objects.filter(user__id=userprofile.user.id, content_type='video').annotate(likes=Count('sjlike')).order_by('-likes')[:50] + likez = SJContent.objects.filter(user__id=userprofile.user.id, content_type='video', sjlike__isnull = False ).order_by('-datetime')[:50] + vidz = SJContent.objects.filter(user__id=userprofile.user.id, content_type='video').order_by('-datetime')[:50] + profile = [ userprofile.id, userprofile.nickname, userprofile.score, 3, 4, 5, userprofile.bio, 7 ] + + response = render_to_response( + 'profile.html', + { + 'SERVER_HOST': settings.SERVER_HOST, + 'SERVER_PORT': settings.SERVER_PORT, + 'NAME': userprofile.nickname, + 'UCNAME': userprofile.nickname.upper(), + 'SCORE': userprofile.score, + 'THUMBNAIL': thumbnail, + + 'VIDZ': json.dumps(videos_response_list(vidz)), + 'TOPZ': json.dumps(videos_response_list(topz)), + 'LIKEZ': json.dumps(videos_response_list(likez)), + 'PROFILE': json.dumps(profile), + + 'NOW': str(int(time.time())), + } + ) + response['Pragma'] = 'no-cache' + return response diff --git a/scannerjammer/urls.py b/scannerjammer/urls.py index 5a5f838..e5a23c3 100644 --- a/scannerjammer/urls.py +++ b/scannerjammer/urls.py @@ -23,6 +23,7 @@ urlpatterns = patterns('', url(r'^backgrounds/$', 'frontend.views.bg', name='bg'), url(r'^top/$', 'frontend.views.topvideos', name='topvideos'), url(r'^directory/$', 'frontend.views.directory', name='directory'), + url(r'^profile/(?P[a-z0-9_]+)$', 'frontend.views.profile', name='profile'), #url(r'.*', 'backend.views.redirect'), ) -- cgit v1.2.3-70-g09d2