Esempio n. 1
0
def del_project(name):
    # firstly del project
    p_id = Project.get(Project.p_name == name).p_id
    query = Project.delete().where(Project.p_name == name)
    query.execute() 
    # secondly del p_id in admin_pro 
    users = User.select() 
    for user in users:
        admin_pro = user.admin_pro
        u_id = user.u_id
        if admin_pro:
            if admin_pro == str(p_id):
                admin_pro = None
            else:
                pids = admin_pro.split(',')
                if str(p_id) in pids:
                    pids.remove(str(p_id))
                    splits = ','
                    admin_pro = splits.join(pids)
            query = User.update(admin_pro = admin_pro).where(User.u_id == u_id)
            query.execute()
    # thirdly del item if p_id in item
    items = Item.select()
    items_id = []
    for item in items:
        if item.project_id == p_id:
            items_id.append(item.it_id)
    query = Item.delete().where(Item.project_id == p_id)
    query.execute() 
    # fourly del reply if it_id in items_id
    for item_id in items_id:
        query = Reply.delete().where(Reply.item_id == item_id)
        query.execute() 
Esempio n. 2
0
def get_user_admin(email):
    query=User.get(User.email == email)
    user_admin = []
    if query.admin_pro:
        projects = query.admin_pro.split(',')
        for pid in projects:
            if pid:
                pname = Project.get(Project.p_id == int(pid)).p_name
                user_admin.append({'p_id':str(pid),'p_name':pname})
    return user_admin
Esempio n. 3
0
def get_admins_of_project(p_id):
    user_admin = []
    try:
        project = Project.get(Project.p_id == p_id)
        #temp_u['u_name'] = u_iter.u_name
        #temp_u['email'] = u_iter.email
        for user_iter in User.select():
            temp_u = { }
            pids = []
            if user_iter.admin_pro:
                pids = user_iter.admin_pro.split(',')
            if str(project.p_id) in pids:
                temp_u['u_name'] = user_iter.u_name
                temp_u['email'] = user_iter.email
                user_admin.append(temp_u)
        return user_admin
    except Exception, e:
        return []  
Esempio n. 4
0
def add_project(name):
    pro,created = Project.get_or_create(p_name = name)
    query=Project.get(Project.p_name == name)
    return query, created # if new project, created is true, otherwise created is false