use from/toAZ
This commit is contained in:
parent
e13f67624d
commit
cea86aee43
17 changed files with 28 additions and 28 deletions
|
@ -52,8 +52,8 @@ class Annotation(models.Model):
|
||||||
|
|
||||||
def set_public_id(self):
|
def set_public_id(self):
|
||||||
if self.id:
|
if self.id:
|
||||||
public_id = Annotation.objects.filter(item=self.item, id__lt=self.id).count()
|
public_id = Annotation.objects.filter(item=self.item, id__lt=self.id).count() + 1
|
||||||
self.public_id = "%s/%s" % (self.item.itemId, ox.to26(public_id))
|
self.public_id = "%s/%s" % (self.item.itemId, ox.toAZ(public_id))
|
||||||
Annotation.objects.filter(id=self.id).update(public_id=self.public_id)
|
Annotation.objects.filter(id=self.id).update(public_id=self.public_id)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
|
|
@ -129,7 +129,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.to26(self.id)
|
return ox.toAZ(self.id)
|
||||||
|
|
||||||
def json(self, user=None):
|
def json(self, user=None):
|
||||||
j = {
|
j = {
|
||||||
|
|
|
@ -65,7 +65,7 @@ def editEvent(request):
|
||||||
update provides keys of event with id
|
update provides keys of event with id
|
||||||
'''
|
'''
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
event = get_object_or_404_json(models.Event, pk=ox.from26(data['id']))
|
event = get_object_or_404_json(models.Event, pk=ox.fromAZ(data['id']))
|
||||||
if event.editable(request.user):
|
if event.editable(request.user):
|
||||||
conflict = False
|
conflict = False
|
||||||
conflict_names = []
|
conflict_names = []
|
||||||
|
@ -110,7 +110,7 @@ def removeEvent(request):
|
||||||
|
|
||||||
'''
|
'''
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
event = get_object_or_404_json(models.Event, pk=ox.from26(data['id']))
|
event = get_object_or_404_json(models.Event, pk=ox.fromAZ(data['id']))
|
||||||
if event.editable(request.user):
|
if event.editable(request.user):
|
||||||
event.delete()
|
event.delete()
|
||||||
response = json_response(status=200, text='removed')
|
response = json_response(status=200, text='removed')
|
||||||
|
|
|
@ -264,7 +264,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.to26(self.id)
|
self.itemId = ox.toAZ(self.id)
|
||||||
|
|
||||||
#this does not work if another item without imdbid has the same metadata
|
#this does not work if another item without imdbid has the same metadata
|
||||||
oxdbId = self.oxdb_id()
|
oxdbId = self.oxdb_id()
|
||||||
|
|
|
@ -8,7 +8,7 @@ import ox
|
||||||
|
|
||||||
def decode_id(id):
|
def decode_id(id):
|
||||||
try:
|
try:
|
||||||
id = ox.from26(id)
|
id = ox.fromAZ(id)
|
||||||
except:
|
except:
|
||||||
id = 0
|
id = 0
|
||||||
return id
|
return id
|
||||||
|
|
|
@ -24,7 +24,7 @@ class Log(models.Model):
|
||||||
def json(self, keys=None):
|
def json(self, keys=None):
|
||||||
j = {
|
j = {
|
||||||
'created': self.created,
|
'created': self.created,
|
||||||
'id': ox.to26(self.id),
|
'id': ox.toAZ(self.id),
|
||||||
'line': self.line,
|
'line': self.line,
|
||||||
'modified': self.modified,
|
'modified': self.modified,
|
||||||
'text': self.text,
|
'text': self.text,
|
||||||
|
|
|
@ -59,7 +59,7 @@ def removeLogs(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'])
|
||||||
models.Log.objects.filter(id__in=[ox.from26(i) for i in data['ids']]).delete()
|
models.Log.objects.filter(id__in=[ox.fromAZ(i) for i in data['ids']]).delete()
|
||||||
response = json_response()
|
response = json_response()
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(removeLogs, cache=False)
|
actions.register(removeLogs, cache=False)
|
||||||
|
@ -130,7 +130,7 @@ def findLogs(request):
|
||||||
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 = [ox.toAZ(i.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()
|
||||||
|
|
|
@ -35,7 +35,7 @@ class News(models.Model):
|
||||||
def json(self, keys=None):
|
def json(self, keys=None):
|
||||||
j = {
|
j = {
|
||||||
'user': self.user.username,
|
'user': self.user.username,
|
||||||
'id': ox.to26(self.id),
|
'id': ox.toAZ(self.id),
|
||||||
'title': self.title,
|
'title': self.title,
|
||||||
'content': self.content,
|
'content': self.content,
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ def findNews(request):
|
||||||
qs = qs[query['range'][0]:query['range'][1]]
|
qs = qs[query['range'][0]:query['range'][1]]
|
||||||
response['data']['items'] = [p.json(keys=data['keys']) for p in qs]
|
response['data']['items'] = [p.json(keys=data['keys']) for p in qs]
|
||||||
elif 'position' in query:
|
elif 'position' in query:
|
||||||
ids = [ox.to26(i.id) for i in qs]
|
ids = [ox.toAZ(i.id) for i in qs]
|
||||||
data['conditions'] = data['conditions'] + {
|
data['conditions'] = data['conditions'] + {
|
||||||
'value': data['position'],
|
'value': data['position'],
|
||||||
'key': query['sort'][0]['key'],
|
'key': query['sort'][0]['key'],
|
||||||
|
@ -98,7 +98,7 @@ def findNews(request):
|
||||||
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 = [ox.toAZ(i.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()
|
||||||
|
@ -148,7 +148,7 @@ def removeNews(request):
|
||||||
response = json_response({})
|
response = json_response({})
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
failed = []
|
failed = []
|
||||||
ids = [ox.from26(i) for i in data['ids']]
|
ids = [ox.fromAZ(i) for i in data['ids']]
|
||||||
for a in models.News.objects.filter(id__in=ids):
|
for a in models.News.objects.filter(id__in=ids):
|
||||||
if a.editable(request.user):
|
if a.editable(request.user):
|
||||||
a.delete()
|
a.delete()
|
||||||
|
@ -156,7 +156,7 @@ def removeNews(request):
|
||||||
failed.append(a.id)
|
failed.append(a.id)
|
||||||
if failed:
|
if failed:
|
||||||
response = json_response(status=403, text='permission denied')
|
response = json_response(status=403, text='permission denied')
|
||||||
response['data']['ids'] = [ox.to26(i) for i in failed]
|
response['data']['ids'] = [ox.toAZ(i) for i in failed]
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(removeNews, cache=False)
|
actions.register(removeNews, cache=False)
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ def editNews(request):
|
||||||
'''
|
'''
|
||||||
response = json_response({})
|
response = json_response({})
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
n = get_object_or_404_json(models.News, id=ox.from26(data['id']))
|
n = get_object_or_404_json(models.News, id=ox.fromAZ(data['id']))
|
||||||
if n.editable(request.user):
|
if n.editable(request.user):
|
||||||
for key in ('title', 'content', 'public'):
|
for key in ('title', 'content', 'public'):
|
||||||
if key in data:
|
if key in data:
|
||||||
|
|
|
@ -76,7 +76,7 @@ class Person(models.Model):
|
||||||
get_or_create = classmethod(get_or_create)
|
get_or_create = classmethod(get_or_create)
|
||||||
|
|
||||||
def get_id(self):
|
def get_id(self):
|
||||||
return ox.to26(self.id)
|
return ox.toAZ(self.id)
|
||||||
|
|
||||||
def json(self, keys=None, user=None):
|
def json(self, keys=None, user=None):
|
||||||
j = {
|
j = {
|
||||||
|
|
|
@ -25,7 +25,7 @@ def editName(request):
|
||||||
can contain any of the allowed keys for name
|
can contain any of the allowed keys for name
|
||||||
'''
|
'''
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
person = get_object_or_404_json(models.Person, pk=ox.from26(data['id']))
|
person = get_object_or_404_json(models.Person, pk=ox.fromAZ(data['id']))
|
||||||
response = json_response()
|
response = json_response()
|
||||||
if 'sortname' in data:
|
if 'sortname' in data:
|
||||||
person.sortname = data['sortname']
|
person.sortname = data['sortname']
|
||||||
|
|
|
@ -61,7 +61,7 @@ class Place(models.Model):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_id(self):
|
def get_id(self):
|
||||||
return ox.to26(self.id)
|
return ox.toAZ(self.id)
|
||||||
|
|
||||||
def json(self, keys=None, user=None):
|
def json(self, keys=None, user=None):
|
||||||
j = {
|
j = {
|
||||||
|
|
|
@ -82,7 +82,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.from26(data['id']))
|
place = get_object_or_404_json(models.Place, pk=ox.fromAZ(data['id']))
|
||||||
names = data.get('name', [])
|
names = data.get('name', [])
|
||||||
if isinstance(names, basestring):
|
if isinstance(names, basestring):
|
||||||
names = [names]
|
names = [names]
|
||||||
|
@ -131,7 +131,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.from26(data))
|
place = get_object_or_404_json(models.Place, pk=ox.fromAZ(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')
|
||||||
|
|
|
@ -61,7 +61,7 @@ class Title(models.Model):
|
||||||
get_or_create = classmethod(get_or_create)
|
get_or_create = classmethod(get_or_create)
|
||||||
|
|
||||||
def get_id(self):
|
def get_id(self):
|
||||||
return ox.to26(self.id)
|
return ox.toAZ(self.id)
|
||||||
|
|
||||||
def json(self, keys=None, user=None):
|
def json(self, keys=None, user=None):
|
||||||
j = {
|
j = {
|
||||||
|
|
|
@ -26,7 +26,7 @@ def editTitle(request):
|
||||||
can contain any of the allowed keys for title
|
can contain any of the allowed keys for title
|
||||||
'''
|
'''
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
title = get_object_or_404_json(models.Title, pk=ox.from26(data['id']))
|
title = get_object_or_404_json(models.Title, pk=ox.fromAZ(data['id']))
|
||||||
response = json_response()
|
response = json_response()
|
||||||
if 'sorttitle' in data:
|
if 'sorttitle' in data:
|
||||||
title.sorttitle = data['sorttitle']
|
title.sorttitle = data['sorttitle']
|
||||||
|
|
|
@ -122,7 +122,7 @@ class SessionData(models.Model):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_id(self):
|
def get_id(self):
|
||||||
return self.user and ox.to26(self.user.id) or self.session_key
|
return self.user and ox.toAZ(self.user.id) or self.session_key
|
||||||
|
|
||||||
def json(self, keys=None, user=None):
|
def json(self, keys=None, user=None):
|
||||||
j = {
|
j = {
|
||||||
|
@ -276,7 +276,7 @@ def user_json(user, keys=None):
|
||||||
'disabled': not user.is_active,
|
'disabled': not user.is_active,
|
||||||
'email': user.email,
|
'email': user.email,
|
||||||
'firstseen': user.date_joined,
|
'firstseen': user.date_joined,
|
||||||
'id': ox.to26(user.id),
|
'id': ox.toAZ(user.id),
|
||||||
'lastseen': user.last_login,
|
'lastseen': user.last_login,
|
||||||
'level': p.get_level(),
|
'level': p.get_level(),
|
||||||
'newsletter': p.newsletter,
|
'newsletter': p.newsletter,
|
||||||
|
|
|
@ -267,8 +267,8 @@ def requestToken(request):
|
||||||
user = None
|
user = None
|
||||||
if user:
|
if user:
|
||||||
while True:
|
while True:
|
||||||
code = ox.to26(random.randint(ox.from26('BAAAAAAAAAAAAAAA'),
|
code = ox.toAZ(random.randint(ox.fromAZ('AAAAAAAAAAAAAAAA'),
|
||||||
ox.from26('BAAAAAAAAAAAAAAAA')))
|
ox.fromAZ('AAAAAAAAAAAAAAAAA')))
|
||||||
if models.UserProfile.objects.filter(reset_code=code).count() == 0:
|
if models.UserProfile.objects.filter(reset_code=code).count() == 0:
|
||||||
break
|
break
|
||||||
user_profile = user.get_profile()
|
user_profile = user.get_profile()
|
||||||
|
@ -320,7 +320,7 @@ def editUser(request):
|
||||||
'''
|
'''
|
||||||
response = json_response()
|
response = json_response()
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
user = get_object_or_404_json(models.User, pk=ox.from26(data['id']))
|
user = get_object_or_404_json(models.User, pk=ox.fromAZ(data['id']))
|
||||||
profile = user.get_profile()
|
profile = user.get_profile()
|
||||||
if 'disabled' in data:
|
if 'disabled' in data:
|
||||||
user.is_active = not data['disabled']
|
user.is_active = not data['disabled']
|
||||||
|
|
Loading…
Reference in a new issue