def __init__(self): self.user_data["xsp_username"] = DBSession.query(Setting).filter_by( name="xsp_username").first().value self.user_data["xsp_password"] = DBSession.query(Setting).filter_by( name="xsp_password").first().value self.user_data["deviceType"] = DBSession.query(Setting).filter_by( name="device_type").first().value
def save(self, **kwargs): log.info("<DB> Save settings %s" % kwargs) for k, v in kwargs.iteritems(): DBSession.query(Setting).filter_by(name=k).one().value = v self.user_data["deviceType"] = kwargs.get("device_type") self.user_data["fetched"] = False redirect("/settings")
def _settings_form(self, **kw): settings = {s.__dict__["name"]: s.__dict__["value"] \ for s in DBSession.query(Setting).all()} _dict = dict(data=settings, xsp_username=self._settings.get_user_prop("xsp_username"), xsp_password=self._settings.get_user_prop("xsp_password")) utils.update_dict(_dict, kw) return _dict
def fetch_user_data(self, xsp_username, xsp_password): DBSession.query(Setting).filter_by( name="xsp_username").one().value = xsp_username DBSession.query(Setting).filter_by( name="xsp_password").one().value = xsp_password if self.user_data.get("name") != xsp_username: self.user_data = {} self.user_data["xsp_username"] = xsp_username self.user_data["xsp_password"] = xsp_password self.user_data["name"] = xsp_username self.user_data["fetched"] = True self.user_data["deviceType"] = DBSession.query(Setting).filter_by( name="device_type").first().value self.user_data["type"] = self.user_data["deviceType"] self.user_data["userId"] = xsp_username self.user_data["password"] = xsp_password server = DBSession.query(Setting).filter_by( name="oci_root").one().value tools.fetch_server_data(server, [self.user_data])
def get_user_prop(self, name, default=''): if name in ["deviceName", "fileContent" ] and name not in self.user_data.keys(): try: xsi = tools.create_xsi_tool_for_account( DBSession.query(Setting).filter_by( name="oci_root").one().value, self.user_data) if name == "deviceName": self.user_data["deviceName"] = xsi.get_device_name_by_type( self.get_device_type()) if name == "fileContent": self.user_data["fileContent"] = utils.xml_string( xsi.get_dm_config(deviceType=self.get_device_type())) except Exception as e: log.error("failed to get '%s'. %s" % (name, e)) return self.user_data.get(name, default)
def setUp(self): """Setup test fixture for each model test method.""" try: new_attrs = {} new_attrs.update(self.attrs) new_attrs.update(self.do_get_dependencies()) self.obj = self.klass(**new_attrs) DBSession.add(self.obj) DBSession.flush() return self.obj except: DBSession.rollback() raise
def get_device_type(self): self.user_data["deviceType"] = DBSession.query(Setting).filter_by( name="device_type").one().value return self.user_data["deviceType"]
def get_admin_password(self): return DBSession.query(Setting).filter_by( name="admin_password").one().value
def get_admin_username(self): return DBSession.query(Setting).filter_by( name="admin_username").one().value
def get_server(self): return DBSession.query(Setting).filter_by(name="oci_root").one().value
def test_query_obj(self): """Model objects can be queried""" obj = DBSession.query(self.klass).one() for key, value in self.attrs.items(): eq_(getattr(obj, key), value)
def tearDown(self): """Tear down test fixture for each model test method.""" DBSession.rollback()
def by_user_name(cls, username): """Return the user object whose user name is ``username``.""" return DBSession.query(cls).filter_by(user_name=username).first()
def by_email_address(cls, email): """Return the user object whose email address is ``email``.""" return DBSession.query(cls).filter_by(email_address=email).first()