Skip to content

Instantly share code, notes, and snippets.

@hassek
Created February 8, 2012 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hassek/1770504 to your computer and use it in GitHub Desktop.
Save hassek/1770504 to your computer and use it in GitHub Desktop.
def sender(request):
if not request.is_ajax():
raise Http404
#import ipdb; ipdb.set_trace()
images = Image.objects.filter(is_available=True).order_by('last_update')
if images:
image = images[0]
image.is_available = False
image.save()
if not request.user.is_anonymous():
UserImage(image=image, sender=request.user).save()
# List of functions to be executed
result = []
result.append(
{'selector': '#panel',
'content': render_response(request, "_sender.html", dict(image=image if image else '')).content,
'call_function': 'change_content'}
)
return HttpResponse(simplejson.dumps(result))
# ----------------------- JAVASCRIPT ---------------------- #
function process_callbacks(data){
for(var i=0;i<data.length;i++){
if($functions[data[i].call_function])
$functions[data[i].call_function](data[i].selector,data[i].content);
else
alert('Error, no existe '+data[i].call_function);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment