def _updateExperimenter(request, conn, eid):
    # update experimenter
    controller = BaseExperimenter(conn, eid)
    name_check = conn.checkOmeName(request.REQUEST.get('omename'), controller.experimenter.omeName)
    email_check = conn.checkEmail(request.REQUEST.get('email'), controller.experimenter.email)
    
    initial={'active':True}
    exclude = list()

    if len(request.REQUEST.getlist('other_groups')) > 0:
        others = controller.getSelectedGroups(request.REQUEST.getlist('other_groups'))   
        initial['others'] = others
        initial['default'] = [(g.id, g.name) for g in others]
        exclude.extend([g.id for g in others])

    available = controller.otherGroupsInitialList(exclude)
    initial['available'] = available

    form = ExperimenterForm(initial=initial, data=request.POST.copy(), name_check=name_check, email_check=email_check)

    if form.is_valid():
        omename = form.cleaned_data['omename']
        firstName = form.cleaned_data['first_name']
        middleName = form.cleaned_data['middle_name']
        lastName = form.cleaned_data['last_name']
        email = form.cleaned_data['email']
        institution = form.cleaned_data['institution']
        admin = webadmin_views.toBoolean(form.cleaned_data['administrator'])
        active = webadmin_views.toBoolean(form.cleaned_data['active'])
        defaultGroup = form.cleaned_data['default_group']
        otherGroups = form.cleaned_data['other_groups']
        controller.updateExperimenter(omename, firstName, lastName, email, admin, active, defaultGroup, otherGroups, middleName, institution)
    else:
        raise Exception(form.errors.as_text())
def _updateGroup(request, conn, gid):
    # update group
    controller = BaseGroup(conn, gid)
    name_check = conn.checkGroupName(request.REQUEST.get('name'), controller.group.name)
    form = GroupForm(initial={'experimenters':controller.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']
        readonly = webadmin_views.toBoolean(form.cleaned_data['readonly'])
        controller.updateGroup(name, owners, permissions, readonly, description)
    else:
        raise Exception(form.errors.as_text())