fix trivia links

This commit is contained in:
j 2016-09-05 18:32:50 +02:00
parent 9a53675b20
commit 98795d3a25
2 changed files with 19 additions and 17 deletions

View file

@ -131,21 +131,23 @@ class Imdb(models.Model):
def data(self, request=None, timeout=ox.cache.cache_timeout):
data = ox.web.imdb.Imdb(self.imdb, timeout=timeout)
data = self.apply_patch(data)
def fix_links(t):
def quote_string(string):
return quote(string).replace('_', '%09').replace('%20', '_')
def fix_names(m):
return '<a href="/name=%s">%s</a>' % (
quote_string(m.group(2).encode('utf-8')), m.group(2)
)
t = re.sub('<a href="(/name/.*?/)">(.*?)</a>', fix_names, t)
def fix_titles(m):
return '<a href="/title=%s">%s</a>' % (
quote_string(m.group(2).encode('utf-8')), m.group(2)
)
t = re.sub('<a href="(/title/.*?/)">(.*?)</a>', fix_titles, t)
def fix_links(t):
t = re.sub('<a href="(/name/.*?)">(.*?)</a>', fix_names, t)
t = re.sub('<a href="(/title/.*?)">(.*?)</a>', fix_titles, t)
return t
if 'trivia' in data:

View file

@ -15,7 +15,7 @@ def getId(request, data):
if movie:
response['data'] = movie.json()
else:
response['status'] = {'text':'not found', 'code': 404}
response['status'] = {'text': 'not found', 'code': 404}
return render_to_json_response(response)
actions.register(getId)
@ -35,7 +35,7 @@ def getData(request, data):
data = i.data(request)
response['data'] = data
else:
response['status'] = {'text':'not found', 'code': 404}
response['status'] = {'text': 'not found', 'code': 404}
return render_to_json_response(response)
actions.register(getData)