summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--templates/todolists/view.html21
-rw-r--r--todolists/views.py17
2 files changed, 32 insertions, 6 deletions
diff --git a/templates/todolists/view.html b/templates/todolists/view.html
index ce191fba..b85a4266 100644
--- a/templates/todolists/view.html
+++ b/templates/todolists/view.html
@@ -1,4 +1,5 @@
{% extends "base.html" %}
+
{% block content %}
<div class="greybox">
<div style="float:right">
@@ -44,4 +45,24 @@
{{list.description|linebreaks}}
</div>
</div>
+
+ <script type="text/javascript" src="/media/jquery-1.4.1.min.js"></script>
+ <script type="text/javascript">
+ $(function() {
+ // Allow flagging of ToDo items using AJAX
+ $('a[href*=todo/flag]').click(function() {
+ var link = this;
+
+ $.getJSON(link.href, function(data) {
+ if (data.complete) {
+ $(link).text('Complete').css('color', 'blue');
+ } else {
+ $(link).text('Incomplete').css('color', 'red');
+ }
+ });
+
+ return false;
+ });
+ });
+ </script>
{% endblock %}
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:
-