sort lists/peers, rename peers
This commit is contained in:
parent
eac91e7a3a
commit
8ddf228068
9 changed files with 141 additions and 26 deletions
|
|
@ -210,12 +210,12 @@ class Changelog(db.Model):
|
|||
|
||||
def action_orderlists(self, user, timestamp, lists):
|
||||
from user.models import List
|
||||
position = 0
|
||||
idx = 0
|
||||
for name in lists:
|
||||
l = List.get_or_create(user.id, name)
|
||||
l.position = position
|
||||
l.index_ = idx
|
||||
l.save()
|
||||
position += 1
|
||||
idx += 1
|
||||
return True
|
||||
|
||||
def action_removelist(self, user, timestamp, name):
|
||||
|
|
@ -239,8 +239,12 @@ class Changelog(db.Model):
|
|||
return True
|
||||
|
||||
def action_editusername(self, user, timestamp, username):
|
||||
from user.models import List
|
||||
old = user.nickname
|
||||
user.info['username'] = username
|
||||
user.update_name()
|
||||
if old != user.nickname:
|
||||
List.rename_user(old, user.nickname)
|
||||
user.save()
|
||||
return True
|
||||
|
||||
|
|
|
|||
|
|
@ -84,6 +84,20 @@ class PostUpdate(Command):
|
|||
if old <= '20140521-65-e14c686' and new > '20140521-65-e14c686':
|
||||
if not os.path.exists(settings.db_path):
|
||||
r('./ctl', 'setup')
|
||||
if old <= '20140525-92-eac91e7' and new > '20140525-92-eac91e7':
|
||||
import user.models
|
||||
for u in user.models.User.query:
|
||||
u.update_name()
|
||||
u.save()
|
||||
import item.models
|
||||
for f in item.models.File.query:
|
||||
changed = False
|
||||
for key in ('mediastate', 'coverRatio', 'previewRatio'):
|
||||
if key in f.info:
|
||||
del f.info[key]
|
||||
changed = True
|
||||
if changed:
|
||||
f.save()
|
||||
|
||||
class Setup(Command):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -242,8 +242,9 @@ class Item(db.Model):
|
|||
record = {}
|
||||
for key in self.meta_keys:
|
||||
if key in data:
|
||||
if self.meta.get(key) != data[key]:
|
||||
record[key] = data[key]
|
||||
self.meta[key] = data[key]
|
||||
record[key] = data[key]
|
||||
update = True
|
||||
for key in self.meta.keys():
|
||||
if key not in self.meta_keys:
|
||||
|
|
@ -254,7 +255,7 @@ class Item(db.Model):
|
|||
self.modified = datetime.utcnow()
|
||||
self.save()
|
||||
user = state.user()
|
||||
if user in self.users:
|
||||
if record and user in self.users:
|
||||
Changelog.record(user, 'edititem', self.id, record)
|
||||
|
||||
def update_primaryid(self, key=None, id=None):
|
||||
|
|
@ -359,7 +360,11 @@ class Item(db.Model):
|
|||
return False
|
||||
if not f:
|
||||
path = 'Downloads/%s.%s' % (self.id, self.info['extension'])
|
||||
f = File.get_or_create(self.id, self.info, path=path)
|
||||
info = self.info.copy()
|
||||
for key in ('mediastate', 'coverRatio', 'previewRatio'):
|
||||
if key in info:
|
||||
del info[key]
|
||||
f = File.get_or_create(self.id, info, path=path)
|
||||
path = self.get_path()
|
||||
if not os.path.exists(path):
|
||||
ox.makedirs(os.path.dirname(path))
|
||||
|
|
@ -371,7 +376,7 @@ class Item(db.Model):
|
|||
t.progress = 1
|
||||
t.save()
|
||||
self.added = datetime.utcnow()
|
||||
Changelog.record(u, 'additem', self.id, self.info)
|
||||
Changelog.record(u, 'additem', self.id, f.info)
|
||||
self.update()
|
||||
f.move()
|
||||
self.update_icons()
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ def add_file(id, f, prefix):
|
|||
item.meta['primaryid'] = item.info.pop('primaryid')
|
||||
db.session.add(item)
|
||||
item.users.append(user)
|
||||
Changelog.record(user, 'additem', item.id, item.info)
|
||||
Changelog.record(user, 'additem', item.id, f.info)
|
||||
if item.meta.get('primaryid'):
|
||||
Changelog.record(user, 'edititem', item.id, dict([item.meta['primaryid']]))
|
||||
item.added = datetime.utcnow()
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from copy import deepcopy
|
|||
import json
|
||||
|
||||
from oxtornado import actions
|
||||
|
||||
import ox
|
||||
|
||||
import models
|
||||
|
||||
|
|
@ -87,6 +87,7 @@ def getUsers(data):
|
|||
users = []
|
||||
for u in models.User.query.filter(models.User.id!=settings.USER_ID).all():
|
||||
users.append(u.json())
|
||||
users.sort(key=lambda u: ox.sort_string(str(u.get('index', '')) + 'Z' + (u.get('name') or '')))
|
||||
return {
|
||||
"users": users
|
||||
}
|
||||
|
|
@ -229,13 +230,17 @@ def sortLists(data):
|
|||
'''
|
||||
n = 0
|
||||
logger.debug('sortLists %s', data)
|
||||
lists = []
|
||||
for id in data['ids']:
|
||||
l = models.List.get(id)
|
||||
l.position = n
|
||||
l.index_ = n
|
||||
n += 1
|
||||
if l.type == 'static':
|
||||
lists.append(l.name)
|
||||
models.db.session.add(l)
|
||||
models.db.session.commit()
|
||||
logger.debug('FIXME: broadcast orderlist event here')
|
||||
if lists:
|
||||
Changelog.record(state.user(), 'orderlists', lists)
|
||||
return {}
|
||||
actions.register(sortLists, cache=False)
|
||||
|
||||
|
|
@ -253,12 +258,31 @@ def editUser(data):
|
|||
p.info['nickname'] = data['nickname']
|
||||
elif 'nickname' in p.info:
|
||||
del p.info['nickname']
|
||||
old = p.nickname
|
||||
p.update_name()
|
||||
if old != p.nickname:
|
||||
models.List.rename_user(old, p.nickname)
|
||||
p.save()
|
||||
return p.json()
|
||||
return {}
|
||||
actions.register(editUser, cache=False)
|
||||
|
||||
def sortUsers(data):
|
||||
'''
|
||||
takes {
|
||||
ids
|
||||
}
|
||||
'''
|
||||
n = 0
|
||||
logger.debug('sortUsers %s', data)
|
||||
for id in data['ids']:
|
||||
u = models.User.get(id)
|
||||
u.info['index'] = n
|
||||
n += 1
|
||||
models.db.session.add(u)
|
||||
models.db.session.commit()
|
||||
return {}
|
||||
actions.register(sortUsers, cache=False)
|
||||
|
||||
def requestPeering(data):
|
||||
'''
|
||||
|
|
|
|||
|
|
@ -183,13 +183,30 @@ class List(db.Model):
|
|||
l.type = 'smart' if l._query else 'static'
|
||||
l.index_ = cls.query.filter_by(user_id=user_id).count()
|
||||
if user_id == settings.USER_ID:
|
||||
p = User.get(settings.USER_ID)
|
||||
if not l._query:
|
||||
Changelog.record(p, 'addlist', l.name)
|
||||
Changelog.record(state.user(), 'addlist', l.name)
|
||||
db.session.add(l)
|
||||
db.session.commit()
|
||||
return l
|
||||
|
||||
@classmethod
|
||||
def rename_user(cls, old, new):
|
||||
for l in cls.query.filter(cls._query!=None):
|
||||
|
||||
def update_conditions(conditions):
|
||||
changed = False
|
||||
for c in conditions:
|
||||
if 'conditions' in c:
|
||||
changed = update_conditions(conditions)
|
||||
else:
|
||||
if c.get('key') == 'list' and c.get('value', '').startswith('%s:' % old):
|
||||
c['value'] = '%s:%s' % new, c['value'].split(':', 1)[1]
|
||||
changed = True
|
||||
return changed
|
||||
|
||||
if update_conditions(l._query.get('conditions', [])):
|
||||
l.save()
|
||||
|
||||
def add_items(self, items):
|
||||
from item.models import Item
|
||||
for item_id in items:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue