Base views should take keyword arguments and should use them for URLs.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Tue, 01 Feb 2011 19:38:41 +0530
changeset 550 a606a40584f7
parent 549 3e8fc2ba0bde
child 551 208c4d591b55
Base views should take keyword arguments and should use them for URLs.
pytask/taskapp/views/task.py
pytask/taskapp/views/textbook.py
--- a/pytask/taskapp/views/task.py	Tue Feb 01 19:37:27 2011 +0530
+++ b/pytask/taskapp/views/task.py	Tue Feb 01 19:38:41 2011 +0530
@@ -5,6 +5,7 @@
 for everything else.
 """
 
+
 __authors__ = [
     '"Nishanth Amuluru" <nishanth@fossee.in>',
     '"Madhusudan.C.S" <madhusudancs@fossee.in>',
@@ -148,7 +149,9 @@
     # TODO(disable): Disable once the tasks can be claimed
     context['uberbar_message'] = DONT_CLAIM_TASK_MSG
 
-    task_url = reverse('view_task', kwargs={'task_id': task_id})
+    task_url = kwargs.get(
+      'task_url', reverse('view_task', kwargs={'task_id': task_id}))
+
     task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id)
 
     user = request.user
@@ -269,7 +272,7 @@
           'task/view.html', RequestContext(request, context))
 
 @login_required
-def edit_task(request, task_id):
+def edit_task(request, task_id, **kwargs):
     """ only creator gets to edit the task and that too only before it gets
     approved.
     """
@@ -277,7 +280,8 @@
     user = request.user
     profile = user.get_profile()
 
-    task_url = reverse('view_task', kwargs={'task_id': task_id})
+    task_url = kwargs.get(
+      'task_url', reverse('view_task', kwargs={'task_id': task_id}))
     task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id)
 
     is_creator = True if user == task.created_by else False
--- a/pytask/taskapp/views/textbook.py	Tue Feb 01 19:37:27 2011 +0530
+++ b/pytask/taskapp/views/textbook.py	Tue Feb 01 19:38:41 2011 +0530
@@ -308,7 +308,12 @@
     if chapter.parent.id != int(book_id):
         raise exceptions.PyTaskException(NOT_A_PARENT_FOR_CHAPTER)
 
-    return task_view.edit_task(request, chapter_id)
+    kwargs = {
+      'task_url': reverse(
+        'view_chapter', kwargs={'book_id': book_id, 'chapter_id': chapter_id})
+      }
+
+    return task_view.edit_task(request, chapter_id, **kwargs)
 
 
 def view_chapter(request, book_id, chapter_id,
@@ -329,7 +334,11 @@
       'edit_url': reverse('edit_chapter', kwargs={
         'book_id': book_id, 'chapter_id': chapter_id})
       }
-    kwargs = {'context': context}
+    kwargs = {
+      'context': context,
+      'task_url': reverse(
+        'view_chapter', kwargs={'book_id': book_id, 'chapter_id': chapter_id})
+      }
 
     return task_view.view_task(request, chapter_id, **kwargs)