本文整理汇总了Python中pylons.session.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
def login(self):
""" Show login form.
"""
if request.method != 'POST':
return render('login.html')
# Verify username and password.
auth_fact = AuthFactory()
auth = auth_fact.get_auth(request.params.get('username'), request.params.get('password'), 'nipap')
if not auth.authenticate():
c.error = 'Invalid username or password'
return render('login.html')
# Mark user as logged in
session['user'] = auth.username
session['full_name'] = auth.full_name
session.save()
# Send user back to the page he originally wanted to get to
if session.get('path_before_login'):
log.error(session.get('path_before_login'))
redirect(session['path_before_login'])
else:
# if previous target is unknown just send the user to a welcome page
redirect(url(controller='schema', action='list'))
示例2: archive
def archive(self, page=1, direction='dsc',
order_by='timestamp', format=None):
"messages archive"
filters = session.get('filter_by', None)
num_items = session.get('msgs_num_items', 50)
if direction == 'dsc':
sort = desc(order_by)
else:
sort = order_by
messages = self._get_archived().order_by(sort)
msgcount = self._get_msg_count(True)
query = UserFilter(Session, c.user, messages, True)
countquery = UserFilter(Session, c.user, msgcount, True)
messages = query.filter()
msgcount = countquery.filter()
if filters:
dynq = DynaQuery(Archive, messages, filters)
dynmsgq = DynaQuery(Archive, msgcount, filters)
messages = dynq.generate()
msgcount = dynmsgq.generate()
c.order_by = order_by
c.direction = direction
msgcount = msgcount.count()
pages = paginate.Page(messages, page=int(page),
items_per_page=num_items,
item_count=msgcount)
if format == 'json':
response.headers['Content-Type'] = 'application/json'
data = convert_to_json(pages,
direction=direction,
order_by=order_by,
section=None)
return data
c.page = pages
return render('/messages/archive.html')
示例3: more
def more(self, id=None):
# id will be something like d_ping_[ping.id]
# so, I want to get a ping where id > that one.
pid = id.split('_')[-1]
try:
pid = int(pid)
except:
log.debug("couldn't identify the ping %s "%id)
return ""
c.username = session.get('user')
c.fl_mod = session.get('mod',False)
for ping in PseudoPing.query().filter(
PseudoPing.fl_decided==False).filter(PseudoPing.id>pid).order_by(PseudoPing.id):
img = ping.Image_fromPing()
if img.in_pool():
c.ping=ping
c.image=ping.image
c.atts = img.all_atts()
return render('one_ping.mako')
else:
ping.fl_decided=True
ping.commit()
#Guess what. We're empty. get to bottom, go back to top. But this time, we need
# to send back the newest image, rather than the next oldest one.
if not self._reload():
return
return self.more(id)
示例4: autorize
def autorize():
loged_in = session.get("loged_in")
if loged_in:
email = session.get("email")
password = session.get("password")
pers = Session.query(Person).filter_by(email=email, password=password).first()
pers.last_activity = int(time.time())
Session.commit()
return True
if "email" and "password" in request.cookies:
email = request.cookies.get("email")
password = request.cookies.get("password")
elif request.method == "POST" and "email" in request.POST:
email = request.POST.get("password")
password = md5(request.POST.get("password"))
else:
return False
pers = Session.query(Person).filter_by(email=email, password=password).first()
if pers:
print "pers is ", pers
session["email"] = email
session["password"] = password
session["loged_in"] = True
session["name"] = pers.name
session["person_id"] = pers.id
session.save()
return True
return False
示例5: old_index
def old_index(self):
user_id = session.get('user_id')
c.user = session['user']
if not user_id:
raise Exception
# User Info
user = meta.Session.query(User).filter(User.id == session.get('user_id')).one()
accounts = meta.Session.query(Account).filter(sa.and_(Account.authkey_id != None , Account.user_id == session.get('user_id')));
dataString = []
accountHost = {}
for account in accounts:
if accountHost.get(account.resource.hostname, True):
accountDict = {}
accountDict['name'] = account.name
accountDict['hostname'] = account.resource.hostname
dataString.append(accountDict)
accountHost[account.resource.hostname] = False
## c.passwordLessAccount = dataString
meta.Session.close()
c.status = "index"
c.results = ""
#return render('/authentication/gsicreds/gsicreds.mako')
redirect(url(controller='gsicreds', action='gsicreds'))
示例6: index
def index(self):
c.clients_quan = meta.Session.query(sidb.Client).count()
c.sorts = [('name', sidb.Client.name), ('prdate', sidb.Tmppricesstorage.price_date), ('tmpitems', sidb.Tmppricesstorage.tmpitems_quan)]
c.sort_col = request.GET.get("sort_field", 'name')
sort_field = dict(c.sorts).get(c.sort_col)
c.sort_rule = request.GET.get("sort_rule", 'asc')
sort_field = (c.sort_rule == 'desc' and sort_field.desc() or sort_field.asc())
for key, value in request.POST.iteritems():
if key in ['s_name', 's_country', 's_city']: session[key] = value
session.save()
c.s_name = session.has_key('s_name') and session.get('s_name') or u''
c.s_country = session.has_key('s_country') and session.get('s_country') or u''
c.s_city = session.has_key('s_city') and session.get('s_city') or u''
clients_list = meta.Session.query(sidb.Client, sidb.City, sidb.Country, sidb.Clientlogo, sidb.User, sidb.Tmppricesstorage.rid.label('storage_rid'),
sidb.Tmppricesstorage.tmpitems_quan, sidb.Tmppricesstorage.price_date).\
join((sidb.City, sidb.Client._cities_rid == sidb.City.rid)).\
join((sidb.Region, sidb.City._regions_rid == sidb.Region.rid)).\
join((sidb.Country, sidb.Region._countries_rid == sidb.Country.rid)).\
outerjoin((sidb.User, sidb.User._clients_rid == sidb.Client.rid)).\
outerjoin((sidb.Clientlogo, sidb.Clientlogo._clients_rid == sidb.Client.rid)).\
outerjoin((sidb.Tmppricesstorage, sidb.Tmppricesstorage._clients_rid == sidb.Client.rid)).\
group_by(sidb.Client.rid).order_by(sort_field)
if c.s_name: clients_list = clients_list.filter(sidb.Client.name.like('%'+c.s_name+'%'))
if c.s_country: clients_list = clients_list.filter(sidb.Country.name.like('%'+c.s_country+'%'))
if c.s_city: clients_list = clients_list.filter(sidb.City.name.like('%'+c.s_city+'%'))
page = paginate.Page(clients_list, items_per_page=15, page=request.GET.get("page", 1), sort_col=c.sort_col, sort_rule=c.sort_rule)
c.pager = page.pager()
c.clients_list = page.items
c.subtempl = 'clients_list'
return render('be/layouts/clients.html')
示例7: show
def show(name):
if session.get(ALLKEY, False):
return False
elif session.get(ONEKEY % name):
return False
else:
return True
示例8: openid_register
def openid_register(self):
openid_url = session.get('openid_identity')
if not openid_url:
redirect(url('account_register'))
c.openid = session.get('openid_identity')
c.defaults = {}
return render('/accounts/register.mako')
示例9: index
def index(self):
gd_client = gdata.photos.service.PhotosService()
#token = request.GET.getone('token')
parameters = cgi.FieldStorage()
token = parameters['token']
gd_client.auth_token = token
gd_client.UpgradeToSessionToken()
session['picasa_token'] = token
session.save()
if session.get('user_id'):
# a user is already logged in
user = Session.query(User).filter_by(id=session.get('user_id')).first()
else:
# the user is not already logged in, let's see if they have
# already created an account before
user = Session.query(User).filter_by(picasa_token=token).first()
if user:
user.picasa_token = token
Session.commit()
else:
# the user does not have an account. We need to create a new one
# for them.
user = User(picasa_token=token)
Session.add(user)
Session.commit()
user = Session.query(User).filter_by(picasa_token=picasa_token).first()
session['user_id'] = user.id
session['picasa_token'] = token
session.save()
log.info("Logged in user %s", user)
redirect(url('index'))
示例10: __before__
def __before__(self, action, **params):
c.user = session.get('user')
c.messages = session.get('messages', [])
c.errors = session.get('errors', [])
session['messages'] = []
session['errors'] = []
session.save()
示例11: set_pos_zoom
def set_pos_zoom(self,latlon=None,zoom=None):
#print "Setting pos to %s"%(latlon,)
if latlon==None:
assert zoom==None
zoomlevel=session.get('zoom',None)
if zoomlevel==None:
zoomlevel=5
merc_x,merc_y=mapper.latlon2merc((58,18),zoomlevel)
else:
merc_x,merc_y=session['last_pos']
else:
assert zoom!=None
zoomlevel=zoom
if zoomlevel<5:
zoomlevel=5
if session.get('mapvariant',None)=='elev':
if zoomlevel>8: zoomlevel=8
else:
if zoomlevel>13: zoomlevel=13
merc_x,merc_y=mapper.latlon2merc(latlon,zoomlevel)
merc_limx1,merc_limy1,merc_limx2,merc_limy2=merc_limits(zoomlevel,conservative=False,hd=True)
if merc_x>merc_limx2: merc_x=merc_limx2
if merc_y>merc_limy2: merc_y=merc_limy2
if merc_x<merc_limx1: merc_x=merc_limx1
if merc_y<merc_limy1: merc_y=merc_limy1
session['last_pos']=(merc_x,merc_y)
session['zoom']=zoomlevel
print "Setting pos to %s, zoom = %d"%(mapper.merc2latlon(session['last_pos'],zoomlevel),zoomlevel)
session.save()
示例12: if_findpasswd
def if_findpasswd(self):
servername = session.get('servername', "NULL")
username = session.get('username', "NULL")
if servername!="NULL":
c.servername = servername
if username!="NULL":
c.username=username
username = request.params.get('username')
newpasswd=request.params.get('newpasswd')
newpasswdrepeat=request.params.get('newpasswdrepeat')
if newpasswd != newpasswdrepeat:
c.errorMsg = "两次输入密码不相同,请重新输入"
return render("result_find_passwd.mako")
if len(base64.decodestring(newpasswd))<6 or len(base64.decodestring(newpasswd))>64:
c.errorMsg="密码长度必须在6-64之间"
return render("result_find_passwd.mako")
try:
con = MySQLdb.connect(host = g.dbhost, user = g.dbuser, passwd = g.dbpasswd, db = g.dbdb, port = g.dbport, charset = "utf8")
cur = con.cursor()
cur.execute("update users set password=%s where username =%s", (newpasswd,username))
con.commit()
except MySQLdb.Error as e:
print "mysql error %d: %s" %(e.args[0], e.args[1])
c.errorMsg = "往数据库插入新密码错误"
finally:
if con != None:
con.close()
return render("index.mako")
示例13: _gccom_jobs
def _gccom_jobs(self, model_key, mode):
c.jobstate = 'build'
c.jobmsg = 'build: setting up the job. before submission.'
c.model_key = model_key
c.mode = mode
c.error_flash = None
if session.has_key('error_flash'):
c.error_flash = session['error_flash']
try: del session['error_flash']
except Exception as _: pass
c.jobname = '%s_%s' % (model_key, mode)
c.cwuser = session.get('user','user')
c.acct = Gccom.gccom_comm_acct
c.model_param_hdrs = Gccom.model_params['hdrs']
c.model_params = Gccom.model_params[c.model_key]
c.model_desc = str(Gccom.model_info[c.model_key]['desc'])
c.title = 'GCOM %s Simulation: Model:%s for JobName: %s' % (
c.mode, str(c.model_desc), c.jobname)
c.resources = h.get_user_resources(session.get('user_id'))
c.hostname = c.resources.keys()[0] if c.resources else '' #used to init/set default host; reset later
c.grid_key = Gccom.model_info[c.model_key]['grid_key']
c.grid_imax = Gccom.bath_grid[c.grid_key]['IMax']
c.grid_jmax = Gccom.bath_grid[c.grid_key]['JMax']
c.grid_kmax = Gccom.bath_grid[c.grid_key]['KMax']
c.grid_name = Gccom.bath_grid[c.grid_key]['name']
c.grid_fname = Gccom.bath_grid[c.grid_key]['fname']
log.info( 'GCOM:: gccom_jobs: building form data for model_key=%s, desc=%s, jobstate= %s, jobname= %s, gridname= %s, gridfnam=%s' % (c.model_key, c.model_desc,c.jobstate, c.jobname, c.grid_name, c.grid_fname))
return render('/gcem/gccom/app_' + c.mode.lower() + '.mako')
示例14: BaseController_UpdateUserHeader
def BaseController_UpdateUserHeader(self):
# Is the user already logged-in?
if session.get("UserName"):
# User info
c.user_login = "Log Out"
c.user_loginurl = "logout"
c.user_pref = "Preferences"
c.user_prefurl = "preferences"
c.user_name = session.get("UserName")
c.user_points = session.get("UserPoints")
c.user_icon = session.get("UserIconID")
c.is_admin = session.get("IsAdmin")
# Nope! Default to basic URLs
else:
# User info
c.user_login = "Log In"
c.user_loginurl = "login"
c.user_pref = "Register"
c.user_prefurl = "register"
c.user_name = ""
c.user_points = 0
c.user_icon = 0
c.is_admin = False
# Top-bar directory info
c.group_name = ""
c.group_id = -1
c.challenge_name = ""
c.challenge_id = -1
示例15: get
def get(self, domain):
username = request.params.get('username')
userid = request.params.get('userid')
group = request.params.get('group', None)
startIndex = int(request.params.get('startindex','0'))
maxResults = int(request.params.get('maxresults','25'))
keys = session.get('account_keys', '').split(',')
if not keys:
error = {'provider': domain,
'message': "no user session exists, auth required",
'status': 401
}
return {'result': None, 'error': error}
provider = get_provider(domain)
# even if we have a session key, we must have an account for that
# user for the specified domain.
acct = None
for k in keys:
a = session.get(k)
if a and a.get('domain') == domain and (not username or a.get('username')==username and not userid or a.get('userid')==userid):
acct = a
break
if not acct:
error = {'provider': domain,
'message': "not logged in or no user account for that domain",
'status': 401
}
return {'result': None, 'error': error}
result, error = provider.api(acct).getcontacts(startIndex, maxResults, group)
return {'result': result, 'error': error}