예제 #1
0
파일: gaspacho.py 프로젝트: GnunuX/gaspacho
def data_rules_group(categoryid, groupid, userid=None):
    #grouping
    group = get_group_by_id(groupid)
    category = get_category_by_id(categoryid)
    if userid != None:
        user = get_user_by_id(userid)
        rules = get_rules(conflevel=confuser, group=group, category=category, user=user)
    else:
        rules = get_rules(group=group, category=category)
    ret = []
    for tag in rules:
        ntag = tag['tag'].name
        for rule in tag['rules']:
            trule = {'name': rule['rule'].name, 'id': rule['rule'].id, 'tag': ntag}
            if rule['choice'].has_key('current'):
                trule['current-state'] = rule['choice']['current'].state
                trule['current-value'] = rule['choice']['current'].value
            if rule['choice'].has_key('herited'):
                trule['herited-state'] = rule['choice']['herited'].state
                trule['herited-value'] = rule['choice']['herited'].value
            ret.append(trule)
    return json.dumps(ret)
예제 #2
0
파일: gaspacho.py 프로젝트: GnunuX/gaspacho
def data_groups_tree(id=None):
    ret = []
    if id == None:
        ogroup = None
    else:
        ogroup = get_group_by_id(id)
    for group in get_groups(ogroup):
        cls = 'group'
        if group.users == [] and group.children == []:
            leaf = True
        else:
            leaf = False
        if id == None:
            expanded = True
        else:
            expanded = False
        ret.append({"text": group.name, "id": group.id, "cls": cls, "leaf": leaf, "expanded": expanded})
    if ogroup != None:
        for user in ogroup.users:
            ret.append({"text": user.name, "id": str(id)+"-"+str(user.id), "cls": user.typ, "leaf": True, "draggable": False})
    if id == None:
        ret.extend(data_templates_tree(None, False))
    return json.dumps(ret)
예제 #3
0
파일: gaspacho.py 프로젝트: GnunuX/gaspacho
 def render_POST(self, request):
     if request.postpath[0] == 'data_categories_paned':
         groupid = request.args['id'][0]
         groupname = request.args['name'][0]
         return data_categories_paned(groupname, groupid)
     elif request.postpath[0] == 'data_groups_tree':
         id = request.args['node'][0]
         if id == 'src':
             id = None
         elif id[0] == 't':
             #template
             tid=int(id[1:])
             if tid == 0:
                 tid=None
             return data_templates_tree(tid)
         elif id == '':
             id = None
         else:
             id = int(id)
         return data_groups_tree(id)
     elif request.postpath[0] == 'data_rules_group':
         userid = request.args['userid'][0]
         groupid = int(request.args['groupid'][0])
         categoryid = int(request.args['categoryid'][0])
         if userid == '':
             userid = None
         else:
             userid = int(userid)
         return data_rules_group(categoryid, groupid, userid)
     elif request.postpath[0] == 'data_rules_template':
         userid = request.args['userid'][0]
         templateid = int(request.args['templateid'][0])
         categoryid = int(request.args['categoryid'][0])
         if userid == '':
             userid = None
         else:
             userid = int(userid)
         return data_rules_template(categoryid, templateid, userid)
     elif request.postpath[0] == 'set_choice_group':
         userid = request.args['userid'][0]
         group = get_group_by_id(int(request.args['groupid'][0]))
         rule = get_rule_by_id(int(request.args['ruleid'][0]))
         state = unicode(request.args['state'][0])
         value = unicode(request.args['value'][0])
         if userid == '':
             user = None
         else:
             user = get_user_by_id(int(userid))
         choice = set_choice(rule=rule, group=group, user=user, state=state, value=value)
         session.commit()
         session.flush()
         return 'ok'
     elif request.postpath[0] == 'set_choice_template':
         userid = request.args['userid'][0]
         template = get_template_by_id(int(request.args['templateid'][0]))
         rule = get_rule_by_id(int(request.args['ruleid'][0]))
         state = unicode(request.args['state'][0])
         value = unicode(request.args['value'][0])
         if userid == '':
             user = None
         else:
             user = get_user_by_id(int(userid))
         choice = set_choice(rule=rule, template=template, user=user, state=state, value=value)
         session.commit()
         session.flush()
         return 'ok'
     else:
         return "hu?"