# HG changeset patch # User Madhusudan.C.S # Date 1296515045 -19800 # Node ID 57b0f8f80ebf129b051ed7087410e2611b759e9f # Parent 23bf9b4611cb18d4d4a9dc02d57929f897f7ca96 Add edit and view chapters views. diff -r 23bf9b4611cb -r 57b0f8f80ebf pytask/taskapp/urls.py --- a/pytask/taskapp/urls.py Tue Feb 01 04:33:35 2011 +0530 +++ b/pytask/taskapp/urls.py Tue Feb 01 04:34:05 2011 +0530 @@ -39,4 +39,10 @@ name='browse_textbooks'), url(r'^textbook/chapter/create/(?P\d+)$', 'create_chapter', name='create_chapter'), + url(r'^textbook/chapter/edit/(?P\d+)/(?P\d+)$', + 'edit_chapter', + name='edit_chapter'), + url(r'^textbook/chapter/view/(?P\d+)/(?P\d+)$', + 'view_chapter', + name='view_chapter'), ) diff -r 23bf9b4611cb -r 57b0f8f80ebf pytask/taskapp/views/task.py --- a/pytask/taskapp/views/task.py Tue Feb 01 04:33:35 2011 +0530 +++ b/pytask/taskapp/views/task.py Tue Feb 01 04:34:05 2011 +0530 @@ -25,6 +25,7 @@ from tagging.models import Tag +from pytask.helpers import exceptions from pytask.views import show_msg from pytask.profile import models as profile_models @@ -34,12 +35,14 @@ DONT_CLAIM_TASK_MSG = ugettext( - "Please don't submit any claims for the tasks until the workshop is " - "over. During the workshop we will introduce you to the work-flow of " - "this entire project. Also please be warned that the task claim work-" + "Please don't submit any claims for the tasks until you get an email " + "to start claiming tasks. Please be warned that the task claim work-" "flow may change. So all the claims submitted before the workshop may " "not be valid.") +NO_EDIT_RIGHT = ugettext( + "You are not authorized to edit this page.") + @login_required def create_task(request): @@ -130,13 +133,17 @@ RequestContext(request, context)) -def view_task(request, task_id): - """ get the task depending on its task_id and display accordingly if it is a get. - check for authentication and add a comment if it is a post request. +def view_task(request, task_id, **kwargs): + """View to get the requested. + + Checks for authentication and add a comment if it is a post request. """ context = {} + if 'context' in kwargs: + context.update(kwargs['context']) + # TODO(disable): Disable once the tasks can be claimed context['uberbar_message'] = DONT_CLAIM_TASK_MSG @@ -199,7 +206,8 @@ context['can_approve'] = False if ((is_creator or user_role != profile_models.ROLES_CHOICES[3][0]) - and task.status == taskapp_models.TASK_STATUS_CHOICES[0][0]): + and task.status in [taskapp_models.TASK_STATUS_CHOICES[0][0], + taskapp_models.TASK_STATUS_CHOICES[1][0]]): context['can_edit'] = True else: context['can_edit'] = False @@ -272,9 +280,16 @@ task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) is_creator = True if user == task.created_by else False - can_edit = True if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] and is_creator else False + + if ((is_creator or profile.role != profile_models.ROLES_CHOICES[3][0]) + and task.status in [taskapp_models.TASK_STATUS_CHOICES[0][0], + taskapp_models.TASK_STATUS_CHOICES[1][0]]): + can_edit = True + else: + can_edit = False + if not can_edit: - raise http.Http404 + raise exceptions.UnauthorizedAccess(NO_EDIT_RIGHT) context = {"user": user, "profile": profile, diff -r 23bf9b4611cb -r 57b0f8f80ebf pytask/taskapp/views/textbook.py --- a/pytask/taskapp/views/textbook.py Tue Feb 01 04:33:35 2011 +0530 +++ b/pytask/taskapp/views/textbook.py Tue Feb 01 04:34:05 2011 +0530 @@ -21,25 +21,29 @@ from tagging.managers import TaggedItem -from pytask.helpers.exceptions import UnauthorizedAccess +from pytask.helpers import exceptions from pytask.profile import models as profile_models from pytask.taskapp import forms as taskapp_forms from pytask.taskapp import models as taskapp_models +from pytask.taskapp.views import task as task_view from pytask.taskapp.views.utils import get_intial_tags_for_chapter DONT_CLAIM_TASK_MSG = ugettext( - "Please don't submit any claims for the tasks until the workshop is " - "over. During the workshop we will introduce you to the work-flow of " - "this entire project. Also please be warned that the task claim work-" + "Please don't submit any claims for the tasks until you get an email " + "to start claiming tasks. Please be warned that the task claim work-" "flow may change. So all the claims submitted before the workshop may " "not be valid.") NO_EDIT_RIGHT = ugettext( "You are not authorized to edit this page.") +NOT_A_PARENT_FOR_CHAPTER = ugettext( + "There is an error in your request. The chapter you are requesting is " + "does not belong to the textbook you have requested.") + @login_required def create_textbook(request): @@ -210,7 +214,7 @@ can_edit = False if not can_edit: - raise UnauthorizedAccess(NO_EDIT_RIGHT) + raise exceptions.UnauthorizedAccess(NO_EDIT_RIGHT) context = { 'user': user, @@ -295,6 +299,41 @@ template, RequestContext(request, context)) @login_required +def edit_chapter(request, book_id, chapter_id, + template='task/chapter_edit.html'): + """View function that lets edit chapters from textbooks. + """ + chapter = shortcuts.get_object_or_404(taskapp_models.Task, pk=chapter_id) + + if chapter.parent.id != int(book_id): + raise exceptions.PyTaskException(NOT_A_PARENT_FOR_CHAPTER) + + return task_view.edit_task(request, chapter_id) + + +def view_chapter(request, book_id, chapter_id, + template='task/chapter_edit.html'): + """View that displays the chapter of the textbook. + + Args: + book_id: the id of the book to which this chapter belongs. + chapter_id: id of the chapter that must be displayed. + """ + + chapter = shortcuts.get_object_or_404(taskapp_models.Task, pk=chapter_id) + + if chapter.parent.id != int(book_id): + raise exceptions.PyTaskException(NOT_A_PARENT_FOR_CHAPTER) + + context = { + 'edit_url': reverse('edit_chapter', kwargs={ + 'book_id': book_id, 'chapter_id': chapter_id}) + } + kwargs = {'context': context} + + return task_view.view_task(request, chapter_id, **kwargs) + +@login_required def approve_textbook(request, task_id): user = request.user diff -r 23bf9b4611cb -r 57b0f8f80ebf pytask/templates/task/view.html --- a/pytask/templates/task/view.html Tue Feb 01 04:33:35 2011 +0530 +++ b/pytask/templates/task/view.html Tue Feb 01 04:34:05 2011 +0530 @@ -15,7 +15,13 @@

{{ task.title }}

{% if can_edit %} - Edit task + {% if edit_url %} + + {% else %} + + {% endif %} + Edit task + {% endif %} {% if can_approve %}