Example #1
0
 def __init__(self, project='*'):
     if project == '*':
         self.tasks = Tasks.select()
         #self.project = Projects.get_or_create(name)
     else:
         self.project = Projects.get_or_create(name=project)
         self.tasks = Tasks.select().where(Tasks.project == self.project)
Example #2
0
    def create_task(self, name, status, description='', MU_type='md'):
        """MarkUp type defaults to 'markdown'
        """
        _status = Statuses.get(name=status)
        _t = Tasks()
        _d = str(datetime.datetime.now())
        _t.name = name
        _t.description = description
        _t.status = _status
        _t.md5hash = md5(_d + name)
        _t.position = Tasks.select().where(Tasks.status == _status).count()
        _t.project = Projects.get_or_create(name=self.name)
        _t.save()

        # TODO save task on disk, inside the repo
        #if description == '':
            #description = name
        #self.tasks_files.create_doc(name+'.'+MU_type, description)
        #self.tasks_files.create_doc(name, description)
        #self.r.add_file(self.r.path+'/tasks/'+name)
        print '*' * 100
        print self.tasks_files.root_path
        print 'tasks fullpath: ' + self.tasks_fullpath + '/' + name + '.'\
            + MU_type
        print '*' * 100
Example #3
0
 def add_task(self, name, status):
     _now = str(datetime.datetime.now())
     _md5hash = md5(_now + name).hexdigest()
     _pos = self.count() + 1
     Tasks.create(
         name=name,
         md5hash=_md5hash,
         project=self.project,
         position=_pos)
Example #4
0
 def set_description(self, tid, new_description):
     """ Set tasks #tid with new_status"""
     _t = Tasks.get(id=tid)
     # get task title
     # and project ?
     # save file's content/description
     _t.set_description(new_description)
     _t.save()
Example #5
0
    def create_task(self, name, status, description='', MU_type='md'):
        """MarkUp type defaults to 'markdown'
        """
        _status = Statuses.get(name=status)
        _t = Tasks()
        _d = str(datetime.datetime.now())
        _t.name = name
        _t.description = description
        _t.status = _status
        _t.md5hash = md5(_d + name)
        _t.position = Tasks.select().where(Tasks.status == _status).count()
        _t.project = Projects.get_or_create(name=self.name)
        _t.save()

        self.tasks_files.create_doc(name + '.' + MU_type, description)
        self.r.add_file(self.tasks_fullpath + '/' + name + '.' + MU_type)
        self.tasks_files.cache(name + '.' + MU_type)
Example #6
0
 def align_status(self, status):
     """ Aligns tasks in specific status to position 0"""
     _t = Tasks.select().where(Tasks.status.name == status)
     _t = _t.order_by(Tasks.position.desc())
     _count = _t.count()
     for x in _t:
         x.position = _count
         x.save()
         _count -= 1
Example #7
0
 def set_position(self, tid, new_pos, project='*'):
     """Set new position and update their friends"""
     if Tasks.select().count() == 1:
         return
     _t = Tasks.get(id=tid)
     # FIXME: why a str?
     old_pos = str(_t.position)
     # query to select tasks to update
     updq = Tasks.select().where(Tasks.status == _t.status)
     # update all Tasks
     # update tasks in the specific project
     if not project == '*':
         updq = updq.where(
             Tasks.project == Projects.get(name=project))
     # update from top to bottom
     # A from 1 to 2:
     # 1 | A -> 2
     # 2 | B -> 1
     # 3 | C -> 3
     if int(new_pos) > int(old_pos):
         tasks_to_update = updq.where(Tasks.position <= str(new_pos),
                           Tasks.position > str(old_pos))
         tasks_to_update = tasks_to_update.order_by(Tasks.position.asc())
     # update from bottom to top
     else:
         tasks_to_update = updq.where(Tasks.position >= str(new_pos),
                           Tasks.position < str(old_pos))
         tasks_to_update = tasks_to_update.order_by(Tasks.position.desc())
     # FIXME: hackish, find if there is a better way
     _first = updq.where(Tasks.position==old_pos).get()
     if updq.count() > 0:
         print 'updq.count: ' + str(updq.count())
         print 'updq' + str([x.id for x in updq])
         #prev_pos = prev.position
         prev_pos = old_pos
         for upd_t in updq:
             next_pos = upd_t.position
             print "moving task: " + str(upd_t.id) + " from: " +\
                 str(next_pos) + " to: " + str(prev_pos)
             upd_t.position = prev_pos
             upd_t.save()
             prev_pos = next_pos
     _first.position = new_pos
     _first.save()
Example #8
0
 def set_title(self, tid, new_title):
     """ Set tasks #tid with new_status"""
     _t = Tasks.get(id=tid)
     # get old title
     _old_title = _t.name
     # move/rename file
     _p = self.projects[_t.project.name]
     #TODO: define in project.py
     _p.rename_file(old_name=_old_title, new_name=new_title,
                    in_path='tasks')
     _t.rename(new_title)
     _t.save()
Example #9
0
 def set_position(self, tid, new_pos, project='*'):
     """Set new position and update their friends"""
     if Tasks.select().count() == 1:
         return
     _t = Tasks.get(id=tid)
     # FIXME: why a str?
     old_pos = str(_t.position)
     # query to select tasks to update
     updq = Tasks.select().where(Tasks.status == _t.status)
     # update all Tasks
     # update tasks in the specific project
     if not project == '*':
         updq = updq.where(
             Tasks.project == Projects.get(name=project))
     # update from top to bottom
     if int(new_pos) > int(old_pos):
         updq = updq.where(Tasks.position <= str(new_pos),
                           Tasks.position >= str(old_pos))
     # update from bottom to top
     else:
         updq = updq.where(Tasks.position >= str(new_pos),
                           Tasks.position <= str(old_pos))
         updq = updq.order_by(Tasks.position.desc())
     # FIXME: hackish, find if there is a better way
     prev = [x for x in updq.limit(1)][0]
     updq = updq.limit(-1).offset(1)
     _first = prev
     if updq.count() > 0:
         print 'updq.count: ' + str(updq.count())
         print 'updq' + str([x.id for x in updq])
         prev_pos = prev.position
         for upd_t in updq:
             next_pos = upd_t.position
             print "moving task: " + str(upd_t.id) + " from: " +\
                 str(next_pos) + " to: " + str(prev_pos)
             upd_t.position = prev_pos
             upd_t.save()
             prev_pos = next_pos
     _first.position = new_pos
     _first.save()
Example #10
0
 def set_title(self, tid, new_title):
     """ Set tasks #tid with new_status"""
     _t = Tasks.get(id=tid)
     _t.rename(new_title)
     _t.save()
Example #11
0
 def force_position(self, tid, new_pos):
     _t = Tasks.get(id=tid)
     _t.position = new_pos
     _t.save()
Example #12
0
 def count_tasks_by_status(self, tid):
     _s = Tasks.get(id=tid).status
     return Tasks.select().where(Tasks.status == _s).count()
Example #13
0
 def count(self):
     return Tasks.select().count()
Example #14
0
 def set_description(self, tid, new_description):
     """ Set tasks #tid with new_status"""
     _t = Tasks.get(id=tid)
     _t.set_description(new_description)
     _t.save()
Example #15
0
 def delete(self, tid):
     """ Deletes a task """
     _t = Tasks.get(id=tid)
     _t.delete_instance()
Example #16
0
 def set_status(self, tid, new_status):
     """ Set tasks #tid with new_status"""
     _t = Tasks.get(id=tid)
     _s = Statuses.get(name=new_status)
     _t.status = _s
     _t.save()
Example #17
0
 def get(self, name):
     q = Tasks.get(Tasks.name == name, Tasks.project == self.project)
     return q