Esempio n. 1
0
def _updateGroup(request, conn, gid):
    # update group
    experimenters = list(conn.getObjects("Experimenter"))
    group = conn.getObject("ExperimenterGroup", gid)
    name_check = conn.checkGroupName(request.REQUEST.get('name'), group.name)
    form = GroupForm(initial={'experimenters': experimenters},
                     data=request.POST.copy(),
                     name_check=name_check)
    if form.is_valid():
        name = form.cleaned_data['name']
        description = form.cleaned_data['description']
        owners = form.cleaned_data['owners']
        permissions = form.cleaned_data['permissions']
        members = form.cleaned_data['members']

        listOfOwners = getSelectedExperimenters(conn, owners)
        if permissions != int(permissions):
            perm = setActualPermissions(permissions)
        else:
            perm = None
        conn.updateGroup(group, name, perm, listOfOwners, description)

        new_members = getSelectedExperimenters(conn,
                                               mergeLists(members, owners))
        conn.setMembersOfGroup(group, new_members)
    else:
        raise Exception(form.errors.as_text())
Esempio n. 2
0
def _createGroup(request, conn):
    #create group
    experimenters = list(conn.getObjects("Experimenter"))
    name_check = conn.checkGroupName(request.REQUEST.get('name'))
    form = GroupForm(initial={'experimenters':experimenters}, data=request.POST.copy(), name_check=name_check)
    if form.is_valid():
        name = form.cleaned_data['name']
        description = form.cleaned_data['description']
        owners = form.cleaned_data['owners']
        members = form.cleaned_data['members']
        permissions = form.cleaned_data['permissions']
        
        perm = setActualPermissions(permissions)
        listOfOwners = getSelectedExperimenters(conn, owners)
        gid = conn.createGroup(name, perm, listOfOwners, description)
        new_members = getSelectedExperimenters(conn, mergeLists(members,owners))
        group = conn.getObject("ExperimenterGroup", gid)
        conn.setMembersOfGroup(group, new_members)
        return gid
    else:
        raise Exception(form.errors.as_text())