pytask/taskapp/views/textbook.py
changeset 543 57b0f8f80ebf
parent 540 b07d52d49db7
child 550 a606a40584f7
equal deleted inserted replaced
542:23bf9b4611cb 543:57b0f8f80ebf
    19 from django.template import RequestContext
    19 from django.template import RequestContext
    20 from django.utils.translation import ugettext
    20 from django.utils.translation import ugettext
    21 
    21 
    22 from tagging.managers import TaggedItem
    22 from tagging.managers import TaggedItem
    23 
    23 
    24 from pytask.helpers.exceptions import UnauthorizedAccess
    24 from pytask.helpers import exceptions
    25 
    25 
    26 from pytask.profile import models as profile_models
    26 from pytask.profile import models as profile_models
    27 
    27 
    28 from pytask.taskapp import forms as taskapp_forms
    28 from pytask.taskapp import forms as taskapp_forms
    29 from pytask.taskapp import models as taskapp_models
    29 from pytask.taskapp import models as taskapp_models
       
    30 from pytask.taskapp.views import task as task_view
    30 from pytask.taskapp.views.utils import get_intial_tags_for_chapter
    31 from pytask.taskapp.views.utils import get_intial_tags_for_chapter
    31 
    32 
    32 
    33 
    33 DONT_CLAIM_TASK_MSG = ugettext(
    34 DONT_CLAIM_TASK_MSG = ugettext(
    34   "Please don't submit any claims for the tasks until the workshop is "
    35   "Please don't submit any claims for the tasks until you get an email "
    35   "over. During the workshop we will introduce you to the work-flow of "
    36   "to start claiming tasks. Please be warned that the task claim work-"
    36   "this entire project. Also please be warned that the task claim work-"
       
    37   "flow may change. So all the claims submitted before the workshop may "
    37   "flow may change. So all the claims submitted before the workshop may "
    38   "not be valid.")
    38   "not be valid.")
    39 
    39 
    40 NO_EDIT_RIGHT = ugettext(
    40 NO_EDIT_RIGHT = ugettext(
    41   "You are not authorized to edit this page.")
    41   "You are not authorized to edit this page.")
       
    42 
       
    43 NOT_A_PARENT_FOR_CHAPTER = ugettext(
       
    44   "There is an error in your request. The chapter you are requesting is "
       
    45   "does not belong to the textbook you have requested.")
    42 
    46 
    43 
    47 
    44 @login_required
    48 @login_required
    45 def create_textbook(request):
    49 def create_textbook(request):
    46 
    50 
   208         can_edit = True
   212         can_edit = True
   209     else:
   213     else:
   210         can_edit = False
   214         can_edit = False
   211 
   215 
   212     if not can_edit:
   216     if not can_edit:
   213         raise UnauthorizedAccess(NO_EDIT_RIGHT)
   217         raise exceptions.UnauthorizedAccess(NO_EDIT_RIGHT)
   214 
   218 
   215     context = {
   219     context = {
   216       'user': user,
   220       'user': user,
   217       'profile': profile,
   221       'profile': profile,
   218       'textbook': textbook,
   222       'textbook': textbook,
   293         context.update({'form': form})
   297         context.update({'form': form})
   294         return shortcuts.render_to_response(
   298         return shortcuts.render_to_response(
   295           template, RequestContext(request, context))
   299           template, RequestContext(request, context))
   296 
   300 
   297 @login_required
   301 @login_required
       
   302 def edit_chapter(request, book_id, chapter_id,
       
   303                  template='task/chapter_edit.html'):
       
   304     """View function that lets edit chapters from textbooks.
       
   305     """
       
   306     chapter = shortcuts.get_object_or_404(taskapp_models.Task, pk=chapter_id)
       
   307 
       
   308     if chapter.parent.id != int(book_id):
       
   309         raise exceptions.PyTaskException(NOT_A_PARENT_FOR_CHAPTER)
       
   310 
       
   311     return task_view.edit_task(request, chapter_id)
       
   312 
       
   313 
       
   314 def view_chapter(request, book_id, chapter_id,
       
   315                  template='task/chapter_edit.html'):
       
   316     """View that displays the chapter of the textbook.
       
   317 
       
   318     Args:
       
   319         book_id: the id of the book to which this chapter belongs.
       
   320         chapter_id: id of the chapter that must be displayed.
       
   321     """
       
   322 
       
   323     chapter = shortcuts.get_object_or_404(taskapp_models.Task, pk=chapter_id)
       
   324 
       
   325     if chapter.parent.id != int(book_id):
       
   326         raise exceptions.PyTaskException(NOT_A_PARENT_FOR_CHAPTER)
       
   327 
       
   328     context = {
       
   329       'edit_url': reverse('edit_chapter', kwargs={
       
   330         'book_id': book_id, 'chapter_id': chapter_id})
       
   331       }
       
   332     kwargs = {'context': context}
       
   333 
       
   334     return task_view.view_task(request, chapter_id, **kwargs)
       
   335 
       
   336 @login_required
   298 def approve_textbook(request, task_id):
   337 def approve_textbook(request, task_id):
   299 
   338 
   300     user = request.user
   339     user = request.user
   301     profile = user.get_profile()
   340     profile = user.get_profile()
   302 
   341