summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorPepper <pepper@scannerjammer.com>2015-05-28 14:23:46 -0400
committerPepper <pepper@scannerjammer.com>2015-05-28 14:23:46 -0400
commit4a4a32e1f979282c1b93a43b0dd10f89a0d2d590 (patch)
tree05aa36967a0be9f92030606c538393c52c0f5fa7 /backend
parenta4916103efb2d97896c456ff0e83064b21e85d25 (diff)
fixed email in profiles
Diffstat (limited to 'backend')
-rwxr-xr-xbackend/urls.py3
-rwxr-xr-xbackend/views.py110
2 files changed, 37 insertions, 76 deletions
diff --git a/backend/urls.py b/backend/urls.py
index a7f884b..44524a4 100755
--- a/backend/urls.py
+++ b/backend/urls.py
@@ -1,6 +1,5 @@
from django.conf.urls import patterns, include, url
-
urlpatterns = patterns('backend.views',
# AUTH API
url(r'^auth/login/$' , 'api_auth_login' ),
@@ -14,7 +13,7 @@ urlpatterns = patterns('backend.views',
url(r'^user/videos/$' , 'api_user_videos' ),
url(r'^user/likes/$' , 'api_user_likes' ),
url(r'^user/top/$' , 'api_user_top' ),
- url(r'^user/settings/$' , 'api_user_settings' ),
+ url(r'^user/settings/$' , 'api_user_settings' ),
# ROOM API
url(r'^room/watch/$' , 'api_room_watch' ),
url(r'^room/list/$' , 'api_room_list' ),
diff --git a/backend/views.py b/backend/views.py
index acb0369..5e24078 100755
--- a/backend/views.py
+++ b/backend/views.py
@@ -31,6 +31,9 @@ from backend.models import SJSearch
from backend.models import SJUserProfile
from browser import Browser
+
+from haystack.query import SearchQuerySet
+from haystack.inputs import AutoQuery, Exact, Clean
API_HEADER = '#@scanjam 0.3b\n'
@@ -80,10 +83,6 @@ def title_from_url (url):
def headers(response):
""" Setup additional headers for response
"""
- response['Access-Control-Allow-Origin'] = '*'
- response['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
- response['Access-Control-Allow-Headers'] = 'x-requested-with'
- response['Access-Control-Max-Age'] = '3628800'
response['Content-type'] = 'text/plain; charset=UTF-8'
def response_error(error, response=None):
@@ -384,6 +383,9 @@ def api_auth_login(request):
return response
user = auth.authenticate(username=request.POST['username'],
password=request.POST['password'])
+#any idea? well for login to work i think ajax should send cookies, but i don't see any django cookies there
+ if not user:
+ return response_error('NO USER')
if user:
if user.is_active:
auth.login(request, user)
@@ -478,9 +480,12 @@ def api_auth_available(request):
@require_POST
def api_auth_checkin(request):
""" Check in user. Private API
+ so we need to figure out what it SHOULD return, right? yeah
+
"""
if request.user.is_authenticated():
response = response_success()
+
response.write(user_response_str(request))
return response
return HttpResponse()
@@ -546,6 +551,7 @@ def api_user_videos(request):
v.user.username,
s['url'],
s['title'],
+ ("%d" % v.sjlike_set.count())
])
response.write(l + '\n')
return response
@@ -600,7 +606,7 @@ def api_user_settings(request):
if not user.is_authenticated():
return response_error('NO LOGGED IN')
user_profile = user.get_profile()
- form_fields = ['userid', 'bio', 'settings']
+ form_fields = ['userid', 'bio', 'settings', 'email']
response = check_form_fields(request, form_fields)
if response:
return response
@@ -608,6 +614,12 @@ def api_user_settings(request):
return response_error('YOU CAN ONLY EDIT YOURSELF MAN')
settings = user_profile.settings
settings.update(thraw(request.POST['settings']))
+ user.email = request.POST['email']
+ user.save()
+ # i guess somehting like this ok whew well now the template? yep #weird looks like edit is gone? here you CAN
+ #log in as me pepper.scannerjammer.Common
+ #user: pepper
+ #pw: amnesia yeah i'm there can't find it I see it in the source...we should try to grep for it, right? yes
user_profile.settings = settings
user_profile.save()
return response_success()
@@ -1049,84 +1061,34 @@ def api_video_remove(request):
def api_video_search(request):
""" Search video view. Private API
"""
+
user = request.user
if not user.is_authenticated():
- return response_error('NO LOGGED IN')
+ return response_error('NOT LOGGED IN')
user_profile = user.get_profile()
form_fields = ['q']
response = check_form_fields(request, form_fields)
if response:
return response
- start = 0
- if 'start' in request.POST and is_number(request.POST['start']):
- start = int(request.POST['start'])
- limit = 10
- if 'limit' in request.POST and is_number(request.POST['limit']):
- limit = int(request.POST['limit'])
- if limit > 100:
- limit = 100
- recenttime = datetime.fromtimestamp(time.time() - 60*60*24*30*3)
-
- videos = SJContent.objects.filter(content_type='video', datetime__gt=recenttime)
- words = {}
- videos_by_url = {}
- videos_by_id = {}
- for video in videos:
- settings = video.settings
- url = settings.get('url', '')
- likes = SJLike.objects.filter(content=video).count()
- username = video.user.username
- if url in videos_by_url:
- videos_by_url[url]['score'] += likes
- if username not in videos_by_url[url]['users']:
- videos_by_url[url]['users'].append(username)
- continue
- settings['id'] = video.id
- settings['users'] = [username]
- settings['score'] = likes
- if 'thumbnail' not in settings:
- settings['thumbnail'] = ''
- videos_by_url[url] = settings
- videos_by_id[video.id] = settings
- terms = re.split(r'\W+', settings['title'])
- terms.extend(settings['users'])
- for term in terms:
- term = term.lower()
- if len(term) >= 2:
- if term not in words:
- words[term] = []
- words[term].append(settings['id'])
- terms = re.split(r'\W+', request.POST['q'].lower())
- match = {}
- for term in terms:
- if term in words:
- for videoid in words[term]:
- if videoid not in match:
- match[videoid] = 1
- else:
- match[videoid] += 1
- results = []
- count = 0
- for videoid in sorted(sorted(match, key=lambda x: videos_by_id[x]['score'], reverse=True), key=lambda x: match[x], reverse=True):
- count += 1
- if count > limit:
- break
- if count < start:
- continue
- settings = videos_by_id[videoid]
- results.append(settings)
- response = response_success(message='')
- for result in results:
+
+ videos = SearchQuerySet().filter(content=request.POST['q']).load_all()
+ for searchresult in videos.all():
+ v = searchresult.object
+ if v.content_type != "video":
+ continue
+ posted_by = SearchQuerySet().filter(content=Exact(v.settings['url'])).count()
response.write('%s\n' % (
- '\t'.join([str(result['id']),
- str(result['score']),
- result['users'][0],
- str(len(result['users'])),
- result['title'],
- result['url'],
- result['thumbnail']])
+ '\t'.join([
+ str(v.id),
+ str(v.sjlike_set.count()),
+ v.user.username,
+ str(posted_by),
+ v.settings['title'],
+ v.settings['url'],
+ v.settings['thumbnail']])
))
- count = len(match)
+ return response
+ count = videos.count()
if start == 0:
search = SJSearch(user=user, datetime=datetime.now())
settings = {