diff options
author | Dusty Phillips <buchuki@gmail.com> | 2008-06-27 21:07:10 -0400 |
---|---|---|
committer | Dusty Phillips <buchuki@gmail.com> | 2008-06-27 21:07:10 -0400 |
commit | 6b013d99fcfb596cbbdfb53fa03a07888dde1e9b (patch) | |
tree | 5143e5b28ce3494e968bf76aba7aa67436aab2fb | |
parent | 28464f50f4ab1b6ad9ce834f405dd9bad7519acf (diff) |
add an 'edit todolist' functionality
-rw-r--r-- | templates/todolists/view.html | 5 | ||||
-rw-r--r-- | todolists/views.py | 32 | ||||
-rw-r--r-- | urls.py | 9 |
3 files changed, 42 insertions, 4 deletions
diff --git a/templates/todolists/view.html b/templates/todolists/view.html index 02c228e4..9e9acbaf 100644 --- a/templates/todolists/view.html +++ b/templates/todolists/view.html @@ -32,6 +32,11 @@ {% endblock %} {% block content %} <div class="greybox"> + {% if perms.todolists.change_todolist %} + <div style="float:right"> + <a href="/todo/edit/{{list.id}}?">Edit Todo List</a> + </div> + {% endif %} <h2 class="title">ToDo List: {{ list.name }}</h2> <table id="todotable" class="results" width="100%"> <thead> diff --git a/todolists/views.py b/todolists/views.py index dc1a9aa7..127fd8b8 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: @@ -15,10 +15,11 @@ urlpatterns = patterns('', (r'^packages/(?P<repo>[A-z0-9]+)/(?P<name>[A-z0-9]+)/$', 'archweb_dev.packages.views.details'), (r'^packages/$', 'archweb_dev.packages.views.search'), - (r'^todo/(\d+)/$', 'archweb_dev.todolists.views.view'), - (r'^todo/add/$', 'archweb_dev.todolists.views.add'), - (r'^todo/flag/(\d+)/(\d+)/$', 'archweb_dev.todolists.views.flag'), - (r'^todo/$', 'archweb_dev.todolists.views.list'), + (r'^todo/(\d+)/$', 'archweb_dev.todolists.views.view'), + (r'^todo/add/$', 'archweb_dev.todolists.views.add'), + (r'^todo/edit/(?P<list_id>\d+)/$', 'archweb_dev.todolists.views.edit'), + (r'^todo/flag/(\d+)/(\d+)/$', 'archweb_dev.todolists.views.flag'), + (r'^todo/$', 'archweb_dev.todolists.views.list'), (r'^news/(\d+)/$', 'archweb_dev.news.views.view'), (r'^news/add/$', 'archweb_dev.news.views.add'), |