gracefully keep favorites on top that have been promoted manually
This commit is contained in:
parent
1d7f01dccb
commit
acef9b683e
2 changed files with 8 additions and 4 deletions
|
@ -75,7 +75,7 @@ So we are now ready to query the favorites.
|
||||||
|
|
||||||
>>> favs = list(favorites.query(userName=johnCId))
|
>>> favs = list(favorites.query(userName=johnCId))
|
||||||
>>> favs
|
>>> favs
|
||||||
[<Favorite ['27', 1, '33', '...']: {'type': 'favorite'}>]
|
[<Favorite ['27', 1, '33', '...']: {'type': 'favorite', 'order': 100}>]
|
||||||
|
|
||||||
>>> list(favAdapted.list(johnC))
|
>>> list(favAdapted.list(johnC))
|
||||||
['27']
|
['27']
|
||||||
|
|
|
@ -50,7 +50,7 @@ class Favorites(object):
|
||||||
return
|
return
|
||||||
personUid = util.getUidForObject(person)
|
personUid = util.getUidForObject(person)
|
||||||
if sortKey is None:
|
if sortKey is None:
|
||||||
sortKey = lambda x: (x.data.get('order', 0), -x.timeStamp)
|
sortKey = lambda x: (x.data.get('order', 100), -x.timeStamp)
|
||||||
for item in sorted(self.context.query(userName=personUid), key=sortKey):
|
for item in sorted(self.context.query(userName=personUid), key=sortKey):
|
||||||
if type is not None:
|
if type is not None:
|
||||||
if item.type != type:
|
if item.type != type:
|
||||||
|
@ -63,7 +63,7 @@ class Favorites(object):
|
||||||
uid = util.getUidForObject(obj)
|
uid = util.getUidForObject(obj)
|
||||||
personUid = util.getUidForObject(person)
|
personUid = util.getUidForObject(person)
|
||||||
if data is None:
|
if data is None:
|
||||||
data = {'type': 'favorite'}
|
data = {'type': 'favorite', 'order': 100}
|
||||||
for track in self.context.query(userName=personUid, taskId=uid):
|
for track in self.context.query(userName=personUid, taskId=uid):
|
||||||
if track.type == data['type']: # already present
|
if track.type == data['type']: # already present
|
||||||
return False
|
return False
|
||||||
|
@ -82,11 +82,15 @@ class Favorites(object):
|
||||||
return changed
|
return changed
|
||||||
|
|
||||||
def reorder(self, uids):
|
def reorder(self, uids):
|
||||||
|
offset = 0
|
||||||
for idx, uid in enumerate(uids):
|
for idx, uid in enumerate(uids):
|
||||||
track = util.getObjectForUid(uid)
|
track = util.getObjectForUid(uid)
|
||||||
if track is not None:
|
if track is not None:
|
||||||
data = track.data
|
data = track.data
|
||||||
data['order'] = idx
|
order = data.get('order', 100)
|
||||||
|
if order < idx or (order >= 100 and order < idx + 100):
|
||||||
|
offset = 100
|
||||||
|
data['order'] = idx + offset
|
||||||
track.data = data
|
track.data = data
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue