text.editable

This commit is contained in:
j 2013-02-21 12:15:20 +00:00
parent 94d4087aef
commit 32d7184758

View file

@ -62,7 +62,7 @@ class Text(models.Model):
return self.user == user or self.status in ('public', 'featured') return self.user == user or self.status in ('public', 'featured')
def editable(self, user): def editable(self, user):
if user.is_anonymous(): if not user or user.is_anonymous():
return False return False
if self.user == user or \ if self.user == user or \
user.is_staff or \ user.is_staff or \
@ -144,7 +144,19 @@ class Text(models.Model):
def json(self, keys=None, user=None): def json(self, keys=None, user=None):
if not keys: if not keys:
keys=['id', 'name', 'user', 'status', 'subscribed', 'posterFrames', 'description', 'text', 'type', 'links'] keys=[
'description',
'editable',
'id',
'links',
'name',
'posterFrames',
'status',
'subscribed',
'text',
'type',
'user'
]
response = {} response = {}
_map = { _map = {
'posterFrames': 'poster_frames' 'posterFrames': 'poster_frames'
@ -152,6 +164,8 @@ class Text(models.Model):
for key in keys: for key in keys:
if key == 'id': if key == 'id':
response[key] = self.get_id() response[key] = self.get_id()
elif key == 'editable':
response[key] = self.editable(user)
elif key == 'user': elif key == 'user':
response[key] = self.user.username response[key] = self.user.username
elif key == 'subscribers': elif key == 'subscribers':