merge
This commit is contained in:
commit
c070cc0cf1
3 changed files with 18 additions and 10 deletions
|
@ -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']:
|
||||
|
|
|
@ -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,16 +66,20 @@ class SessionData(models.Model):
|
|||
if not data.timesseen:
|
||||
data.timesseen = 0
|
||||
data.timesseen += 1
|
||||
data.lastseen = datetime.now()
|
||||
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': '',
|
||||
|
@ -126,9 +129,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 +210,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 = {
|
||||
|
|
|
@ -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')
|
||||
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue