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()
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()
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()
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()
def force_position(self, tid, new_pos): _t = Tasks.get(id=tid) _t.position = new_pos _t.save()
def count_tasks_by_status(self, tid): _s = Tasks.get(id=tid).status return Tasks.select().where(Tasks.status == _s).count()
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()
def delete(self, tid): """ Deletes a task """ _t = Tasks.get(id=tid) _t.delete_instance()
def set_title(self, tid, new_title): """ Set tasks #tid with new_status""" _t = Tasks.get(id=tid) _t.rename(new_title) _t.save()
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()
def get(self, name): q = Tasks.get(Tasks.name == name, Tasks.project == self.project) return q