summaryrefslogtreecommitdiff
path: root/todolists
diff options
context:
space:
mode:
authorEvangelos Foutras <foutrelis@gmail.com>2010-02-07 17:38:48 +0200
committerDan McGee <dan@archlinux.org>2010-02-26 21:03:09 -0600
commitce0b9076ee149d139b16d978b31c9db56db9fbea (patch)
treecd677cd828d2a0738c8c2724edda42e6b0efde16 /todolists
parentd5fe951cdcce5af05171a5a2d0bbd5a6cec1f597 (diff)
Implement AJAX flagging for todo items
[Some trailing whitespace got killed in the process. :3] Dan: I made a few small changes including moving the jQuery include down above the other script block; since it is not needed right away it can be loaded later in the page. Signed-off-by: Evangelos Foutras <foutrelis@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'todolists')
-rw-r--r--todolists/views.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/todolists/views.py b/todolists/views.py
index 9ebe6f3a..a38ec0d7 100644
--- a/todolists/views.py
+++ b/todolists/views.py
@@ -1,12 +1,14 @@
from django import forms
-from django.http import HttpResponseRedirect
+from django.http import HttpResponse, HttpResponseRedirect
from django.template import RequestContext
from django.core.mail import send_mail
from django.shortcuts import get_object_or_404, render_to_response
from django.contrib.auth.decorators import login_required, permission_required
from django.views.generic.create_update import delete_object
from django.template import Context, loader
+from django.utils import simplejson
+
from main.models import Todolist, TodolistPkg, Package
class TodoListForm(forms.Form):
@@ -19,7 +21,7 @@ class TodoListForm(forms.Form):
widget=forms.Textarea(attrs={'rows': '20', 'cols': '60'}))
def clean_packages(self):
- package_names = [s.strip() for s in
+ package_names = [s.strip() for s in
self.cleaned_data['packages'].split("\n")]
package_names = set(package_names)
packages = Package.objects.filter(
@@ -34,12 +36,16 @@ def flag(request, listid, pkgid):
pkg = get_object_or_404(TodolistPkg, id=pkgid)
pkg.complete = not pkg.complete
pkg.save()
+ if request.is_ajax():
+ return HttpResponse(
+ simplejson.dumps({'complete': pkg.complete}),
+ mimetype='application/json')
return HttpResponseRedirect('/todo/%s/' % (listid))
@login_required
def view(request, listid):
list = get_object_or_404(Todolist, id=listid)
- return render_to_response('todolists/view.html',
+ return render_to_response('todolists/view.html',
RequestContext(request, {'list':list}))
@login_required
@@ -134,8 +140,8 @@ def send_todolist_email(todo):
}
t = loader.get_template('todolists/addedtotodolist')
c = Context(page_dict)
- send_mail('arch: Package [%s] added to Todolist' % todo.pkg.pkgname,
- t.render(c),
+ send_mail('arch: Package [%s] added to Todolist' % todo.pkg.pkgname,
+ t.render(c),
'Arch Website Notification <nobody@archlinux.org>',
[todo.pkg.maintainer.email],
fail_silently=True)
@@ -143,4 +149,3 @@ def send_todolist_email(todo):
# vim: set ts=4 sw=4 et:
-