# HG changeset patch # User Madhusudan.C.S # Date 1296507713 -19800 # Node ID b07d52d49db776b14d3227bf75e00025011ad52e # Parent 59e032315ab92ab558ffc276552ccbaf1ea032a6 Initial tags for the chapters should not contain Textbook as the keyword. diff -r 59e032315ab9 -r b07d52d49db7 pytask/taskapp/views/textbook.py --- a/pytask/taskapp/views/textbook.py Tue Feb 01 02:14:49 2011 +0530 +++ b/pytask/taskapp/views/textbook.py Tue Feb 01 02:31:53 2011 +0530 @@ -27,6 +27,7 @@ from pytask.taskapp import forms as taskapp_forms from pytask.taskapp import models as taskapp_models +from pytask.taskapp.views.utils import get_intial_tags_for_chapter DONT_CLAIM_TASK_MSG = ugettext( @@ -262,7 +263,6 @@ context.update(csrf(request)) textbook = shortcuts.get_object_or_404(taskapp_models.Task, pk=book_id) - initial_tags = ', '.join([textbook.tags_field] + ['Chapter']) if request.method == 'POST': form = taskapp_forms.CreateChapterForm(request.POST) @@ -289,7 +289,7 @@ template, RequestContext(request, context)) else: form = taskapp_forms.CreateChapterForm( - initial={'tags_field': initial_tags}) + initial={'tags_field': get_intial_tags_for_chapter(textbook)}) context.update({'form': form}) return shortcuts.render_to_response( template, RequestContext(request, context)) diff -r 59e032315ab9 -r b07d52d49db7 pytask/taskapp/views/utils.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pytask/taskapp/views/utils.py Tue Feb 01 02:31:53 2011 +0530 @@ -0,0 +1,26 @@ +"""Module containing taskapp views specific utility functions +""" + +__authors__ = [ + '"Madhusudan.C.S" ', + ] + + +def get_intial_tags_for_chapter(textbook): + """Returns the initial tag set for chapter/module for the textbook. + + Args: + textbook: textbook entity for which the tags should be built. + """ + + tags1=textbook.tags_field + tags = textbook.tags_field.split(',') + rebuild_tags = [] + for tag in tags: + tag.strip() + if 'Textbook' not in tag: + rebuild_tags.append(tag) + + initial_tags = ', '.join(rebuild_tags + ['Chapter']) + + return initial_tags \ No newline at end of file