use from/toAZ

This commit is contained in:
j 2011-12-18 15:05:49 +05:30
parent e13f67624d
commit cea86aee43
17 changed files with 28 additions and 28 deletions

View file

@ -52,8 +52,8 @@ class Annotation(models.Model):
def set_public_id(self):
if self.id:
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))
public_id = Annotation.objects.filter(item=self.item, id__lt=self.id).count() + 1
self.public_id = "%s/%s" % (self.item.itemId, ox.toAZ(public_id))
Annotation.objects.filter(id=self.id).update(public_id=self.public_id)
def save(self, *args, **kwargs):

View file

@ -129,7 +129,7 @@ class Event(models.Model):
super(Event, self).save(*args, **kwargs)
def get_id(self):
return ox.to26(self.id)
return ox.toAZ(self.id)
def json(self, user=None):
j = {

View file

@ -65,7 +65,7 @@ def editEvent(request):
update provides keys of event with id
'''
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):
conflict = False
conflict_names = []
@ -110,7 +110,7 @@ def removeEvent(request):
'''
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):
event.delete()
response = json_response(status=200, text='removed')

View file

@ -264,7 +264,7 @@ class Item(models.Model):
self.itemId = str(uuid.uuid1())
super(Item, self).save(*args, **kwargs)
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
oxdbId = self.oxdb_id()

View file

@ -8,7 +8,7 @@ import ox
def decode_id(id):
try:
id = ox.from26(id)
id = ox.fromAZ(id)
except:
id = 0
return id

View file

@ -24,7 +24,7 @@ class Log(models.Model):
def json(self, keys=None):
j = {
'created': self.created,
'id': ox.to26(self.id),
'id': ox.toAZ(self.id),
'line': self.line,
'modified': self.modified,
'text': self.text,

View file

@ -59,7 +59,7 @@ def removeLogs(request):
can contain any of the allowed keys for place
'''
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()
return render_to_json_response(response)
actions.register(removeLogs, cache=False)
@ -130,7 +130,7 @@ def findLogs(request):
if qs.count() > 0:
response['data']['position'] = utils.get_positions(ids, [qs[0].itemId])[0]
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'])
else:
response['data']['items'] = qs.count()

View file

@ -35,7 +35,7 @@ class News(models.Model):
def json(self, keys=None):
j = {
'user': self.user.username,
'id': ox.to26(self.id),
'id': ox.toAZ(self.id),
'title': self.title,
'content': self.content,
}

View file

@ -87,7 +87,7 @@ def findNews(request):
qs = qs[query['range'][0]:query['range'][1]]
response['data']['items'] = [p.json(keys=data['keys']) for p in qs]
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'] + {
'value': data['position'],
'key': query['sort'][0]['key'],
@ -98,7 +98,7 @@ def findNews(request):
if qs.count() > 0:
response['data']['position'] = utils.get_positions(ids, [qs[0].itemId])[0]
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'])
else:
response['data']['items'] = qs.count()
@ -148,7 +148,7 @@ def removeNews(request):
response = json_response({})
data = json.loads(request.POST['data'])
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):
if a.editable(request.user):
a.delete()
@ -156,7 +156,7 @@ def removeNews(request):
failed.append(a.id)
if failed:
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)
actions.register(removeNews, cache=False)
@ -179,7 +179,7 @@ def editNews(request):
'''
response = json_response({})
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):
for key in ('title', 'content', 'public'):
if key in data:

View file

@ -76,7 +76,7 @@ class Person(models.Model):
get_or_create = classmethod(get_or_create)
def get_id(self):
return ox.to26(self.id)
return ox.toAZ(self.id)
def json(self, keys=None, user=None):
j = {

View file

@ -25,7 +25,7 @@ def editName(request):
can contain any of the allowed keys for name
'''
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()
if 'sortname' in data:
person.sortname = data['sortname']

View file

@ -61,7 +61,7 @@ class Place(models.Model):
return False
def get_id(self):
return ox.to26(self.id)
return ox.toAZ(self.id)
def json(self, keys=None, user=None):
j = {

View file

@ -82,7 +82,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.from26(data['id']))
place = get_object_or_404_json(models.Place, pk=ox.fromAZ(data['id']))
names = data.get('name', [])
if isinstance(names, basestring):
names = [names]
@ -131,7 +131,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.from26(data))
place = get_object_or_404_json(models.Place, pk=ox.fromAZ(data))
if place.editable(request.user):
place.delete()
response = json_response(status=200, text='deleted')

View file

@ -61,7 +61,7 @@ class Title(models.Model):
get_or_create = classmethod(get_or_create)
def get_id(self):
return ox.to26(self.id)
return ox.toAZ(self.id)
def json(self, keys=None, user=None):
j = {

View file

@ -26,7 +26,7 @@ def editTitle(request):
can contain any of the allowed keys for title
'''
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()
if 'sorttitle' in data:
title.sorttitle = data['sorttitle']

View file

@ -122,7 +122,7 @@ class SessionData(models.Model):
return data
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):
j = {
@ -276,7 +276,7 @@ def user_json(user, keys=None):
'disabled': not user.is_active,
'email': user.email,
'firstseen': user.date_joined,
'id': ox.to26(user.id),
'id': ox.toAZ(user.id),
'lastseen': user.last_login,
'level': p.get_level(),
'newsletter': p.newsletter,

View file

@ -267,8 +267,8 @@ def requestToken(request):
user = None
if user:
while True:
code = ox.to26(random.randint(ox.from26('BAAAAAAAAAAAAAAA'),
ox.from26('BAAAAAAAAAAAAAAAA')))
code = ox.toAZ(random.randint(ox.fromAZ('AAAAAAAAAAAAAAAA'),
ox.fromAZ('AAAAAAAAAAAAAAAAA')))
if models.UserProfile.objects.filter(reset_code=code).count() == 0:
break
user_profile = user.get_profile()
@ -320,7 +320,7 @@ def editUser(request):
'''
response = json_response()
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()
if 'disabled' in data:
user.is_active = not data['disabled']