Initial tags for the chapters should not contain Textbook as the keyword.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Tue, 01 Feb 2011 02:31:53 +0530
changeset 540 b07d52d49db7
parent 539 59e032315ab9
child 541 a1007eb3fff9
Initial tags for the chapters should not contain Textbook as the keyword.
pytask/taskapp/views/textbook.py
pytask/taskapp/views/utils.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))
--- /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" <madhusudancs@fossee.in>',
+    ]
+
+
+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