taskapp/events/task.py
changeset 119 39ab7c460143
parent 117 58fa1d626d37
child 120 aad4e6065d85
equal deleted inserted replaced
118:5bbb29a07b87 119:39ab7c460143
     1 from datetime import datetime
     1 from datetime import datetime
     2 from pytask.taskapp.models import Profile, Task, Comment, Credit, Claim, Map
     2 from pytask.taskapp.models import Profile, Task, Comment, Credit, Claim, Map
     3 from pytask.taskapp.utilities.request import create_request
     3 from pytask.taskapp.utilities.request import create_request
       
     4 from pytask.taskapp.utilities.helper import get_key
     4 
     5 
     5 def publishTask(task, rem_mentors=True, rem_comments=True):
     6 def publishTask(task, rem_mentors=True, rem_comments=True):
     6     """ set the task status to open """
     7     """ set the task status to open """
     7 
     8 
     8     if task.sub_type == 'D':
     9     if task.sub_type == 'D':
    93 def addMentor(task,mentor):
    94 def addMentor(task,mentor):
    94     """ add the mentor to mentors list of the task """
    95     """ add the mentor to mentors list of the task """
    95     
    96     
    96     task.mentors.add(mentor)
    97     task.mentors.add(mentor)
    97     task.save()
    98     task.save()
    98     return task    
    99     return task     
    99     
   100 
       
   101 
       
   102 
   100 def createTask(title,desc,created_by,credits):
   103 def createTask(title,desc,created_by,credits):
   101     """ creates a bare minimum task with title, description and credits.
   104     """ creates a bare minimum task with title, description and credits.
   102     the creator of the task will be assigned as a mentor for the task.
   105     the creator of the task will be assigned as a mentor for the task.
   103     """
   106     """
   104 
   107 
       
   108     while True:
       
   109         id = get_key()
       
   110         try:
       
   111             task = Task.objects.get(id__iexact=id)
       
   112             continue
       
   113         except Task.DoesNotExist:
       
   114             break
       
   115 
   105     try:
   116     try:
   106         task = Task.objects.get(title__iexact=title)
   117         task = Task.objects.get(title__iexact=title)
   107         return None
   118         return None
   108     except Task.DoesNotExist:
   119     except:
   109         task = Task(title=title)
   120         task = Task(title=title)
       
   121 
       
   122     task.id = id 
   110     task.desc = desc
   123     task.desc = desc
   111     task.created_by = created_by
   124     task.created_by = created_by
   112     task.credits = credits
   125     task.credits = credits
   113     task.creation_datetime = datetime.now()
   126     task.creation_datetime = datetime.now()
   114     task.save()
   127     task.save()