本文整理汇总了Python中pylons.session.pop函数的典型用法代码示例。如果您正苦于以下问题:Python pop函数的具体用法?Python pop怎么用?Python pop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pop函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: authenticated_user
def authenticated_user(reload=False):
"""
Returns reference to AuthenticatedUser which is stored in session.
If it's not in session method will add it and save session, then return object.
"""
AUTHENTICATED_USER = "AUTHENTICATED_USER"
# Create authenticated user if it doesn't exist
if request.environ.has_key('REMOTE_USER'):
if reload or not session.has_key(AUTHENTICATED_USER) \
or session[AUTHENTICATED_USER] == None \
or session[AUTHENTICATED_USER].username != request.environ['REMOTE_USER']:
model = request.environ['sqlalchemy.model']
db = request.environ['sqlalchemy.session']
try:
authenticated_user = db.query(model.AuthenticatedUser).filter_by(username=request.environ['REMOTE_USER']).one()
except:
authenticated_user = model.AuthenticatedUser(
username = request.environ['REMOTE_USER'], email = request.environ['REMOTE_USER'])
db.save(authenticated_user)
db.commit()
log.info(_("Created an %s" % (str(authenticated_user))))
db.expunge(authenticated_user)
session[AUTHENTICATED_USER] = authenticated_user
session.save()
return session[AUTHENTICATED_USER]
if session.has_key(AUTHENTICATED_USER):
session.pop(AUTHENTICATED_USER, None)
session.save()
return None
示例2: logout
def logout(self):
if "user" not in session:
return redirect("/")
else:
session.pop("user")
session.save()
return redirect("/")
示例3: index
def index(self):
c.user_name = session.pop('user_name', '')
c.user_url = session.pop('user_url', '')
c.user_phone = session.pop('user_phone', '')
c.user_email = session.pop('user_email', '')
c.capcha_error = session.pop('capcha_error', '')
session.save()
return render('/register_user.mako.html')
示例4: import_metadata
def import_metadata(self, **kwargs):
if request.method == 'POST':
redirect_url = self._import_metadata(request.params)
redirect(redirect_url)
else:
c.group_id = request.params.get('group')
c.error_summary = session.pop('error_summary', None)
c.errors = session.pop('errors', None)
c.result = session.pop('result', None)
return render('package/import_metadata.html')
示例5: logout
def logout(self):
if 'user' not in session:
session['flash'] = 'Not logged in'
session.save()
return redirect('/')
else:
session.pop('user')
session.save()
session['flash'] = 'Successfully logged out'
session.save()
return redirect('/')
示例6: _process_contact
def _process_contact(self):
# Validate secure_form's (CSRF protection) token
if not (request.params.get(secure_form.token_key) == secure_form.authentication_token()):
abort (403, detail=u'Not permitted (possible CSRF attack)')
# If cancelled, dont do anything
if request.params.get('op') != 'Submit':
session.pop('contactform.errors', None)
session.pop('contactform.values', None)
return url(controller='contactform', action='nevermind')
# Validate form fields ...
schema = ContactForm()
try:
fields = schema.to_python(dict(request.params))
session.pop('contactform.errors', None)
session.pop('contactform.values', None)
self._save_contact(fields, schema)
return url(controller='contactform', action='thanks')
except formencode.Invalid, ex:
session.update({
'contactform.errors': ex.error_dict,
'contactform.values': ex.value,
})
return url(controller='contactform', action='contact')
示例7: do_signin
def do_signin(self):
path_before_login = session.pop("path_before_login", self.default_path)
g = self._py_object.app_globals
# disable api check in *.ini config
if g.check_api:
api = eveapi.EVEAPIConnection()
auth = api.auth(userID=c.api_userid, apiKey=c.api_key)
def check_character(name):
try:
result = auth.account.Characters()
except eveapi.Error, e:
c.errors.add(e.args[0])
return None
for char in result.characters:
if char.name == name:
return char
return None
def get_corp(char):
try:
result = auth.corp.CorporationSheet(characterID=char.characterID)
except eveapi.Error, e:
c.errors.add(e.args[0])
return None
return result
示例8: logged_in
def logged_in(self):
# we need to set the language via a redirect
lang = session.pop('lang', None)
session.save()
# we need to set the language explicitly here or the flash
# messages will not be translated.
ckan.lib.i18n.set_lang(lang)
if c.user:
context = {'model': model,
'user': c.user}
data_dict = {'id': c.user}
user_dict = get_action('user_show')(context, data_dict)
h.flash_success(_("%s is now logged in") %
user_dict['display_name'])
return self.me(locale=lang)
else:
err = _('Login failed. Bad username or password.')
if g.openid_enabled:
err += _(' (Or if using OpenID, it hasn\'t been associated '
'with a user account.)')
h.flash_error(err)
h.redirect_to(locale=lang, controller='user', action='login')
示例9: logged_in
def logged_in(self):
# we need to set the language via a redirect
lang = session.pop("lang", None)
session.save()
came_from = request.params.get("came_from", "")
# we need to set the language explicitly here or the flash
# messages will not be translated.
i18n.set_lang(lang)
if c.user:
context = None
data_dict = {"id": c.user}
user_dict = get_action("user_show")(context, data_dict)
h.flash_success(_("%s is now logged in") % user_dict["display_name"])
if came_from:
return h.redirect_to(str(came_from))
return self.me()
else:
err = _("Login failed. Bad username or password.")
if g.openid_enabled:
err += _(" (Or if using OpenID, it hasn't been associated " "with a user account.)")
if h.asbool(config.get("ckan.legacy_templates", "false")):
h.flash_error(err)
h.redirect_to(locale=lang, controller="user", action="login", came_from=came_from)
else:
return self.login(error=err)
示例10: login
def login(self, error=None):
lang = session.pop('lang', None)
if lang:
session.save()
return h.redirect_to(locale=str(lang), controller='user',
action='login')
if 'error' in request.params:
h.flash_error(request.params['error'])
if request.environ['SCRIPT_NAME'] and g.openid_enabled:
# #1662 restriction
log.warn('Cannot mount CKAN at a URL and login with OpenID.')
g.openid_enabled = False
if not c.user:
came_from = request.params.get('came_from', '')
c.login_handler = h.url_for(
self._get_repoze_handler('login_handler_path'),
came_from=came_from)
if error:
vars = {'error_summary': {'': error}}
else:
vars = {}
return render('user/login.html', extra_vars=vars)
else:
return render('user/logout_first.html')
示例11: pop_messages
def pop_messages(self):
from pylons import session
messages = session.pop(self.session_key, [])
# only save session if it has changed
if messages:
session.save()
return [Message(*m) for m in messages]
示例12: logged_in
def logged_in(self):
# we need to set the language via a redirect
lang = session.pop('lang', None)
session.save()
came_from = request.params.get('came_from', '')
# we need to set the language explicitly here or the flash
# messages will not be translated.
i18n.set_lang(lang)
if c.user:
context = None
data_dict = {'id': c.user}
user_dict = get_action('user_show')(context, data_dict)
h.flash_success(_("%s is now logged in") %
user_dict['display_name'])
if came_from:
return h.redirect_to(str(came_from))
return self.me()
else:
err = _('Login failed. Bad username or password.')
if g.openid_enabled:
err += _(' (Or if using OpenID, it hasn\'t been associated '
'with a user account.)')
if h.asbool(config.get('ckan.legacy_templates', 'false')):
h.flash_error(err)
h.redirect_to(locale=lang, controller='user',
action='login', came_from=came_from)
else:
return self.login(error=err)
示例13: pop_message
def pop_message(self):
message = session.pop("flash", None)
session['flash'] = None
session.save()
if not message:
return None
return message
示例14: logged_in
def logged_in(self):
# we need to set the language via a redirect
lang = session.pop('lang', None)
session.save()
# we need to set the language explicitly here or the flash
# messages will not be translated.
i18n.set_lang(lang)
if c.user:
is_new = False
is_sysadmin = new_authz.is_sysadmin(c.user)
# Retrieve information about the current user
context = {'model': model, 'session': model.Session,
'user': c.user or c.author,
'schema': schema.user_new_form_schema()}
data_dict = {'id': c.user}
user_dict = get_action('user_show')(context, data_dict)
# This check is not needed (or correct) for sys admins
if not is_sysadmin:
# Get all organizations and all groups the user belongs to
orgs_q = model.Session.query(model.Group) \
.filter(model.Group.is_organization == True) \
.filter(model.Group.state == 'active')
q = model.Session.query(model.Member) \
.filter(model.Member.table_name == 'user') \
.filter(model.Member.table_id == user_dict['id'])
group_ids = []
for row in q.all():
group_ids.append(row.group_id)
if not group_ids:
is_new = True
else:
orgs_q = orgs_q.filter(model.Group.id.in_(group_ids))
orgs_list = model_dictize.group_list_dictize(orgs_q.all(), context)
if len(orgs_list) == 0:
is_new = True
h.flash_success(_("<p><strong>Note</strong></p>"
"<p>%s is now logged in</p>") %
user_dict['display_name'], allow_html=True)
if is_new:
return h.redirect_to(controller='ckanext.canada.controller:CanadaController',
action='view_new_user', locale=lang)
else:
return h.redirect_to(controller='package',
action='search', locale=lang)
else:
h.flash_error(_('Login failed. Bad username or password.'))
return h.redirect_to(controller='user',
action='login', locale=lang)
示例15: pop_messages
def pop_messages(self):
"""Return all accumulated messages and delete them from the session.
The return value is a list of ``Message`` objects.
"""
from pylons import session
messages = session.pop(self.session_key, [])
session.save()
return [_Message(*m) for m in messages]