diff options
author | Dusty Phillips <buchuki@gmail.com> | 2008-06-28 03:07:10 +0200 |
---|---|---|
committer | Dusty Phillips <buchuki@gmail.com> | 2008-06-28 03:07:10 +0200 |
commit | 6b013d99fcfb596cbbdfb53fa03a07888dde1e9b (patch) | |
tree | 5143e5b28ce3494e968bf76aba7aa67436aab2fb /todolists | |
parent | 28464f50f4ab1b6ad9ce834f405dd9bad7519acf (diff) | |
download | archweb-6b013d99fcfb596cbbdfb53fa03a07888dde1e9b.tar.gz archweb-6b013d99fcfb596cbbdfb53fa03a07888dde1e9b.tar.xz |
add an 'edit todolist' functionality
Diffstat (limited to 'todolists')
-rw-r--r-- | todolists/views.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/todolists/views.py b/todolists/views.py index dc1a9aa..127fd8b 100644 --- a/todolists/views.py +++ b/todolists/views.py @@ -75,5 +75,37 @@ def add(request): } return render_response(request, 'general_form.html', page_dict) +@permission_required('todolists.change_todolist') +def edit(request, list_id): + todo_list = get_object_or_404(Todolist, id=list_id) + if request.POST: + form = TodoListForm(request.POST) + if form.is_valid(): + todo_list.name = form.clean_data['name'] + todo_list.description = form.clean_data['description'] + todo_list.save() + + packages = [p.pkg for p in todo_list.packages] + + for pkg in form.clean_data['packages']: + if pkg not in packages: + TodolistPkg.objects.create(list = todo_list, pkg = pkg) + + return HttpResponseRedirect('/todo/%d/' % todo_list.id) + else: + form = TodoListForm(initial={ + 'name': todo_list.name, + 'description': todo_list.description, + 'packages': todo_list.package_names, + }) + page_dict = { + 'title': 'Edit To-do List "%s"' % todo_list.name, + 'form': form, + 'submit_text': 'Save List' + } + return render_response(request, 'general_form.html', page_dict) + + + # vim: set ts=4 sw=4 et: |