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