From 37e15bcb70369faa19baa543ae9c3d13a6cc3c0e Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 7 Nov 2011 23:13:04 +0100 Subject: [PATCH 1/4] update lastseen manually --- pandora/user/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora/user/models.py b/pandora/user/models.py index 7b580ca1a..b5fcd88d3 100644 --- a/pandora/user/models.py +++ b/pandora/user/models.py @@ -4,7 +4,6 @@ import copy from datetime import datetime from django.contrib.auth.models import User -from django.contrib.sessions.models import Session from django.db import models from django.db.models import Max from django.conf import settings @@ -21,7 +20,7 @@ class SessionData(models.Model): session_key = models.CharField(max_length=40, primary_key=True) user = models.ForeignKey(User, unique=True, null=True, blank=True, related_name='data') firstseen = models.DateTimeField(auto_now_add=True, db_index=True) - lastseen = models.DateTimeField(auto_now=True, db_index=True) + lastseen = models.DateTimeField(default=datetime.now, db_index=True) username = models.CharField(max_length=255, null=True, db_index=True) level = models.IntegerField(default=0) @@ -67,6 +66,7 @@ class SessionData(models.Model): if not data.timesseen: data.timesseen = 0 data.timesseen += 1 + data.lastseen = datetime.now() data.save() return data From 1ded5a0cd478c7b1177dad93149f9892a5dd1a82 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 7 Nov 2011 23:28:28 +0100 Subject: [PATCH 2/4] fix signup --- pandora/user/models.py | 9 +++++++-- pandora/user/views.py | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pandora/user/models.py b/pandora/user/models.py index b5fcd88d3..f89764b0e 100644 --- a/pandora/user/models.py +++ b/pandora/user/models.py @@ -126,9 +126,15 @@ class UserProfile(models.Model): def user_post_save(sender, instance, **kwargs): profile, new = UserProfile.objects.get_or_create(user=instance) - + SessionData.objects.filter(user=instance).update(level=profile.level, + username=instance.username) models.signals.post_save.connect(user_post_save, sender=User) +def profile_post_save(sender, instance, **kwargs): + SessionData.objects.filter(user=instance.user).update(level=instance.level, + username=instance.user.username) +models.signals.post_save.connect(profile_post_save, sender=UserProfile) + def get_ui(user_ui, user=None): ui = {} config = copy.deepcopy(settings.CONFIG) @@ -201,7 +207,6 @@ def init_user(user, request=None): result['volumes'] = [v.json() for v in user.volumes.all()] return result - def user_json(user, keys=None): p = user.get_profile() j = { diff --git a/pandora/user/views.py b/pandora/user/views.py index a560c90a7..57330918a 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -161,7 +161,7 @@ def signup(request): user.save() #create default user lists: for l in settings.CONFIG['personalLists']: - list = models.List(name=l['name'], user=user) + list = models.List(name=l['id'], user=user) for key in ('query', 'public', 'featured'): if key in l: setattr(list, key, l[key]) @@ -170,7 +170,7 @@ def signup(request): user = authenticate(username=data['username'], password=data['password']) login(request, user) - user_json = models.init_user(user) + user_json = models.init_user(user, request) response = json_response({ 'user': user_json }, text='account created') @@ -219,7 +219,7 @@ def resetPassword(request): user = authenticate(username=user.username, password=data['password']) login(request, user) - user_json = models.init_user(user) + user_json = models.init_user(user, request) response = json_response({ 'user': user_json }, text='password reset') From 6aec4ff1b11bf6f6faa3d02d745e44909d673210 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 8 Nov 2011 00:00:08 +0100 Subject: [PATCH 3/4] user positions --- pandora/user/models.py | 5 ++++- pandora/user/views.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pandora/user/models.py b/pandora/user/models.py index f89764b0e..903710580 100644 --- a/pandora/user/models.py +++ b/pandora/user/models.py @@ -70,13 +70,16 @@ class SessionData(models.Model): data.save() return data + def get_id(self): + return self.user and ox.to26(self.user.id) or self.session_key + def json(self, keys=None, user=None): j = { 'disabled': False, 'email': '', 'firstseen': self.firstseen, 'ip': self.ip, - 'id': self.user and ox.to26(self.user.id) or self.session_key, + 'id': self.get_id(), 'lastseen': self.lastseen, 'level': 'guest', 'notes': '', diff --git a/pandora/user/views.py b/pandora/user/views.py index 57330918a..8e2d58a02 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -515,7 +515,7 @@ Positions if qs.count() > 0: response['data']['position'] = utils.get_positions(ids, [qs[0].itemId])[0] elif 'positions' in data: - ids = [ox.to26(i.id) for i in qs] + ids = [i.get_id() for i in qs] response['data']['positions'] = utils.get_positions(ids, data['positions']) else: response['data']['items'] = qs.count() From b1e93e506266c8cc00142081a21aaac892c4d759 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 8 Nov 2011 01:23:12 +0100 Subject: [PATCH 4/4] dont return same title twice in autocomplete --- pandora/item/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora/item/views.py b/pandora/item/views.py index a845832c7..84c2953ac 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -324,7 +324,7 @@ def autocomplete(request): qs = qs.order_by(order_by, nulls_last=True) qs = qs[data['range'][0]:data['range'][1]] response = json_response({}) - response['data']['items'] = [i.get(data['key']) for i in qs] + response['data']['items'] = list(set([i.get(data['key']) for i in qs])) else: qs = models.Facet.objects.filter(key=data['key']) if data['value']: