diff options
Diffstat (limited to 'taskapp')
-rw-r--r-- | taskapp/events/task.py | 62 | ||||
-rw-r--r-- | taskapp/forms/task.py | 2 | ||||
-rw-r--r-- | taskapp/models.py | 11 | ||||
-rw-r--r-- | taskapp/views/task.py | 14 |
4 files changed, 64 insertions, 25 deletions
diff --git a/taskapp/events/task.py b/taskapp/events/task.py index 335b645..727b04e 100644 --- a/taskapp/events/task.py +++ b/taskapp/events/task.py @@ -1,12 +1,15 @@ from datetime import datetime -from pytask.taskapp.models import Profile, Task, Comment, Credit, Claim +from pytask.taskapp.models import Profile, Task, Comment, Credit, Claim, Map def publishTask(task): """ set the task status to open """ - - sub_tasks = task.subs.all() - dependencies = task.deps.all() - if sub_tasks or any(map(lambda t:t.status!="CM",dependencies)): + + if task.sub_type == 'D': + deps, subs = task.map_subs.all(), [] + else: + subs, deps = task.map_subs.all(), [] + + if subs or any(map(lambda t:t.status!="CM",deps)): task.status = "LO" else: task.status = "OP" @@ -20,8 +23,20 @@ def addSubTask(main_task, sub_task): ## Shall modify after talking to pr about subtasks ## I think i might even remove the concept of subtasks - main_task.subs.add(sub_task) - sub_tasks = main_task.subs.all() + + main_task.sub_type = "S" + main_task.save() + + try: + mapobj = Map.objects.get(main=main_task) + except Map.DoesNotExist: + mapobj = Map() + mapobj.main = main_task + mapobj.save() + mapobj.subs.add(sub_task) + mapobj.save() + + sub_tasks = getTask(main_task.id).subs if main_task.status == "OP": if any(map(lambda t:t.status!="CM",sub_tasks)): main_task.status = "LO" @@ -36,8 +51,21 @@ def addDep(main_task, dependency): And also if the task doesn't have any subs. """ - main_task.deps.add(dependency) - deps = main_task.deps.all() + main_task.sub_type = "D" + main_task.save() + + try: + mapobj = Map.objects.get(main=main_task) + except Map.DoesNotExist: + mapobj = Map() + mapobj.main = main_task + mapobj.save() + + mapobj.subs.add(dependency) + mapobj.save() + + deps = getTask(main_task.id).deps + if main_task.status in ["OP", "LO"]: if all(map(lambda t:t.status=="CM",deps)): main_task.status = "OP" @@ -99,9 +127,21 @@ def getTask(tid): """ task = Task.objects.get(id=tid) - deps = task.deps.all() - subs = task.subs.all() + try: + mapobj = Map.objects.get(main=task) + except Map.DoesNotExist: + mapobj = Map() + mapobj.main = task + mapobj.save() + + task_subs = mapobj.subs.all() + + if task.sub_type == "D": + task.deps, task.subs = task_subs, [] + elif task.sub_type == "S": + task.subs, task.deps = task_subs, [] + deps, subs = task.deps, task.subs if deps and task.status in ["OP", "LO"]: task.status = "OP" if all(map(lambda t:t.status=="CM",deps)) else "LO" if subs and task.status in ["OP", "LO", "CM"]: diff --git a/taskapp/forms/task.py b/taskapp/forms/task.py index d3cea32..3bf5825 100644 --- a/taskapp/forms/task.py +++ b/taskapp/forms/task.py @@ -39,5 +39,5 @@ def AddTaskForm(task_choices, is_plain=False): type_choices = [('S','Subtasks'),('D','Dependencies')] type = forms.ChoiceField(type_choices, widget=forms.RadioSelect) - task = forms.MultipleChoiceField(choices=task_choices) + task = forms.ChoiceField(choices=task_choices) return myForm() diff --git a/taskapp/models.py b/taskapp/models.py index a4de208..cb72070 100644 --- a/taskapp/models.py +++ b/taskapp/models.py @@ -75,9 +75,6 @@ class Task(models.Model): # tags = models.CharField(max_length = 200, blank = True) tags_field = TagField() - subs = models.ManyToManyField('self', blank = True, related_name = "%(class)s_parents") - deps = models.ManyToManyField('self', blank = True, related_name = "%(class)s_deps") - credits = models.PositiveSmallIntegerField() progress = models.PositiveSmallIntegerField(default = 0) @@ -87,7 +84,7 @@ class Task(models.Model): assigned_users = models.ManyToManyField(User, blank = True, related_name = "%(class)s_assigned_users") creation_datetime = models.DateTimeField() - + sub_type = models.CharField(max_length=1, choices = (('D','Dependency'),('S','Subtask')), default = 'D') #is_claimable = models.BooleanField() ## not yet decided if attribs after this are to be included @@ -97,6 +94,12 @@ class Task(models.Model): def __unicode__(self): return unicode(self.title) +class Map(models.Model): + + main = models.ForeignKey('Task', related_name = "%(class)s_main") + subs = models.ManyToManyField('Task', blank = True, null = True, related_name = "%(class)s_subs") + + class Comment(models.Model): task = models.ForeignKey('Task') diff --git a/taskapp/views/task.py b/taskapp/views/task.py index 0a36a25..975dd53 100644 --- a/taskapp/views/task.py +++ b/taskapp/views/task.py @@ -33,8 +33,9 @@ def view_task(request, tid): task = getTask(tid) comments = Comment.objects.filter(task=task) mentors = task.mentors.all() - subs = task.subs.all() - deps = task.deps.all() + + deps, subs = task.deps, task.subs + errors = [] is_guest = True if not user.is_authenticated() else False @@ -62,7 +63,6 @@ def view_task(request, tid): if request.method == 'POST': if not is_guest: data = request.POST["data"] - task = getTask(tid) new_comment = Comment(task=task, data=data, created_by=user, creation_datetime=datetime.now()) new_comment.save() return redirect(task_url) @@ -162,15 +162,13 @@ def add_tasks(request, tid): user = request.user task = getTask(tid) - deps = task.deps.all() - subs = task.subs.all() - + deps, subs = task.deps, task.subs is_plain = False if deps or subs else True ## again a brute force method valid_tasks = [] for a_task in Task.objects.all(): - if not ( a_task.status in deps or a_task in subs or a_task.status=="CD" or a_task==task ): + if not ( a_task in deps or a_task in subs or a_task.status=="CD" or a_task==task ): valid_tasks.append(a_task) task_choices = [ (_.id,_.title) for _ in valid_tasks ] @@ -185,7 +183,6 @@ def add_tasks(request, tid): ## first decide if adding subs and deps can be in same page ## only exclude tasks with status deleted data = request.POST - print data if is_plain and not data.get('type', None): errors.append('Please choose which type of task(s) do you want to add.') if not data.get('task', None): errors.append('Please choose a one task') @@ -202,7 +199,6 @@ def add_tasks(request, tid): ## we might iterate over a task list later on task_id = data['task'] sub_or_dep = getTask(task_id) - print task_id, sub_or_dep update_method(task, sub_or_dep) return redirect(task_url) |