本文整理汇总了Python中model.Session类的典型用法代码示例。如果您正苦于以下问题:Python Session类的具体用法?Python Session怎么用?Python Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wrapper
def wrapper(self, *args, **kwargs):
#Get the session parameters
auth_id = self.request.cookies.get('auth_id', '')
session_id = self.request.cookies.get('session_id', '')
#Check the db for the session
session = Session.GetSession(session_id, auth_id)
if session is None:
session = Session()
session.session_id = Session.MakeId()
session.auth_token = Session.MakeId()
session.put()
# Attach the session to the method
self.SessionObj = session
#Call the handler.
result = method(self, *args, **kwargs)
self.response.headers.add_header('Set-Cookie', 'auth_id=%s; path=/; HttpOnly' % str(session.auth_token))
self.response.headers.add_header('Set-Cookie', 'session_id=%s; path=/; HttpOnly' % str(session.session_id))
return result
示例2: on_message
def on_message(msg, server):
text = msg.get("text", "")
match = re.findall(r"!status( .*)?", text)
if not match: return
session = Session()
try:
realm = session.query(Realm).filter(Realm.name == wowconfig["realm"]).one()
status = u"Currently *{0}* is ".format(realm.name)
if realm.online:
status += "online (last check: {0})".format(
humanize.naturaltime(realm.lastchecked)
)
status += "\n\n*Battleground status*:\n```"
for area in realm.areas:
status += "{0} : {1} controlled : {2} : next in {3}\n".format(
area.name,
area.faction,
area.status,
humanize.naturaldelta(area.next),
)
status += "```"
else:
status += "offline (last check: {0}, last seen: {1})".format(
humanize.naturaltime(realm.lastchecked),
humanize.naturaltime(realm.lastseen)
)
return status
except NoResultFound:
return u"No status known on *{0}*".format(wowconfig["realm"])
示例3: main_page
def main_page():
s = Session()
books = s.query(Book).all()
authors = s.query(Author).all()
s.close()
return render_template('beta.html', books=books, authors=authors)
示例4: do_command
def do_command (task_id) :
try :
task_res = get_task_by_id(task_id)
if task_res["status"] != 0 :
return {"status":-1 , "val":None}
task = task_res["val"]["task"]
group_id = script_group = task_res["val"]["script_group"].id
server_group = task_res["val"]["server_group"]
scripts = get_scripts_by_group_id(group_id)["val"]
script_list = []
for script in scripts :
script_list.append(str(script.location))
server_list = []
for server in server_group.servers :
server_list.append(server.dump())
if script_list == [] or server_list == [] :
return {"status":-1 , "val":None}
task_to_do = {"scripts":script_list , "servers":server_list}
success_array , key_code_list = upload_remotefile.do_task(task_to_do)
session = Session()
taskStatus = session.query(TaskStatus).filter(TaskStatus.task_id == task_id).first()
if taskStatus == None :
taskStatus = TaskStatus(task_id , json.dumps(success_array) , json.dumps(key_code_list))
taskStatus_id = taskStatus.save_return_id(session)
else :
taskStatus.success_array = json.dumps(success_array)
taskStatus.key_code_list = json.dumps(key_code_list)
taskStatus_id = taskStatus.id
taskStatus.save(session)
session.close()
return {"status":0 , "val":taskStatus_id}
except Exception , msginfo :
return {"status":-1 , "val":msginfo}
示例5: syncSeason
def syncSeason(self, serie, season):
qry = Session.query(Serie).filter_by(path=serie)
if qry.count() == 0:
raise Exception("No serie linked to %s/%s" % (serie, saison))
serie = qry.one()
path = season
num = getSeasonNumFromFoldername(season)
if num is None:
raise Exception("This is not a season (%s)" % season)
season = filter(lambda season: season.num == num, serie.seasons)
if len(season) == 0:
season = Season(num=num, path=path)
Session.add(season)
serie.seasons.append(season)
else:
assert 1 == len(season)
season = season[0]
season.num = num
season.path = path
episodes = glob(os.path.join(self.basepath, serie.path, season.path, "*"))
episodes = filter(lambda episode: os.path.isfile(episode), episodes)
for episode in [os.path.basename(e) for e in episodes]:
try:
self.syncEpisode(serie.path, season.path, episode)
except:
pass
示例6: initialize_device
def initialize_device():
"""
Set up the Device info into the database.
By this time, the HardwareDefinition and SoftwareDefinition
entries must be entered.
"""
session = Session()
hd = session.query(HardwareDefinition).one()
sd = session.query(SoftwareDefinition).one()
device = Device(id=hd.serial_number,
interior_sensor=hd.interior_sensor,
exterior_sensor=hd.exterior_sensor)
device.hardware_version = hd.hardware_version
device.software_version = sd.software_version
device.database_service = True # database always set to True
device.device_service = sd.device_service
device.grainbin_service = sd.grainbin_service
session.add(device)
# set grainbin info
if sd.grainbin_service:
grainbins = initialize_grainbin(device.id, hd.grainbin_reader_count)
device.grainbin_count = len(grainbins)
session.add_all(grainbins)
session.commit()
session.close()
return
示例7: LogHandlerTests
class LogHandlerTests(reader.LogHandler):
def __init__(self):
self.session = Session()
self.tests = {(item.test, item.subtest) for item in self.session.query(Test)}
self.new_tests = []
def _insert_test(self, test, subtest):
if (test, subtest) not in self.tests:
test_obj = {"test": test,
"subtest": subtest}
self.new_tests.append(test_obj)
self.tests.add((test, subtest))
def test_status(self, data):
test = self._insert_test(data["test"], data["subtest"])
def test_end(self, data):
self._insert_test(data["test"], None)
sys.stdout.write("-")
sys.stdout.flush()
def suite_end(self, data):
self.session.bulk_insert_mappings(Test, self.new_tests)
self.session.commit()
sys.stdout.write(" committing\n")
示例8: main_page
def main_page():
s = Session()
meals = s.query(Meal).all()
products = s.query(Product).all()
s.close()
return render_template('beta.html', meals=meals, products=products)
示例9: draw_table
def draw_table(self):
s = Session()
self.orders = s.query(Order).all()
s.close()
self.ui.orders_table.clear()
self.ui.orders_table.setRowCount(1)
self.ui.orders_table.setColumnCount(5)
self.ui.orders_table.setHorizontalHeaderLabels([QString.fromUtf8('Номер'), QString.fromUtf8('Поломка'),
QString.fromUtf8('Дата приемки'), QString.fromUtf8('Клиент'),
QString.fromUtf8('Статус')])
#self.ui.orders_table.resizeColumnsToContents()
for order in self.orders:
data = []
data.append(str(order.id))
data.append(QString.fromUtf8(order.device))
data.append(str(order.get_ordered_date()))
data.append(QString.fromUtf8(order.get_client().get_fio()))
data.append(QString.fromUtf8(order.get_status(1).to_string()))
for i in range(0,5):
tableitem = QTableWidgetItem()
tableitem.setText(data[i])
tableitem.font = QFont("Arial", 10)
tableitem.font.setBold(True)
tableitem.textcolor = QColor("black")
self.ui.orders_table.setItem(self.ui.orders_table.rowCount() - 1,i,tableitem)
self.ui.orders_table.setRowCount(self.ui.orders_table.rowCount()+1)
self.ui.orders_table.resizeColumnsToContents()
示例10: make_account
def make_account(username, password):
session = Session()
a = Account(username, password)
session.add(a)
bot = MBotData("testerbot", 0, 0, )
session.commit()
示例11: update_position
def update_position(group_id , json_str) :
try :
session = Session()
position_list = json_str.split('|')
position_list.remove(position_list[len(position_list)-1])
for i in range(len(position_list)) :
position_list[i] = int(str(position_list[i]))
sorted_script = session.query(Sorted_Script).filter(Sorted_Script.group_id == group_id).first()
sorted_array = json.loads(sorted_script.sorted_array)
check = True
for item in position_list :
if item not in sorted_array :
check = False
break
if len(position_list) != len(sorted_array) :
check = False
if check == True :
sorted_script.sorted_array = json.dumps(position_list)
sorted_script.save(session)
return {"status":0 , "val":None}
else :
return {"status":-1 , "val":None}
except Exception , msginfo :
return {"status":-1 , "val":msginfo}
示例12: delete
def delete(self, sessionid):
s = Session()
with s.transaction:
session = s.query(CoachingSession).get(sessionid)
if session:
s.delete(session)
else:
self.response.set_status(404)
示例13: get_script_by_id
def get_script_by_id(script_id) :
try :
session = Session()
script = session.query(Script).filter(Script.id == script_id).first()
if script == None :
return {"status":-1 , "val":None}
return {"status":0 , "val":script}
except Exception , msginfo :
return {"status": -1 , "val":msginfo}
示例14: login
def login(self):
s = Session()
res = s.query(Staff).filter_by(login=unicode(self.ui.login.text()),
passwd=unicode(self.ui.password.text())).all()
if len(res):
self.mv = MainWindow(res[0])
self.mv.show()
self.close()
s.close()
示例15: get_service_group_by_id
def get_service_group_by_id(group_id) :
try :
session = Session()
group_list = session.query(ServerGroup).all()
if group_list == None or len(group_list) == 0 :
return {"status":-1 , "val":None}
return {"status":0 , "val":group_list}
except Exception , msginfo :
return {"status":-1 , "val":msginfo}