pytask/taskapp/views/textbook.py
changeset 540 b07d52d49db7
parent 538 478c7fc9a223
child 543 57b0f8f80ebf
equal deleted inserted replaced
539:59e032315ab9 540:b07d52d49db7
    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.utils import get_intial_tags_for_chapter
    30 
    31 
    31 
    32 
    32 DONT_CLAIM_TASK_MSG = ugettext(
    33 DONT_CLAIM_TASK_MSG = ugettext(
    33   "Please don't submit any claims for the tasks until the workshop is "
    34   "Please don't submit any claims for the tasks until the workshop is "
    34   "over. During the workshop we will introduce you to the work-flow of "
    35   "over. During the workshop we will introduce you to the work-flow of "
   260       }
   261       }
   261 
   262 
   262     context.update(csrf(request))
   263     context.update(csrf(request))
   263 
   264 
   264     textbook = shortcuts.get_object_or_404(taskapp_models.Task, pk=book_id)
   265     textbook = shortcuts.get_object_or_404(taskapp_models.Task, pk=book_id)
   265     initial_tags = ', '.join([textbook.tags_field] + ['Chapter'])
       
   266 
   266 
   267     if request.method == 'POST':
   267     if request.method == 'POST':
   268         form = taskapp_forms.CreateChapterForm(request.POST)
   268         form = taskapp_forms.CreateChapterForm(request.POST)
   269         if form.is_valid():
   269         if form.is_valid():
   270             data = form.cleaned_data.copy()
   270             data = form.cleaned_data.copy()
   287             context.update({"form": form})
   287             context.update({"form": form})
   288             return shortcuts.render_to_response(
   288             return shortcuts.render_to_response(
   289               template, RequestContext(request, context))
   289               template, RequestContext(request, context))
   290     else:
   290     else:
   291         form = taskapp_forms.CreateChapterForm(
   291         form = taskapp_forms.CreateChapterForm(
   292           initial={'tags_field': initial_tags})
   292           initial={'tags_field': get_intial_tags_for_chapter(textbook)})
   293         context.update({'form': form})
   293         context.update({'form': form})
   294         return shortcuts.render_to_response(
   294         return shortcuts.render_to_response(
   295           template, RequestContext(request, context))
   295           template, RequestContext(request, context))
   296 
   296 
   297 @login_required
   297 @login_required