本文整理汇总了Python中tg.session.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pwd_expired_change
def pwd_expired_change(self, **kw):
require_authenticated()
return_to = kw.get('return_to')
kw = F.password_change_form.to_python(kw, None)
ap = plugin.AuthenticationProvider.get(request)
try:
expired_username = session.get('expired-username')
expired_user = M.User.query.get(username=expired_username) if expired_username else None
ap.set_password(expired_user or c.user, kw['oldpw'], kw['pw'])
expired_user.set_tool_data('allura', pwd_reset_preserve_session=session.id)
expired_user.set_tool_data('AuthPasswordReset', hash='', hash_expiry='') # Clear password reset token
except wexc.HTTPUnauthorized:
flash('Incorrect password', 'error')
redirect(tg.url('/auth/pwd_expired', dict(return_to=return_to)))
flash('Password changed')
session.pop('pwd-expired', None)
session['username'] = session.get('expired-username')
session.pop('expired-username', None)
session.save()
h.auditlog_user('Password reset (via expiration process)')
if return_to and return_to != request.url:
redirect(return_to)
else:
redirect('/')
示例2: pwd_expired_change
def pwd_expired_change(self, **kw):
require_authenticated()
return_to = kw.get("return_to")
kw = F.password_change_form.to_python(kw, None)
ap = plugin.AuthenticationProvider.get(request)
try:
expired_username = session.get("expired-username")
expired_user = M.User.query.get(username=expired_username) if expired_username else None
ap.set_password(expired_user or c.user, kw["oldpw"], kw["pw"])
expired_user.set_tool_data("allura", pwd_reset_preserve_session=session.id)
expired_user.set_tool_data("AuthPasswordReset", hash="", hash_expiry="") # Clear password reset token
except wexc.HTTPUnauthorized:
flash("Incorrect password", "error")
redirect(tg.url("/auth/pwd_expired", dict(return_to=return_to)))
flash("Password changed")
session.pop("pwd-expired", None)
session["username"] = session.get("expired-username")
session.pop("expired-username", None)
session.save()
h.auditlog_user("Password reset (via expiration process)")
if return_to and return_to != request.url:
redirect(return_to)
else:
redirect("/")
示例3: check_phone_verification
def check_phone_verification(self, pin, **kw):
p = plugin.ProjectRegistrationProvider.get()
request_id = session.get('phone_verification.request_id')
number_hash = session.get('phone_verification.number_hash')
res = p.check_phone_verification(c.user, request_id, pin, number_hash)
if 'error' in res:
res['error'] = jinja2.Markup.escape(res['error'])
res['error'] = h.really_unicode(res['error'])
return res
示例4: clear
def clear(self):
try:
session.get('skip', set()).remove(self.name)
except KeyError:
pass
session['settings'].pop(self.name, None)
session.save()
flash(_('Settings cleared'))
redirect(self.url)
示例5: index
def index(self):
result = None
if session.get('username') is not None:
user = DBSession.query(User).filter_by(user_name=session.get('username')).first()
if user is not None and user.is_cloud():
if session['cloud_only'] == True:
override_template(self.index, 'genshi:stackone.templates.clouddashboard')
result = self.controller_impl.index()
return dict(result)
示例6: oauth_callback
def oauth_callback(self, **kw):
client_id = config.get("github_importer.client_id")
secret = config.get("github_importer.client_secret")
if not client_id or not secret:
return # GitHub app is not configured
oauth = OAuth2Session(client_id, state=session.get("github.oauth.state"))
token = oauth.fetch_token(
"https://github.com/login/oauth/access_token", client_secret=secret, authorization_response=request.url
)
c.user.set_tool_data("GitHubProjectImport", token=token["access_token"])
redirect(session.get("github.oauth.redirect", "/"))
示例7: post_logout
def post_logout(self, came_from=url('/')):
try:
if session.get('username'):
UIUpdateManager().del_user_updated_entities(session['username'], session['group_names'])
UIUpdateManager().del_user_updated_tasks(session['username'])
TopCache().delete_usercache(session.get('auth'))
except Exception as e:
print_traceback()
LOGGER.error(to_str(e))
session.delete()
示例8: index
def index(self, *args, **kw):
'''
Find first not set up service
'''
for name, item in self.menu:
if name in session.get('skip', set()):
continue
if name not in session.get('settings', {}):
redirect(item.url)
# Redirect to the first item in list
# redirect(self.menu[0][1].url)
# Redirect to the last item in list
redirect(item.url)
示例9: oauth_callback
def oauth_callback(self, **kw):
client_id = config.get('github_importer.client_id')
secret = config.get('github_importer.client_secret')
if not client_id or not secret:
return # GitHub app is not configured
oauth = OAuth2Session(
client_id, state=session.get('github.oauth.state'))
token = oauth.fetch_token(
'https://github.com/login/oauth/access_token',
client_secret=secret,
authorization_response=request.url
)
c.user.set_tool_data('GitHubProjectImport',
token=token['access_token'])
redirect(session.get('github.oauth.redirect', '/'))
示例10: get_all_instance_categories
def get_all_instance_categories(self):
try:
return self.csep_service.get_all_instance_categories_db(session.get('servicepoint_id'))
except Exception as ex:
print_traceback()
LOGGER.error(to_str(ex))
raise ex
示例11: fetch
def fetch(self, page, rows, sidx, sord, **kw):
''' Function called on AJAX request made by FlexGrid
Fetch data from DB, return the list of rows + total + current page
'''
# Try and use grid preference
grid_rows = session.get('grid_rows', None)
if rows=='-1': # Default value
rows = grid_rows if grid_rows is not None else 25
# Save grid preference
session['grid_rows'] = rows
session.save()
rows = int(rows)
try:
page = int(page)
rows = int(rows)
offset = (page-1) * int(rows)
except:
offset = 0
page = 1
rows = 25
apps = DBSession.query(Campaign).filter(Campaign.deleted==None)
total = 1 + apps.count() / rows
column = getattr(Campaign, sidx)
apps = apps.order_by(getattr(column,sord)()).offset(offset).limit(rows)
rows = [ { 'id' : a.cmp_id, 'cell': row(a) } for a in apps ]
return dict(page=page, total=total, rows=rows)
示例12: fetch
def fetch(self, page, rows, sidx, sord, **kw):
""" Function called on AJAX request made by FlexGrid
Fetch data from DB, return the list of rows + total + current page
"""
# Try and use grid preference
grid_rows = session.get("grid_rows", None)
if rows == "-1": # Default value
rows = grid_rows if grid_rows is not None else 25
# Save grid preference
session["grid_rows"] = rows
session.save()
rows = int(rows)
try:
page = int(page)
rows = int(rows)
offset = (page - 1) * int(rp)
except:
offset = 0
page = 1
rows = 25
apps = DBSession.query(Application)
total = apps.count()
column = getattr(Application, sidx)
apps = apps.order_by(getattr(column, sord)()).offset(offset).limit(rows)
rows = [{"id": a.app_id, "cell": row(a)} for a in apps]
return dict(page=page, total=total, rows=rows)
示例13: ajaxAddtoCart
def ajaxAddtoCart( self, **kw ):
_id = kw.get( 'id', None ) or None
if not _id : return {'flag' : 1 , 'msg' : 'No ID provided!'}
try:
items = session.get( 'items', [] )
tmp = {
'_k' : "%s%s" % ( dt.now().strftime( "%Y%m%d%H%M%S" ), random.randint( 100, 10000 ) ) ,
'id' : _id,
}
qs = []
for qk, qv in self._filterAndSorted( "option_qty", kw ):
if not qv : continue
q, _ = qv.split( "|" )
if not q.isdigit() : continue
qs.append( int( q ) )
tmp['qty'] = sum( qs ) if qs else 0
p = qry( Product ).get( _id )
tmp['values'], tmp['optionstext'] = self._formatKW( kw, p )
items.append( tmp )
session['items'] = items
session.save()
return {'flag' : 0 , 'total' : len( session['items'] )}
except:
traceback.print_exc()
return {'flag' : 1, 'msg':'Error occur on the sever side!'}
示例14: ajaxSavetoCart
def ajaxSavetoCart( self, **kw ):
_k = kw.get( "_k", None )
if not _k : return {'flag' : 1 , 'msg' : 'No ID provided!'}
try:
items = session.get( 'items', [] )
for index, item in enumerate( items ):
if item['_k'] != _k : continue
p = qry( Product ).get( item['id'] )
item['values'], item['optionstext'] = self._formatKW( kw , p )
qs = []
for qk, qv in self._filterAndSorted( "option_qty", kw ):
if not qv : continue
q, _ = qv.split( "|" )
if not q.isdigit() : continue
qs.append( int( q ) )
item['qty'] = sum( qs ) if qs else 0
items[index] = item
session['items'] = items
session.save()
return {'flag' : 0 , 'optionstext' : item['optionstext'], }
except:
traceback.print_exc()
return {'flag' : 1 , 'msg' : 'Error occur on the sever side!'}
return {'flag' : 1 , 'msg' : 'No such item!'}
示例15: outcall_fetch
def outcall_fetch(self, page, rows, sidx, sord, cust_id, **kw):
''' Function called on AJAX request made by FlexGrid
Fetch data from DB, return the list of rows + total + current page
'''
# Try and use grid preference
grid_rows = session.get('grid_rows', None)
if rows=='-1': # Default value
rows = grid_rows if grid_rows is not None else 25
# Save grid preference
session['grid_rows'] = rows
session.save()
rows = int(rows)
try:
page = int(page)
rows = int(rows)
offset = (page-1) * int(rp)
except:
offset = 0
page = 1
rows = 25
data = DBSession.query(Outcall, CDR) \
.outerjoin(CDR, Outcall.uniqueid==CDR.uniqueid) \
.filter(Outcall.cust_id==cust_id)
total = 1 + data.count() / rows
column = getattr(Outcall, sidx)
data = data.order_by(getattr(column,sord)()).offset(offset).limit(rows)
rows = [
{ 'id' : a.Outcall.out_id, 'cell': outcall_row(a) } for a in data ]
return dict(page=page, total=total, rows=rows)