scripts/utils.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Tue, 01 Feb 2011 02:14:49 +0530
changeset 539 59e032315ab9
parent 535 d90684a803c1
permissions -rw-r--r--
Add exception middleware and related files.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
535
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
"""Helper script that contains many utilities.
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
"""
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
__authors__ = [
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
  '"Madhusudan.C.S" <madhusudancs@gmail.com>',
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
  ]
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
from tagging.managers import TaggedItem
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    12
from pytask.taskapp.models import Task
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    15
def remove_textbook_from_chapter():
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
    """Removes the tag Textbook from Chapter.
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
    """
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    18
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
    tasks = TaggedItem.objects.get_by_model(Task, 'Chapter')
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    20
    for task in tasks:
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    21
        tags = task.tags_field.split(',')
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    22
        retags = []
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    23
        for tag in tags:
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    24
            if 'Textbook' not in tag:
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
                retags.append(tag)
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
        task.tags_field = ', '.join(retags)
d90684a803c1 Add a utility script with a function to remove Textbook from current textbook chapter tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
        task.save()