ajax_request def add_movie request from django forms util import Error

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
@ajax_request
def add_movie(request):
from django.forms.util import ErrorDict
if 'as_json' not in ErrorDict.__dict__:
from lib.ajax import as_json
ErrorDict.as_json = as_json
form = UrlForm(request, request.POST)
is_profile = request.POST['is_profile']
check = lambda x: "" if int(is_profile) else x
watch = lambda x: u"посмотрел" if x else u"посмотрела"
if form.is_valid():
seen = form.save()
if seen.like:
html = u"<li><span class='left_block'><span class='date'><span class='tl'><span class='tr'><span class='bl'><span class='br'>%s</span></span></span></span></span><a href='/users/%s/'>%s</a> %s <a href='http://www.imdb.com/title/%s/' class='f-name'>%s</a></span><span class='love'><span class='tl'><span class='tr'><span class='bl'><span class='br'>%s</span></span></span></span></span></li>" % (seen.date.strftime("%d %b"), seen.profile.username, check(seen.profile.username), watch(seen.profile.gender), seen.movie.imdb, seen.movie.title, u"понравилось")
else:
html = u"<li><span class='left_block'><span class='date'><span class='tl'><span class='tr'><span class='bl'><span class='br'>%s</span></span></span></span></span><a href='/users/%s/'>%s</a> %s <a href='http://www.imdb.com/title/%s/' class='f-name'>%s</a></span><span class='hate'><span class='tl'><span class='tr'><span class='bl'><span class='br'>%s</span></span></span></span></span></li>" % (seen.date.strftime("%d %b"), seen.profile.username, check(seen.profile.username), watch(seen.profile.gender), seen.movie.imdb, seen.movie.title, u"не понравилось")
return {'html': html}
else:
return form.errors.as_json()