

def _add_or_edit(self, rlms, version, add_or_edit, obj, config):
    edit_id = request.args.get('id')
    form_class = get_form_class(rlms, version)
    form = form_class(add_or_edit=add_or_edit, obj=obj)
    error_messages = []
    if form.validate_on_submit():
        configuration = config
        for key in form.get_field_names():
            if (key not in dir(forms.AddForm)):
                field = getattr(form, key)
                is_password = ('password' in unicode(field.type).lower())
                if (is_password and (not add_or_edit) and (field.data == '')):
                    continue
                configuration[key] = field.data
        config_json = json.dumps(configuration)
        current_rlms_id = (None if add_or_edit else edit_id)
        ManagerClass = get_manager_class(rlms, version, current_rlms_id)
        rlms_instance = ManagerClass(config_json)
        if hasattr(rlms_instance, 'test'):
            try:
                error_messages = (rlms_instance.test() or [])
            except Exception as e:
                error_messages.append(('%s%s' % (gettext('Error testing the RLMS:'), e)))
                traceback.print_exc()
        if (form.publicly_available.data and (len(form.public_identifier.data) == 0)):
            form.public_identifier.errors = [gettext('If the RLMS is public, it must have a public identifier')]
            error_messages.append(gettext('Invalid public identifier'))
        elif (form.publicly_available.data and (len(form.public_identifier.data) < 4)):
            form.public_identifier.errors = [gettext('If the RLMS is public, it must have a public identifier with at least 4 characters')]
            error_messages.append(gettext('Invalid public identifier'))
        elif form.publicly_available.data:
            existing_objects = self.session.query(RLMS).filter_by(public_identifier=form.public_identifier.data).all()
            if (not add_or_edit):
                existing_objects = [existing_obj for existing_obj in existing_objects if (unicode(existing_obj.id) != unicode(edit_id))]
            if existing_objects:
                form.public_identifier.errors = [gettext('That identifier is already taken')]
                error_messages.append(gettext("Use other identifier or don't make the RLMS public"))
        if (not error_messages):
            if add_or_edit:
                rlms_obj = RLMS(kind=rlms, version=version, name=form.name.data, url=form.url.data, location=form.location.data, configuration=config_json, publicly_available=form.publicly_available.data, public_identifier=form.public_identifier.data, default_autoload=form.default_autoload.data)
            else:
                rlms_obj = self.session.query(RLMS).filter_by(id=form).first()
                rlms_obj.url = form.url.data
                rlms_obj.location = form.location.data
                rlms_obj.name = form.name.data
                rlms_obj.default_autoload = form.default_autoload.data
                rlms_obj.publicly_available = form.publicly_available.data
                rlms_obj.public_identifier = form.public_identifier.data
                rlms_obj.configuration = config_json
            self.session.add(rlms_obj)
            try:
                self.session.commit()
            except:
                self.session.rollback()
                raise
            if add_or_edit:
                rlms_id = rlms_obj.id
            else:
                rlms_id = edit_id
            labs_url = url_for('.labs', id=rlms_id, _external=True)
            if (rlms == http_plugin.PLUGIN_NAME):
                if add_or_edit:
                    configuration['context_id'] = rlms_id
                    config_json = json.dumps(configuration)
                    rlms_obj.configuration = config_json
                    try:
                        self.session.commit()
                    except:
                        self.session.rollback()
                        raise
                rlms_instance = ManagerClass(config_json)
                try:
                    setup_url = rlms_instance.setup(back_url=labs_url)
                except Exception as e:
                    flash(gettext(("Couldn't load the setup URL! (this usually means that the plug-in is not correctly configured). Error message: %s" % e)))
                    return redirect(url_for('.edit_view', id=rlms_id))
                else:
                    return redirect(setup_url)
            return redirect(labs_url)
    if ((not add_or_edit) and (rlms == http_plugin.PLUGIN_NAME)):
        setup_url = url_for('.plugin_setup', rlms_id=edit_id)
    else:
        setup_url = None
    return self.render('labmanager_admin/create-rlms-step-2.html', name=rlms, version=version, form=form, fields=form.get_field_names(), error_messages=error_messages, edit_id=edit_id, setup_url=setup_url)

dataset/ETHPy150Open gateway4labs/labmanager/labmanager/views/admin.py RLMSPanel._add_or_edit/VarMisuse@547/834 `edit_id`->`form`