allow data-name attribute in texts and use for navigation

This commit is contained in:
j 2013-11-10 22:01:25 +00:00
commit dca703a4ee
7 changed files with 61 additions and 27 deletions

View file

@ -130,7 +130,7 @@ class Text(models.Model):
elif key == 'description':
self.description = ox.sanitize_html(data['description'])
elif key == 'text':
self.text = ox.sanitize_html(data['text'])
self.text = ox.sanitize_html(data['text'], global_attributes=['data-name'])
elif key == 'rightslevel':
self.rightslevel = int(data['rightslevel'])
@ -152,6 +152,7 @@ class Text(models.Model):
self.update_icon()
def json(self, keys=None, user=None):
default_keys = ['id']
if not keys:
keys=[
'description',
@ -165,7 +166,10 @@ class Text(models.Model):
'subscribed',
'text',
'type',
'user'
'user',
'uploaded',
'embeds',
'names',
]
response = {}
_map = {
@ -191,6 +195,10 @@ class Text(models.Model):
response['names'] = []
else:
response['names'] = re.compile('<[^<>]*?data-name="(.+?)"').findall(self.text)
for key in response.keys():
if key not in keys + default_keys:
del response[key]
return response
def path(self, name=''):

View file

@ -72,7 +72,8 @@ actions.register(addText, cache=False)
def getText(request):
'''
takes {
id: textid
id: textid,
keys: []
}
returns {
id:
@ -101,7 +102,7 @@ def getText(request):
text = None
response['status']['code'] = 404
if text:
response['data'] = text.json(user=request.user)
response['data'] = text.json(user=request.user, keys=data.get('keys'))
return render_to_json_response(response)
actions.register(getText)