

@expose('/lab/availability/local', methods=['POST'])
def change_accessibility(self):
    lab_id = int(request.form['lab_id'])
    activate = (request.form['activate'] == 'true')
    lab = self.session.query(Laboratory).filter_by(id=lab_id).first()
    if (lab is not None):
        if activate:
            lab.available = (not activate)
            lab.default_local_identifier = ''
        else:
            local_id = request.form['default_local_identifier']
            local_id = local_id.lstrip(' ')
            local_id = local_id.strip(' ')
            if ((not activate) and (len(local_id) == 0)):
                flash(gettext('Invalid local identifier (empty)'))
                return redirect(url_for('.index_view'))
            existing_labs = self.session.query(Laboratory).filter_by(default_local_identifier=local_id).all()
            if ((len(existing_labs) > 0) and (lab not in existing_labs)):
                flash(gettext("Local identifier '%(localidentifier)s' already exists", localidentifier=local_id))
                return redirect(url_for('.index_view'))
            lab.available = (not activate)
            lab.default_local_identifier = local_id
        self.session.add(lab)
        self.session.commit()
    return redirect(url_for('.index_view'))

dataset/ETHPy150Open gateway4labs/labmanager/labmanager/views/admin.py LaboratoryPanel.change_accessibility/original