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.order_by(order_by, nulls_last=True)
|
||||||
qs = qs[data['range'][0]:data['range'][1]]
|
qs = qs[data['range'][0]:data['range'][1]]
|
||||||
response = json_response({})
|
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:
|
else:
|
||||||
qs = models.Facet.objects.filter(key=data['key'])
|
qs = models.Facet.objects.filter(key=data['key'])
|
||||||
if data['value']:
|
if data['value']:
|
||||||
|
|
|
@ -4,7 +4,6 @@ import copy
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.sessions.models import Session
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Max
|
from django.db.models import Max
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -21,7 +20,7 @@ class SessionData(models.Model):
|
||||||
session_key = models.CharField(max_length=40, primary_key=True)
|
session_key = models.CharField(max_length=40, primary_key=True)
|
||||||
user = models.ForeignKey(User, unique=True, null=True, blank=True, related_name='data')
|
user = models.ForeignKey(User, unique=True, null=True, blank=True, related_name='data')
|
||||||
firstseen = models.DateTimeField(auto_now_add=True, db_index=True)
|
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)
|
username = models.CharField(max_length=255, null=True, db_index=True)
|
||||||
level = models.IntegerField(default=0)
|
level = models.IntegerField(default=0)
|
||||||
|
|
||||||
|
@ -67,16 +66,20 @@ class SessionData(models.Model):
|
||||||
if not data.timesseen:
|
if not data.timesseen:
|
||||||
data.timesseen = 0
|
data.timesseen = 0
|
||||||
data.timesseen += 1
|
data.timesseen += 1
|
||||||
|
data.lastseen = datetime.now()
|
||||||
data.save()
|
data.save()
|
||||||
return data
|
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):
|
def json(self, keys=None, user=None):
|
||||||
j = {
|
j = {
|
||||||
'disabled': False,
|
'disabled': False,
|
||||||
'email': '',
|
'email': '',
|
||||||
'firstseen': self.firstseen,
|
'firstseen': self.firstseen,
|
||||||
'ip': self.ip,
|
'ip': self.ip,
|
||||||
'id': self.user and ox.to26(self.user.id) or self.session_key,
|
'id': self.get_id(),
|
||||||
'lastseen': self.lastseen,
|
'lastseen': self.lastseen,
|
||||||
'level': 'guest',
|
'level': 'guest',
|
||||||
'notes': '',
|
'notes': '',
|
||||||
|
@ -126,9 +129,15 @@ class UserProfile(models.Model):
|
||||||
|
|
||||||
def user_post_save(sender, instance, **kwargs):
|
def user_post_save(sender, instance, **kwargs):
|
||||||
profile, new = UserProfile.objects.get_or_create(user=instance)
|
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)
|
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):
|
def get_ui(user_ui, user=None):
|
||||||
ui = {}
|
ui = {}
|
||||||
config = copy.deepcopy(settings.CONFIG)
|
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()]
|
result['volumes'] = [v.json() for v in user.volumes.all()]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def user_json(user, keys=None):
|
def user_json(user, keys=None):
|
||||||
p = user.get_profile()
|
p = user.get_profile()
|
||||||
j = {
|
j = {
|
||||||
|
|
|
@ -161,7 +161,7 @@ def signup(request):
|
||||||
user.save()
|
user.save()
|
||||||
#create default user lists:
|
#create default user lists:
|
||||||
for l in settings.CONFIG['personalLists']:
|
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'):
|
for key in ('query', 'public', 'featured'):
|
||||||
if key in l:
|
if key in l:
|
||||||
setattr(list, key, l[key])
|
setattr(list, key, l[key])
|
||||||
|
@ -170,7 +170,7 @@ def signup(request):
|
||||||
user = authenticate(username=data['username'],
|
user = authenticate(username=data['username'],
|
||||||
password=data['password'])
|
password=data['password'])
|
||||||
login(request, user)
|
login(request, user)
|
||||||
user_json = models.init_user(user)
|
user_json = models.init_user(user, request)
|
||||||
response = json_response({
|
response = json_response({
|
||||||
'user': user_json
|
'user': user_json
|
||||||
}, text='account created')
|
}, text='account created')
|
||||||
|
@ -219,7 +219,7 @@ def resetPassword(request):
|
||||||
user = authenticate(username=user.username, password=data['password'])
|
user = authenticate(username=user.username, password=data['password'])
|
||||||
login(request, user)
|
login(request, user)
|
||||||
|
|
||||||
user_json = models.init_user(user)
|
user_json = models.init_user(user, request)
|
||||||
response = json_response({
|
response = json_response({
|
||||||
'user': user_json
|
'user': user_json
|
||||||
}, text='password reset')
|
}, text='password reset')
|
||||||
|
@ -515,7 +515,7 @@ Positions
|
||||||
if qs.count() > 0:
|
if qs.count() > 0:
|
||||||
response['data']['position'] = utils.get_positions(ids, [qs[0].itemId])[0]
|
response['data']['position'] = utils.get_positions(ids, [qs[0].itemId])[0]
|
||||||
elif 'positions' in data:
|
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'])
|
response['data']['positions'] = utils.get_positions(ids, data['positions'])
|
||||||
else:
|
else:
|
||||||
response['data']['items'] = qs.count()
|
response['data']['items'] = qs.count()
|
||||||
|
|
Loading…
Reference in a new issue