summaryrefslogtreecommitdiffstats
path: root/hyperkitty/views/thread.py
diff options
context:
space:
mode:
authorAurélien Bompard <aurelien@bompard.org>2012-12-10 12:25:38 +0100
committerAurélien Bompard <aurelien@bompard.org>2012-12-10 12:25:38 +0100
commit6ea042ab3c6310bb87cb01041656e6928a163a5f (patch)
treea191c3d7dbd9de77f7b24c69b31bbb9af0eadbf1 /hyperkitty/views/thread.py
parent1efaf31a907aa42fc0b01029d332f539b2067a75 (diff)
downloadhyperkitty-6ea042ab3c6310bb87cb01041656e6928a163a5f.tar.gz
hyperkitty-6ea042ab3c6310bb87cb01041656e6928a163a5f.tar.xz
hyperkitty-6ea042ab3c6310bb87cb01041656e6928a163a5f.zip
Don't reload the page when adding tags or liking stuff
Diffstat (limited to 'hyperkitty/views/thread.py')
-rw-r--r--hyperkitty/views/thread.py46
1 files changed, 27 insertions, 19 deletions
diff --git a/hyperkitty/views/thread.py b/hyperkitty/views/thread.py
index ec5a60f..1375d9f 100644
--- a/hyperkitty/views/thread.py
+++ b/hyperkitty/views/thread.py
@@ -90,7 +90,7 @@ def thread_index(request, mlist_fqdn, threadid):
tag_form = AddTagForm(initial={'from_url' : from_url})
try:
- tags = Tag.objects.filter(threadid=threadid)
+ tags = Tag.objects.filter(threadid=threadid, list_address=mlist_fqdn)
except Tag.DoesNotExist:
tags = {}
@@ -124,28 +124,36 @@ def thread_index(request, mlist_fqdn, threadid):
return HttpResponse(t.render(c))
-def add_tag(request, mlist_fqdn, email_id):
+def add_tag(request, mlist_fqdn, hashid):
""" Add a tag to a given thread. """
if not request.user.is_authenticated():
return HttpResponse('You must be logged in to add a tag',
content_type="text/plain", status=403)
- if request.method == 'POST':
- form = AddTagForm(request.POST)
- if form.is_valid():
- print "Adding tag..."
+ if request.method != 'POST':
+ return HttpResponse("Something went wrong here",
+ content_type="text/plain", status=500)
- tag = form.data['tag']
-
- try:
- tag_obj = Tag.objects.get(threadid=email_id, list_address=mlist_fqdn, tag=tag)
- except Tag.DoesNotExist:
- tag_obj = Tag(list_address=mlist_fqdn, threadid=email_id, tag=tag)
-
- tag_obj.save()
- response_dict = { }
- else:
- response_dict = {'error' : 'Error adding tag, enter valid data' }
-
- return HttpResponse(simplejson.dumps(response_dict), mimetype='application/javascript')
+ form = AddTagForm(request.POST)
+ if not form.is_valid():
+ return HttpResponse("Error adding tag: invalid data",
+ content_type="text/plain", status=500)
+ tag = form.data['tag']
+ try:
+ tag_obj = Tag.objects.get(threadid=hashid,
+ list_address=mlist_fqdn, tag=tag)
+ except Tag.DoesNotExist:
+ tag_obj = Tag(list_address=mlist_fqdn, threadid=hashid, tag=tag)
+ tag_obj.save()
+
+ # Now refresh the tag list
+ tags = Tag.objects.filter(threadid=hashid, list_address=mlist_fqdn)
+ t = loader.get_template('threads/tags.html')
+ html = t.render(RequestContext(request, {
+ "tags": tags,
+ "list_address": mlist_fqdn}))
+
+ response = {"tags": [ t.tag for t in tags ], "html": html}
+ return HttpResponse(simplejson.dumps(response),
+ mimetype='application/javascript')