本文整理汇总了Python中pylons.url函数的典型用法代码示例。如果您正苦于以下问题:Python url函数的具体用法?Python url怎么用?Python url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了url函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
def delete(self, repo_name):
"""DELETE /repos/repo_name: Delete an existing item"""
# Forms posted to this method should contain a hidden field:
# <input type="hidden" name="_method" value="DELETE" />
# Or using helpers:
# h.form(url('repo_settings_delete', repo_name=ID),
# method='delete')
# url('repo_settings_delete', repo_name=ID)
repo_model = RepoModel()
repo = repo_model.get_by_repo_name(repo_name)
if not repo:
h.not_mapped_error(repo_name)
return redirect(url('home'))
try:
action_logger(self.rhodecode_user, 'user_deleted_repo',
repo_name, self.ip_addr, self.sa)
repo_model.delete(repo)
invalidate_cache('get_repo_cached_%s' % repo_name)
h.flash(_('deleted repository %s') % repo_name, category='success')
Session().commit()
except Exception:
log.error(traceback.format_exc())
h.flash(_('An error occurred during deletion of %s') % repo_name,
category='error')
return redirect(url('admin_settings_my_account', anchor='my'))
示例2: logout
def logout(self):
'''
This action deletes the cookie and redirects to the
/openid/status to show the login status
If the logout is called in the context of an openid authentication,
the user is already logged in as a different user. In this case we
forward to the /openid/login page after the logout was made.
Another option for the openid authentication context would be to
redirect to the return_to url by setting
redirect_to = params["openid.return_to"]
p["openid.mode"] = "setup_needed"
which advises the openid relying party to restart the login process.
'''
response.delete_cookie(COOKIE_NAME)
params = {}
params.update(request.params)
p = {}
## are we are called during an openid auth request?
if "openid.return_to" in params:
redirect_to = "/openid/login"
p.update(params)
do_redirect = url(str("%s?%s" % (redirect_to, urlencode(p))))
else:
redirect_to = "/openid/status"
do_redirect = url(str("%s?%s" % (redirect_to, urlencode(p))))
redirect(do_redirect)
示例3: loggedout
def loggedout(self):
"Logged out page"
session.clear()
session.save()
came_from = (unquote(str(request.params.get('came_from', '')))
or url('/accounts/login'))
redirect(url(came_from))
示例4: rss
def rss(self, repo_name):
"""Produce an rss2 feed via feedgenerator module"""
feed = Rss201rev2Feed(
title=self.title % repo_name,
link=url('summary_home', repo_name=repo_name,
qualified=True),
description=self.description % repo_name,
language=self.language,
ttl=self.ttl
)
for cs in reversed(list(c.rhodecode_repo[-self.feed_nr:])):
desc_msg = []
desc_msg.append('%s - %s<br/><pre>' % (cs.author, cs.date))
desc_msg.append(self.__changes(cs))
feed.add_item(title=self._get_title(cs),
link=url('changeset_home', repo_name=repo_name,
revision=cs.raw_id, qualified=True),
author_name=cs.author,
description=''.join(desc_msg),
)
response.content_type = feed.mime_type
return feed.writeString('utf-8')
示例5: welcome
def welcome(self):
identity = request.environ.get("repoze.who.identity")
came_from = request.params.get('came_from') or "/"
came_from = unquote(came_from)
came_from = unquote(came_from)
came_from = unquote(came_from)
came_from = str(came_from)
if identity:
# Login succeeded
userid = identity['repoze.who.userid']
#user_det = get_mediator_details(userid)
#if user_det['name']:
# session['user_name'] = user_det['name']
#if user_det['uri']:
# session['user_uri'] = str(user_det['uri'])
session['user_id'] = userid
session.save()
return redirect(url(came_from))
else:
# Login failed
try:
login_counter = request.environ['repoze.who.logins'] + 1
except:
login_counter = 0
destination = "/login?came_from=%s&logins=%s" % (came_from, login_counter)
return redirect(url(destination))
示例6: delete_my_account
def delete_my_account(self):
if hasattr(self, 'form_result'):
h.flash(_('Your account has been successfully removed!'))
c.user.delete_user()
meta.Session.commit()
redirect(url(controller='home', action='logout'))
redirect(url(controller='profile', action='login_settings'))
示例7: login_validate
def login_validate(self):
if (c.userid != "false"):
redirect(url('/users/login?m=2'))
session['logged_in'] = True
session.save()
if request.method == 'POST':
loginform = LoginForm(request.POST)
if loginform.is_valid():
userid = authenticate_user(loginform.cleaned_data['email'], \
loginform.cleaned_data['password'])
if (userid != "invalid" ):
session['userid'] = userid
session.save()
print session['userid']
c.login = "valid"
print loginform.cleaned_data['redirect']
if request.POST['redirect']=='null':
redirect(url('/'))
else:
redirect(url(str(loginform.cleaned_data['redirect'])))
else:
c.login = "invalid"
c.form = LoginForm(request.POST)
return render("/users/login.mako")
else:
c.form = LoginForm(request.POST)
return render("/users/login.mako")
redirect(url('/'))
示例8: test_new_wrong_user
def test_new_wrong_user(self):
# First we add a Dataset with user 'test_new'
user = Account.by_name('test_new')
assert user.api_key == 'd0610659-627b-4403-8b7f-6e2820ebc95d'
u = url(controller='api/version2', action='create')
params = {
'metadata':
'https://dl.dropbox.com/u/3250791/sample-openspending-model.json',
'csv_file':
'http://mk.ucant.org/info/data/sample-openspending-dataset.csv'
}
apikey_header = 'apikey {0}'.format(user.api_key)
response = self.app.post(u, params, {'Authorization': apikey_header})
assert "200" in response.status
assert Dataset.by_name('openspending-example') is not None
# After that we try to update the Dataset with user 'test_new2'
user = Account.by_name('test_new2')
assert user.api_key == 'c011c340-8dad-419c-8138-1c6ded86ead5'
u = url(controller='api/version2', action='create')
params = {
'metadata':
'https://dl.dropbox.com/u/3250791/sample-openspending-model.json',
'csv_file':
'http://mk.ucant.org/info/data/sample-openspending-dataset.csv'
}
apikey_header = 'apikey {0}'.format(user.api_key)
response = self.app.post(u, params, {'Authorization': apikey_header},
expect_errors=True)
assert '403' in response.status
示例9: submit
def submit(self):
"""
Verify username and password
"""
# Both fields filled?
form_username = str(request.params.get("username"))
form_password = str(request.params.get("password"))
m = hashlib.md5()
m.update(form_password)
passhash = m.hexdigest()
# Get user data from database
if app_globals.rpcservice.check_admin(form_username, passhash):
# Mark admin as logged in
session["user"] = form_username
session["passhash"] = passhash
session.save()
return redirect(url(controller="syncuser", action="index"))
if app_globals.rpcservice.check_user(form_username, passhash):
# Mark user as logged in
session["user"] = form_username
session["passhash"] = passhash
session.save()
return redirect(url(controller="account"))
return redirect(url.current(action="invalid"))
示例10: job_insert
def job_insert(self):
if (c.userid == "false"):
redirect(url('/users/login?m=1'))
#extra_questions = get_questions(request)
#form = UserCreationForm(request.POST or None, extra=extra_questions)
if request.method == 'POST':
appname = request.POST['appname']
if (appname =='tophatfusion'):
c.form = tophatfusionForm(request.POST,request.POST )
elif (appname =='bfast') :
c.form = bfastForm(request.POST,request.POST )
elif (appname =='chipseq') :
c.form = chipseqForm(request.POST,request.POST )
if c.form.is_valid():
#add using job queue
jobid =add_job(c.userid)
for key in c.form.cleaned_data:
print "key", key
print "value", c.form.cleaned_data[key]
newjobinfo = model.jobinfo()
newjobinfo.key = key
newjobinfo.value = c.form.cleaned_data[key]
newjobinfo.submitted_time = time.asctime()
newjobinfo.jobid = jobid
add_jobinfo(newjobinfo)
update_job_status(jobid, str(JOBSTATES.NEW))
redirect(url('/ngs/job_table_view?m=1&id=' + str(jobid) ))
else:
return render('/forms/chipseq_form.mako')
示例11: test_aggregate_order
def test_aggregate_order(self):
def unique(seq):
result = []
for item in seq:
if item not in result:
result.append(item)
return result
response = self.app.get(url(controller='api/version2',
action='aggregate',
dataset='cra', order='year:asc',
drilldown='year'))
assert response.status == '200 OK'
result = json.loads(response.body)
order = [cell['year'] for cell in result['drilldown']]
expected_result = map(unicode, [2003, 2004, 2005, 2006, 2007,
2008, 2009, 2010])
assert unique(order) == expected_result
response = self.app.get(url(controller='api/version2',
action='aggregate',
dataset='cra', order='year:desc',
drilldown='year'))
assert response.status == '200 OK'
result = json.loads(response.body)
order = [cell['year'] for cell in result['drilldown']]
expected_result = map(unicode, [2010, 2009, 2008, 2007, 2006,
2005, 2004, 2003])
assert unique(order) == expected_result
示例12: delete
def delete(self, group_name):
"""DELETE /repos_groups/group_name: Delete an existing item"""
# Forms posted to this method should contain a hidden field:
# <input type="hidden" name="_method" value="DELETE" />
# Or using helpers:
# h.form(url('repos_group', group_name=GROUP_NAME),
# method='delete')
# url('repos_group', group_name=GROUP_NAME)
gr = c.repos_group = ReposGroupModel()._get_repo_group(group_name)
repos = gr.repositories.all()
if repos:
h.flash(_('This group contains %s repositores and cannot be '
'deleted') % len(repos), category='warning')
return redirect(url('repos_groups'))
children = gr.children.all()
if children:
h.flash(_('This group contains %s subgroups and cannot be deleted'
% (len(children))), category='warning')
return redirect(url('repos_groups'))
try:
ReposGroupModel().delete(group_name)
Session().commit()
h.flash(_('Removed repository group %s') % group_name,
category='success')
#TODO: in future action_logger(, '', '', '', self.sa)
except Exception:
log.error(traceback.format_exc())
h.flash(_('Error occurred during deletion of repository group %s')
% group_name, category='error')
return redirect(url('repos_groups'))
示例13: public_journal_rss
def public_journal_rss(self):
"""
Produce an rss2 feed via feedgenerator module
"""
c.following = self.sa.query(UserFollowing)\
.filter(UserFollowing.user_id == self.rhodecode_user.user_id)\
.options(joinedload(UserFollowing.follows_repository))\
.all()
journal = self._get_journal_data(c.following)
feed = Rss201rev2Feed(title=self.title % 'rss',
link=url('public_journal_rss', qualified=True),
description=_('Public journal'),
language=self.language,
ttl=self.ttl)
for entry in journal[:self.feed_nr]:
#tmpl = h.action_parser(entry)[0]
action, action_extra = h.action_parser(entry, feed=True)
title = "%s - %s %s" % (entry.user.short_contact, action,
entry.repository.repo_name)
desc = action_extra()
feed.add_item(title=title,
pubdate=entry.action_date,
link=url('', qualified=True),
author_email=entry.user.email,
author_name=entry.user.full_contact,
description=desc)
response.content_type = feed.mime_type
return feed.writeString('utf-8')
示例14: _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')
示例15: post_edit_statement
def post_edit_statement(self, id):
if not c.user:
# should not happen therefore no c.returnTo
redirect(url(controller='login', action='signin', id=id))
query = meta.Session.query(model.Statement)
thesis = query.filter_by(id=id).first().attachTrueFalseCount()
if not c.user.allow_edit(thesis):
raise Exception('no you dont')
newMsg = request.params.get('msg')
if len(stripMarkup(newMsg)) > int(statement_length):
h.flash(_("Error: Only %s characters are allowed!") % statement_length)
c.previousMessage = newMsg
return self.edit_statement(id)
thesis.message = newMsg
meta.Session.commit()
search.update_index(thesis)
redirect(url(controller, 'statements', action='show', id=id))