# Path: pytask/taskapp/models.py
# class Task(models.Model):
# 
#     parent = models.ForeignKey('self', blank=True, null=True,
#                                related_name="children_tasks")
# 
#     title = models.CharField(
#       max_length=1024, verbose_name=u"Title",
#       help_text=u"Keep it simple and below 100 chars.")
# 
#     desc = models.TextField(verbose_name=u"Description")
# 
#     status = models.CharField(max_length=255,
#                               choices=TASK_STATUS_CHOICES,
#                               default="Unpublished")
# 
#     tags_field = TagField(
#       verbose_name=u"Tags", help_text=u"Give tags separated by commas. "
#       "The allowed characters are all alphabet, numbers, underscore(_), "
#       "period(.), forward slash(/), dash(-), ampersand(&), single quote(') "
#       " and space.")
# 
#     pynts = models.PositiveSmallIntegerField(
#       help_text=u"Number of Pynts a user gets on completing the task")
# 
#     created_by = models.ForeignKey(User,
#                                    related_name="created_tasks")
# 
#     approved_by = models.ForeignKey(User, blank=True, null=True,
#                                     related_name="approved_tasks")
# 
#     reviewers = models.ManyToManyField(User, blank=True, null=True,
#                                        related_name="reviewing_tasks")
# 
#     claimed_users = models.ManyToManyField(User, blank=True, null=True, 
#                                            related_name="claimed_tasks")
# 
#     selected_users = models.ManyToManyField(User, blank=True, null=True, 
#                                             related_name="selected_tasks")
# 
#     creation_datetime = models.DateTimeField(auto_now_add=True)
# 
#     approval_datetime = models.DateTimeField(blank=True, null=True)
# 
#     last_modified = models.DateTimeField(auto_now=True,
#                                          default=datetime.now())
# 
#     def __unicode__(self):
#         return unicode(self.title)


import csv
import datetime
import os
import sys
from django.contrib.auth.models import User
from pytask.taskapp.models import Task
    # branches/departments
    branch_name = os.extsep.join(file_name.split(os.extsep)[:-1])

    textbooks = []
    for line in csv_obj:
        if len(line) == 2 and line[0]:
            sep = ' by '
        else:
            sep = ''

        textbooks.append({
          'title': sep.join(line),
          'desc': '(To be filled in by the Coordinator or the T/A.)',
          'tags_field': ', '. join(['Textbook', branch_name, line[1]]),
          'pynts': 10,
          'status': 'Open',
          })

    return textbooks

def seed_db(data):
    """Seeds the database when the data is passed as the argument

    Args:
        data: A dictionary containing the data to be seeded into the
              task model.
    """

    for task in data:
        task.update(STATIC_DATA)

# Path: pytask/taskapp/models.py
# class Task(models.Model):
# 
#     parent = models.ForeignKey('self', blank=True, null=True,
#                                related_name="children_tasks")
# 
#     title = models.CharField(
#       max_length=1024, verbose_name=u"Title",
#       help_text=u"Keep it simple and below 100 chars.")
# 
#     desc = models.TextField(verbose_name=u"Description")
# 
#     status = models.CharField(max_length=255,
#                               choices=TASK_STATUS_CHOICES,
#                               default="Unpublished")
# 
#     tags_field = TagField(
#       verbose_name=u"Tags", help_text=u"Give tags separated by commas. "
#       "The allowed characters are all alphabet, numbers, underscore(_), "
#       "period(.), forward slash(/), dash(-), ampersand(&), single quote(') "
#       " and space.")
# 
#     pynts = models.PositiveSmallIntegerField(
#       help_text=u"Number of Pynts a user gets on completing the task")
# 
#     created_by = models.ForeignKey(User,
#                                    related_name="created_tasks")
# 
#     approved_by = models.ForeignKey(User, blank=True, null=True,
#                                     related_name="approved_tasks")
# 
#     reviewers = models.ManyToManyField(User, blank=True, null=True,
#                                        related_name="reviewing_tasks")
# 
#     claimed_users = models.ManyToManyField(User, blank=True, null=True, 
#                                            related_name="claimed_tasks")
# 
#     selected_users = models.ManyToManyField(User, blank=True, null=True, 
#                                             related_name="selected_tasks")
# 
#     creation_datetime = models.DateTimeField(auto_now_add=True)
# 
#     approval_datetime = models.DateTimeField(blank=True, null=True)
# 
#     last_modified = models.DateTimeField(auto_now=True,
#                                          default=datetime.now())
# 
#     def __unicode__(self):
#         return unicode(self.title)


# Path: scripts/generate_tasks_from_csv.py
import csv
import datetime
import os
import sys
from django.contrib.auth.models import User
from pytask.taskapp.models import Task

    # branches/departments
    branch_name = os.extsep.join(file_name.split(os.extsep)[:-1])

    textbooks = []
    for line in csv_obj:
        if len(line) == 2 and line[0]:
            sep = ' by '
        else:
            sep = ''

        textbooks.append({
          'title': sep.join(line),
          'desc': '(To be filled in by the Coordinator or the T/A.)',
          'tags_field': ', '. join(['Textbook', branch_name, line[1]]),
          'pynts': 10,
          'status': 'Open',
          })

    return textbooks

def seed_db(data):
    """Seeds the database when the data is passed as the argument

    Args:
        data: A dictionary containing the data to be seeded into the
              task model.
    """

    for task in data:
        task.update(STATIC_DATA)

        task_obj = Task(**task)