本文整理汇总了Python中ututi.lib.helpers.flash函数的典型用法代码示例。如果您正苦于以下问题:Python flash函数的具体用法?Python flash怎么用?Python flash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了flash函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: invitation
def invitation(self, group):
"""Act on the invitation of the current user to this group."""
if hasattr(self, 'form_result'):
invitations = meta.Session.query(PendingInvitation
).filter_by(group=group, user=c.user, active=True
).all()
if invitations:
if self.form_result.get('accept', '') == 'True':
group.add_member(c.user)
if c.user.location is None:
c.user.location = group.location
h.flash(_("Congratulations! You are now a member of the group '%s'") % group.title)
else:
h.flash(_("Invitation to group '%s' rejected.") % group.title)
self._clear_requests(group, c.user)
meta.Session.commit()
came_from = self.form_result.get('came_from', None)
if came_from is None:
redirect(url(controller='group', action='home', id=group.group_id))
else:
redirect(came_from.encode('utf-8'))
else:
redirect(url(controller='group', action='home', id=group.group_id))
示例2: watch_subject
def watch_subject(self):
self._watch_subject()
if request.params.has_key("js"):
return "OK"
else:
h.flash(render_mako_def("subject/flash_messages.mako", "watch_subject", subject=self._getSubject()))
redirect(request.referrer)
示例3: edit_student_group
def edit_student_group(self, id):
try:
group = TeacherGroup.get(int(id))
except ValueError:
abort(404)
if group is None or group.teacher != c.user:
abort(404)
c.student_group = group
defaults = {
'title' : group.title,
'email' : group.email,
'group_id' : group.id
}
if hasattr(self, 'form_result'):
group.title = self.form_result['title']
group.email = self.form_result['email']
group.update_binding()
meta.Session.commit()
message = _(u'Group %(group_title)s (%(group_email)s) updated!') % {
'group_title': group.title,
'group_email': group.email}
h.flash(message)
redirect(url(controller='profile', action='dashboard'))
return htmlfill.render(self._edit_student_group(), defaults=defaults)
示例4: invite_fb
def invite_fb(self, group):
# Handle POST.
invited = request.params.get('ids[]')
if invited:
ids = invited.split(',')
for facebook_id in ids:
group.create_pending_fb_invitation(int(facebook_id), c.user)
make_facebook_invitations(ids, c.user, group.location)
meta.Session.commit()
h.flash(ungettext('Invited %(num)d friend.',
'Invited %(num)d friends.',
len(ids)) % dict(num=len(ids)))
redirect(c.group.url(action='members'))
# Render page.
fb_user = facebook.get_user_from_cookie(request.cookies,
config['facebook.appid'], config['facebook.secret'])
c.has_facebook = fb_user is not None
if c.has_facebook:
try:
graph = facebook.GraphAPI(fb_user['access_token'])
friends = graph.get_object("me/friends")
except facebook.GraphAPIError:
c.has_facebook = False
if not c.has_facebook:
# Ask to log on to facebook.
return render('group/invite.mako')
friend_ids = [f['id'] for f in friends['data']]
friend_users = meta.Session.query(User).filter(
User.facebook_id.in_(friend_ids)).all()
c.exclude_ids = ','.join(str(u.facebook_id) for u in friend_users
if c.group.is_member(u))
return render('group/invite.mako')
示例5: document
def document(self):
resp = request.environ.get('pylons.original_response')
req = request.environ.get('pylons.original_request')
c.came_from = url.current()
if resp is None:
return render("/error.mako")
c.reason = req.environ.get('ututi.access_denied_reason', None)
if resp.status_int in [403, 404]:
self.form_result = {}
self._search()
c.came_from = url('/')
if resp.status_int == 403:
return render("/access_denied.mako")
elif resp.status_int == 404:
h.flash(_("Document at %(url)s was not found, but maybe you are interested in something else?") % {
'url': req.url.encode('ascii', 'ignore')})
# if user is logged in, show search form, otherwise - login form
try:
if session['login']:
return render('/search/index.mako')
except KeyError:
return render('/login.mako')
return render("/error.mako")
示例6: update
def update(self):
values = {
'fullname': None,
'description': None,
'profile_is_public': None,
'url_name': None,
'teacher_position': None,
'teacher_sub_department': None,
}
values.update(self.form_result)
c.user.fullname = values['fullname']
if values['description'] is not None:
# this check is needed because description field
# is currently reused as teacher's information and
# is not displayed for teacher in this form.
c.user.description = values['description']
c.user.profile_is_public = bool(values['profile_is_public'])
c.user.url_name = values['url_name']
if c.user.is_teacher:
c.user.profile_is_public = True # teacher profile always public
c.user.teacher_position = values['teacher_position'] # additional teacher fields
sd_id = values['teacher_sub_department']
if sd_id is not None:
if sd_id != '':
sd = meta.Session.query(SubDepartment).filter_by(id=sd_id).one()
if sd is not None:
c.user.sub_department = sd
else:
c.user.sub_department = None
meta.Session.commit()
h.flash(_('Your profile was updated.'))
redirect(url(controller='profile', action='edit'))
示例7: invite_friends_fb
def invite_friends_fb(self):
# handle facebook callback
ids = request.params.get('ids[]')
if ids:
ids = map(int, ids.split(','))
invited = make_facebook_invitations(ids, c.user, c.user.location)
meta.Session.commit()
if invited:
h.flash(ungettext('Invited %(num)d friend.',
'Invited %(num)d friends.',
len(invited)) % dict(num=len(invited)))
redirect(url(controller='profile', action='home'))
# render page
fb_user = facebook.get_user_from_cookie(request.cookies,
config['facebook.appid'], config['facebook.secret'])
c.has_facebook = fb_user is not None
if c.has_facebook:
try:
graph = facebook.GraphAPI(fb_user['access_token'])
friends = graph.get_object("me/friends")
friend_ids = [f['id'] for f in friends['data']]
friend_users = meta.Session.query(User)\
.filter(User.facebook_id.in_(friend_ids))\
.filter(User.location == c.user.location).all()
c.exclude_ids = ','.join(str(u.facebook_id) for u in friend_users)
except facebook.GraphAPIError:
c.has_facebook = False
return render('profile/invite_friends_fb.mako')
示例8: 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'))
示例9: google_login
def google_login(self):
openid_session = session.get("openid_session", {})
openid_store = None # stateless
cons = Consumer(openid_session, openid_store)
GOOGLE_OPENID = 'https://www.google.com/accounts/o8/id'
openid = GOOGLE_OPENID
try:
authrequest = cons.begin(openid)
except DiscoveryFailure:
h.flash(_('Authentication failed, please try again.'))
redirect(c.came_from or url(controller='home', action='index'))
ax_req = ax.FetchRequest()
ax_req.add(ax.AttrInfo('http://axschema.org/namePerson/first',
alias='firstname', required=True))
ax_req.add(ax.AttrInfo('http://axschema.org/namePerson/last',
alias='lastname', required=True))
ax_req.add(ax.AttrInfo('http://schema.openid.net/contact/email',
alias='email', required=True))
authrequest.addExtension(ax_req)
kargs = self._auth_args()
redirecturl = authrequest.redirectURL(
url('frontpage', qualified=True),
return_to=url(controller='federation', action='google_verify',
qualified=True, **kargs))
session['openid_session'] = openid_session
session.save()
redirect(redirecturl)
示例10: link_google
def link_google(self, registration):
openid_session = session.get("openid_session", {})
openid_store = None # stateless
cons = Consumer(openid_session, openid_store)
GOOGLE_OPENID = 'https://www.google.com/accounts/o8/id'
try:
authrequest = cons.begin(GOOGLE_OPENID)
except DiscoveryFailure:
h.flash(_('Authentication failed, please try again.'))
redirect(registration.url(action='personal_info'))
ax_req = ax.FetchRequest()
ax_req.add(ax.AttrInfo('http://axschema.org/namePerson/first',
alias='firstname', required=True))
ax_req.add(ax.AttrInfo('http://axschema.org/namePerson/last',
alias='lastname', required=True))
ax_req.add(ax.AttrInfo('http://schema.openid.net/contact/email',
alias='email', required=True))
authrequest.addExtension(ax_req)
session['openid_session'] = openid_session
session.save()
realm = url(controller='home', action='index', qualified=True)
return_to = registration.url(action='google_verify', qualified=True)
redirect(authrequest.redirectURL(realm, return_to))
示例11: register_teacher
def register_teacher(self, location):
# bounce existing users to different action
if c.user is not None:
redirect(location.url(action='register_teacher_existing'))
if not hasattr(self, 'form_result'):
return htmlfill.render(self._register_teacher_form())
email = self.form_result['email']
if User.get(email, location):
h.flash(_('The email you entered is registered in Ututi. '
'Please login to proceed.'))
destination = location.url(action='register_teacher_existing')
redirect(url(controller='home', action='login', email=email,
came_from=destination))
# lookup/create registration entry and send confirmation code to user
registration = UserRegistration.create_or_update(location, email)
registration.teacher = True
meta.Session.commit()
registration.send_confirmation_email()
# show confirmation page
c.email = email
return render('registration/email_approval.mako')
示例12: _reject_post
def _reject_post(self, group, thread, redirecturl=None, ajax=False):
success = False
if thread.in_moderation_queue:
thread.reject()
meta.Session.commit()
success = True
if ajax:
if success:
return render_mako_def('mailinglist/administration.mako',
'rejectedMessage')
else:
return render_mako_def('mailinglist/administration.mako',
'warningMessage')
if success:
h.flash(_("Message %(link_to_message)s has been rejected.") % {
'link_to_message': h.link_to(thread.subject, thread.url())
})
else:
h.flash(_("Could not reject %(link_to_message)s as it was already approved.") % {
'link_to_message': h.link_to(thread.subject, thread.url())
})
if redirecturl is None:
redirecturl = group.url(controller='mailinglist', action='administration')
redirect(redirecturl)
示例13: post_anonymous
def post_anonymous(self, group):
post = post_message(group,
c.user,
self.form_result['subject'],
self.form_result['message'])
h.flash(_('Your message to the group was successfully sent.'))
redirect(group.url())
示例14: send_message
def send_message(self):
self._send_message(
self.form_result['group'],
self.form_result['subject'],
self.form_result['message'],
self.form_result.get('category_id', None))
h.flash(_('Message sent.'))
self._redirect()
示例15: delete_email_domain
def delete_email_domain(self, id):
domain = EmailDomain.get(id)
if domain is not None:
domain.delete()
meta.Session.commit()
else:
h.flash('Email domain with id %s does not exist' % id)
redirect(url(controller='admin', action='email_domains'))