コード例 #1
0
def delete_task():
    """
    INPUT:
        ids: list of int
        parent_id: int
    """
    tids=list(set(request.json['ids']))
    pid=int(request.json['parent_id'])

    t_o,_=g.user.tasks(pid,need_list=False)
    t_o=t_o.get(pid,[])
    t_onew=t_o[:]

    for tid in tids:
        if tid not in t_o:
            flash('任务不存在或没有权限','error')
            g.action_success=False
            return

    cur=mysql.get_db().cursor()
    for tid in tids:
        cur.execute('''
            delete from tasks where tid=%s and uid=%s
        ''',[tid,g.user.uid])
        t_onew.remove(tid)

    model.update_linkedlist(t_o,t_onew,'tasks')
コード例 #2
0
ファイル: vadd.py プロジェクト: xmcp/ddl-bee
def add_zone():
    """
    INPUT:
         names: list of str
    """
    names = request.json['names']

    z_o, _ = g.user.zones(need_list=False)
    z_o = z_o.get(None, [])
    if len(z_o) + len(names) > current_app.config['LIMIT_ZONES']:
        flash('课程数量超出限制', 'error')
        g.action_success = False
        return

    cur = mysql.get_db().cursor()
    z_onew = z_o
    for name in names:
        if len(name) > current_app.config['MAX_NAME_LENGTH']:
            flash('名称长度超出限制', 'error')
            g.action_success = False
            return

        cur.execute(
            '''
            insert into zones (next_zid, name, uid) values (null, %s, %s)    
        ''', [name, g.user.uid])
        z_onew = z_onew + [cur.lastrowid]

    model.update_linkedlist(z_o, z_onew, 'zones')
コード例 #3
0
def delete_zone():
    """
    INPUT:
        ids: list of int
    """
    zids=list(set(request.json['ids']))

    z_o,_=g.user.zones(need_list=False)
    z_o=z_o.get(None,[])
    z_onew=z_o[:]

    for zid in zids:
        if zid not in z_o:
            flash('课程不存在或没有权限','error')
            g.action_success=False
            return

    cur=mysql.get_db().cursor()
    for zid in zids:
        cur.execute('''
            delete from zones where zid=%s and uid=%s
        ''',[zid,g.user.uid])
        z_onew.remove(zid)

    model.update_linkedlist(z_o,z_onew,'zones')
コード例 #4
0
ファイル: vadd.py プロジェクト: xmcp/ddl-bee
def add_project():
    """
    INPUT:
        names: list of str
        parent_id: int
    """
    zid = int(request.json['parent_id'])
    try:
        names = list(proc_extpid(request.json['names']))
    except SisterErrorMsg as e:
        flash(e.msg, 'error')
        g.action_success = False
        return

    if not g.user.check_zone(zid):
        flash('课程不存在或没有权限', 'error')
        g.action_success = False
        return

    p_o, _ = g.user.projects(zid, need_list=False)
    p_o = p_o.get(zid, [])
    if len(p_o) + len(names) > current_app.config['LIMIT_PROJECTS_PER_ZONE']:
        flash('类别数量超出限制', 'error')
        g.action_success = False
        return

    already_extpids = set(g.user.imported_extpids())
    for name, extpid in names:
        if extpid:
            if g.user.ring > current_app.config['MAX_RING_FOR_SHARING']:
                flash('你所在的用户组不能导入共享', 'error')
                g.action_success = False
                return

            if extpid in already_extpids:
                flash(name + ':已经添加过了', 'error')
                g.action_success = False
                return
            else:
                already_extpids.add(extpid)

    cur = mysql.get_db().cursor()
    p_onew = p_o
    for name, extpid in names:
        if len(name) > current_app.config['MAX_NAME_LENGTH']:
            flash('名称长度超出限制', 'error')
            g.action_success = False
            return

        cur.execute(
            '''
            insert into projects (next_pid, name, uid, zid, extpid) values (null, %s, %s, %s, %s)    
        ''', [name, g.user.uid, zid, extpid])
        p_onew = p_onew + [cur.lastrowid]

    model.update_linkedlist(p_o, p_onew, 'projects')
コード例 #5
0
ファイル: vadd.py プロジェクト: xmcp/ddl-bee
def add_task():
    """
    INPUT:
        names: list of str
        parent_id: int
        task_due_first: int or null
        task_due_delta: int (days) or null
    """
    names = request.json['names']
    pid = int(request.json['parent_id'])
    task_due_first = request.json['task_due_first']
    task_due_delta = int(request.json['task_due_delta'])
    if task_due_first is not None:
        task_due_first = int(task_due_first)

    if not 0 <= task_due_delta < 1000:
        flash('截止日期间隔错误', 'error')
        g.action_success = False
        return

    if not g.user.check_project(pid):
        flash('类别不存在或没有权限', 'error')
        g.action_success = False
        return

    t_o, _ = g.user.tasks(pid, need_list=False)
    t_o = t_o.get(pid, [])
    if len(t_o) + len(names) > current_app.config['LIMIT_TASKS_PER_PROJECT']:
        flash('任务数量超出限制', 'error')
        g.action_success = False
        return

    cur = mysql.get_db().cursor()
    t_onew = t_o
    for idx, name in enumerate(names):
        if len(name) > current_app.config['MAX_NAME_LENGTH']:
            flash('名称长度超出限制', 'error')
            g.action_success = False
            return

        cur.execute(
            '''
            insert into tasks (next_tid, name, uid, pid, status, due) values (null, %s, %s, %s, %s, %s)     
        ''', [
                name, g.user.uid, pid,
                'placeholder' if len(names) > 1 else 'active',
                None if task_due_first is None else
                (task_due_first + idx * 86400 * task_due_delta)
            ])
        t_onew = t_onew + [cur.lastrowid]

    model.update_linkedlist(t_o, t_onew, 'tasks')
コード例 #6
0
def reorder_zone():
    """
    INPUT:
        order: list of int
    """
    zids = list(request.json['order'])

    z_o, _ = g.user.zones(need_list=False)
    z_o = z_o[None]

    if not check_same(z_o, zids):
        flash('课程发生变化', 'error')
        g.action_success = False
        return

    model.update_linkedlist(z_o, zids, 'zones')
コード例 #7
0
def reorder_task():
    """
    INPUT:
        parent_id: int
        order: list of int
    """
    pid = int(request.json['parent_id'])
    tids = list(request.json['order'])

    t_o, _ = g.user.tasks(pid, need_list=False)
    t_o = t_o[pid]

    if not check_same(t_o, tids):
        flash('任务发生变化', 'error')
        g.action_success = False
        return

    model.update_linkedlist(t_o, tids, 'tasks')
コード例 #8
0
def reorder_project():
    """
    INPUT:
        parent_id: int
        order: list of int
    """
    zid = int(request.json['parent_id'])
    pids = list(request.json['order'])

    p_o, _ = g.user.projects(zid, need_list=False)
    p_o = p_o[zid]

    if not check_same(p_o, pids):
        flash('类别发生变化', 'error')
        g.action_success = False
        return

    model.update_linkedlist(p_o, pids, 'projects')
コード例 #9
0
def delete_project():
    """
    INPUT:
        ids: list of int
        parent_id: int
    """
    pids=list(set(request.json['ids']))
    zid=int(request.json['parent_id'])

    p_o,_=g.user.projects(zid,need_list=False)
    p_o=p_o.get(zid,[])
    p_onew=p_o[:]

    for pid in pids:
        if pid not in p_o:
            flash('类别不存在或没有权限','error')
            g.action_success=False
            return

    cur=mysql.get_db().cursor()
    for pid in pids:
        p_onew.remove(pid)

        # get linked extpid
        cur.execute('''
            select extpid from projects where pid=%s
        ''',[pid])
        extpid=cur.fetchone()[0]

        if extpid is None: # src project
            cur.execute('''
                select count(*) from projects where extpid=%s
            ''',[pid])
            peercnt=cur.fetchone()[0]

            if peercnt==0: # no peers: safely delete
                cur.execute('''
                    delete from projects where pid=%s and uid=%s
                ''',[pid,g.user.uid])

            else: # otherwise: only remove from current user, delete it later
                cur.execute('''
                    update projects set uid=null, zid=null, share_hash=null where pid=%s and uid=%s
                ''',[pid,g.user.uid])
                cur.execute('''
                    update tasks set uid=null where pid=%s and uid=%s
                ''',[pid,g.user.uid])
                # completes will be deleted after last person deletes the project and tasks are deleted

        else: # imported project
            # delete self
            cur.execute('''
                delete from projects where pid=%s and uid=%s
            ''',[pid,g.user.uid])

            cur.execute('''
                select count(*) from projects where
                    (extpid=%s and pid!=%s) or /* other imported ones */
                    (pid=%s and uid is not null) /* original one that is not flagged as deletion */
            ''',[extpid,pid,extpid])
            peercnt=cur.fetchone()[0]

            if peercnt==0: # delete src
                cur.execute('''
                    delete from projects where pid=%s
                ''',[extpid])

    model.update_linkedlist(p_o,p_onew,'projects')