forked from 0x2620/pandora
text.editable
This commit is contained in:
parent
94d4087aef
commit
32d7184758
1 changed files with 16 additions and 2 deletions
|
@ -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':
|
||||||
|
|
Loading…
Reference in a new issue