Add a utility script with a function to remove Textbook from current textbook chapter tasks.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Tue, 01 Feb 2011 02:03:54 +0530
changeset 535 d90684a803c1
parent 534 9627f119f14e
child 536 03164bb5b52d
Add a utility script with a function to remove Textbook from current textbook chapter tasks.
scripts/utils.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/utils.py	Tue Feb 01 02:03:54 2011 +0530
@@ -0,0 +1,27 @@
+"""Helper script that contains many utilities.
+"""
+
+
+__authors__ = [
+  '"Madhusudan.C.S" <madhusudancs@gmail.com>',
+  ]
+
+
+from tagging.managers import TaggedItem
+
+from pytask.taskapp.models import Task
+
+
+def remove_textbook_from_chapter():
+    """Removes the tag Textbook from Chapter.
+    """
+
+    tasks = TaggedItem.objects.get_by_model(Task, 'Chapter')
+    for task in tasks:
+        tags = task.tags_field.split(',')
+        retags = []
+        for tag in tags:
+            if 'Textbook' not in tag:
+                retags.append(tag)
+        task.tags_field = ', '.join(retags)
+        task.save()