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)
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
def __init__( self, name, path, vcs_type, cache_path='/tmp', doc_path='doc', tasks_path='tasks'): self.name = name # root path self.path = path # repo's path self.fullpath = path + '/' + self.name # root cache path self.cache_path = cache_path + '/' + self.name # doc's path relative to repo's path self.doc_path = doc_path # tasks's path relative to repo's path self.tasks_path = tasks_path # vcs type: git or hg self.vcs_type = vcs_type # path to cache tasks self.tasks_cache = self.cache_path + '/' + self.tasks_path # path to cache doc self.doc_cache = self.cache_path + '/' + self.doc_path # open project's repo self.r = Repo(self.fullpath, self.vcs_type) # project's documents full path self.doc_fullpath = self.fullpath + '/' + self.doc_path # tasks's documents full path self.tasks_fullpath = self.fullpath + '/' + self.tasks_path # project's documents handler self.doc_files = Doc(self.doc_fullpath, self.doc_cache) # tasks's documents handler self.tasks_files = Doc(self.tasks_fullpath, self.tasks_cache) # create project in db if not exist Projects.get_or_create(name=self.name)
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)
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()
title="Task list", leftmenu=menu, project=None)) @get('/tasks/add', name='add_task') @view('tasks/tasks_add') def add_task(): _redirect = '/tasks/add', auth.require( role='edit', fail_redirect='/login?redirect=' + _redirect[0]) menu = make_tasks_menu() statuses = Statuses.select() print [x.name for x in statuses] projects = Projects.select() print [x.name for x in projects] return(dict(title="Add task", leftmenu=menu, project=None, projects=projects, statuses=statuses)) @post('/tasks/add') def create_task(): auth.require(role='edit', fail_redirect='/login') name = request.forms.name description = request.forms.description #position = request.forms.position status = request.forms.status