switch to base26 ids
This commit is contained in:
parent
addd1780f1
commit
bc118c67ee
9 changed files with 36 additions and 23 deletions
|
@ -21,6 +21,9 @@ def parseCondition(condition, user):
|
|||
'user': 'user__username',
|
||||
'place': 'places__id',
|
||||
'event': 'events__id',
|
||||
'in': 'start',
|
||||
'out': 'end',
|
||||
'id': 'public_id',
|
||||
}.get(k, k)
|
||||
if not k:
|
||||
k = 'name'
|
||||
|
@ -40,10 +43,8 @@ def parseCondition(condition, user):
|
|||
return ~q
|
||||
else:
|
||||
return q
|
||||
if k == 'id':
|
||||
v = ox.from32(v.split('/')[-1])
|
||||
elif k in ('places__id', 'events__id'):
|
||||
v = ox.from32(v)
|
||||
if k in ('places__id', 'events__id'):
|
||||
v = ox.from26(v)
|
||||
if isinstance(v, bool): #featured and public flag
|
||||
key = k
|
||||
elif k in ('lat', 'lng', 'area', 'south', 'west', 'north', 'east', 'matches',
|
||||
|
@ -56,7 +57,12 @@ def parseCondition(condition, user):
|
|||
}.get(op, ''))
|
||||
else:
|
||||
key = "%s%s" % (k, {
|
||||
'>': '__gt',
|
||||
'>=': '__gte',
|
||||
'<': '__lt',
|
||||
'<=': '__lte',
|
||||
'==': '__iexact',
|
||||
'=': '__icontains',
|
||||
'^': '__istartswith',
|
||||
'$': '__iendswith',
|
||||
}.get(op, '__icontains'))
|
||||
|
|
|
@ -117,10 +117,14 @@ class Annotation(models.Model):
|
|||
self.hue = self.saturation = self.lightness = 0
|
||||
#FIXME: set volume here
|
||||
|
||||
def set_public_id(self):
|
||||
public_id = Annotation.objects.filter(item=self.item, id__lt=self.id).count()
|
||||
self.public_id = "%s/%s" % ( self.item.itemId, ox.to26(public_id))
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.id:
|
||||
super(Annotation, self).save(*args, **kwargs)
|
||||
self.public_id = '%s/%s' % (self.item.itemId, ox.to32(self.id))
|
||||
self.set_public_id()
|
||||
if self.duration != self.end - self.start:
|
||||
self.update_calculated_values()
|
||||
super(Annotation, self).save(*args, **kwargs)
|
||||
|
|
|
@ -45,11 +45,15 @@ def order_query(qs, sort):
|
|||
operator = e['operator']
|
||||
if operator != '-':
|
||||
operator = ''
|
||||
if e['key'].startswith('clip:'):
|
||||
key = {
|
||||
'in': 'start',
|
||||
'out': 'end',
|
||||
}.get(e['key'], e['key'])
|
||||
if key.startswith('clip:'):
|
||||
key = annotation_sort_key(e['key'][len('clip:'):])
|
||||
else:
|
||||
elif key not in ('start', 'end', 'value'):
|
||||
#key mgith need to be changed, see order_sort in item/views.py
|
||||
key = "item__sort__%s" % e['key']
|
||||
key = "item__sort__%s" % key
|
||||
order = '%s%s' % (operator, key)
|
||||
order_by.append(order)
|
||||
if order_by:
|
||||
|
@ -155,13 +159,12 @@ def removeAnnotations(request):
|
|||
'''
|
||||
response = json_response({})
|
||||
data = json.loads(request.POST['data'])
|
||||
ids = map(ox.from32, data['ids'])
|
||||
failed = []
|
||||
for a in models.Annotation.objects.filter(id__in=ids):
|
||||
for a in models.Annotation.objects.filter(public_id__in=data['ids']):
|
||||
if a.editable(request.user):
|
||||
a.delete()
|
||||
else:
|
||||
failed.append(a.get_id)
|
||||
failed.append(a.public_id)
|
||||
if failed:
|
||||
response = json_response(status=403, text='permission denied')
|
||||
response['data']['ids'] = failed
|
||||
|
@ -187,8 +190,7 @@ def editAnnotation(request):
|
|||
'''
|
||||
response = json_response({})
|
||||
data = json.loads(request.POST['data'])
|
||||
itemId, annotationId = data['id'].split('/')
|
||||
a = get_object_or_404_json(models.Annotation, pk=ox.from32(annotationId))
|
||||
a = get_object_or_404_json(models.Annotation, public_id=data['id'])
|
||||
if a.editable(request.user):
|
||||
a.value = data['value']
|
||||
a.start = data['in']
|
||||
|
|
|
@ -83,7 +83,7 @@ class Event(models.Model):
|
|||
super(Event, self).save(*args, **kwargs)
|
||||
|
||||
def get_id(self):
|
||||
return ox.to32(self.id)
|
||||
return ox.to26(self.id)
|
||||
|
||||
def json(self, user=None):
|
||||
j = {
|
||||
|
|
|
@ -291,7 +291,7 @@ class Item(models.Model):
|
|||
self.itemId = str(uuid.uuid1())
|
||||
super(Item, self).save(*args, **kwargs)
|
||||
if not settings.USE_IMDB:
|
||||
self.itemId = ox.to32(self.id)
|
||||
self.itemId = ox.to26(self.id)
|
||||
|
||||
oxdbId = self.oxdb_id()
|
||||
if oxdbId:
|
||||
|
|
|
@ -40,7 +40,7 @@ def parseCondition(condition, user):
|
|||
else:
|
||||
return q
|
||||
if k == 'id':
|
||||
v = ox.from32(v)
|
||||
v = ox.from26(v)
|
||||
if isinstance(v, bool): #featured and public flag
|
||||
key = k
|
||||
elif k in ('lat', 'lng', 'area', 'south', 'west', 'north', 'east', 'matches', 'id'):
|
||||
|
|
|
@ -59,9 +59,9 @@ class Place(models.Model):
|
|||
return False
|
||||
|
||||
def get_id(self):
|
||||
return ox.to32(self.id)
|
||||
return ox.to26(self.id)
|
||||
|
||||
def json(self, user=None):
|
||||
def json(self, keys=None, user=None):
|
||||
j = {
|
||||
'id': self.get_id(),
|
||||
'user': self.user.username,
|
||||
|
@ -71,7 +71,8 @@ class Place(models.Model):
|
|||
'name', 'alternativeNames', 'geoname', 'countryCode',
|
||||
'south', 'west', 'north', 'east',
|
||||
'lat', 'lng', 'area', 'matches', 'type'):
|
||||
j[key] = getattr(self, key)
|
||||
if not keys or key in keys:
|
||||
j[key] = getattr(self, key)
|
||||
return j
|
||||
|
||||
def get_matches(self):
|
||||
|
|
|
@ -71,7 +71,7 @@ def editPlace(request):
|
|||
can contain any of the allowed keys for place
|
||||
'''
|
||||
data = json.loads(request.POST['data'])
|
||||
place = get_object_or_404_json(models.Place, pk=ox.from32(data['id']))
|
||||
place = get_object_or_404_json(models.Place, pk=ox.from26(data['id']))
|
||||
names = data.get('name', [])
|
||||
if isinstance(names, basestring):
|
||||
names = [names]
|
||||
|
@ -111,7 +111,7 @@ def removePlace(request):
|
|||
data = json.loads(request.POST['data'])
|
||||
if isinstance(data, dict):
|
||||
data = data['id']
|
||||
place = get_object_or_404_json(models.Place, pk=ox.from32(data))
|
||||
place = get_object_or_404_json(models.Place, pk=ox.from26(data))
|
||||
if place.editable(request.user):
|
||||
place.delete()
|
||||
response = json_response(status=200, text='deleted')
|
||||
|
@ -227,7 +227,7 @@ Positions
|
|||
qs = order_query(query['qs'], query['sort'])
|
||||
if 'keys' in data:
|
||||
qs = qs[query['range'][0]:query['range'][1]]
|
||||
response['data']['items'] = [p.json(request.user) for p in qs]
|
||||
response['data']['items'] = [p.json(data['keys'], request.user) for p in qs]
|
||||
elif 'position' in query:
|
||||
ids = [i.get_id() for i in qs]
|
||||
data['conditions'] = data['conditions'] + {
|
||||
|
|
|
@ -274,7 +274,7 @@ def requestToken(request):
|
|||
user = None
|
||||
if user:
|
||||
while True:
|
||||
token = ox.to32(random.randint(32768, 1048575))
|
||||
token = ox.to26(random.randint(32768, 1048575))
|
||||
if models.UserProfile.objects.filter(reset_token=token).count() == 0:
|
||||
break
|
||||
user_profile = user.get_profile()
|
||||
|
|
Loading…
Reference in a new issue