本文整理汇总了Python中nuorisovaalitadmin.models.DBSession.delete方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.delete方法的具体用法?Python DBSession.delete怎么用?Python DBSession.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nuorisovaalitadmin.models.DBSession
的用法示例。
在下文中一共展示了DBSession.delete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PasswordResetView
# 需要导入模块: from nuorisovaalitadmin.models import DBSession [as 别名]
# 或者: from nuorisovaalitadmin.models.DBSession import delete [as 别名]
class PasswordResetView(object):
"""Password reset logic."""
def __init__(self, request):
self.request = request
self.session = DBSession()
self.prune_expired()
def prune_expired(self):
"""Prunes password reset requests that have expired."""
self.session.query(PasswordReset)\
.filter(PasswordReset.expires < datetime.now())\
.delete()
def render_form(self):
"""Renders the password reset form."""
return {
'action_url': route_url('reset_password_initiate', self.request),
'title': u'Nollaa salasana',
}
def password_change_form(self):
"""Renders the form for changing a password for a valid token."""
log = logging.getLogger('nuorisovaalitadmin')
reset = self.session.query(PasswordReset)\
.filter(PasswordReset.token == self.request.matchdict['token'])\
.filter(PasswordReset.expires >= datetime.now())\
.first()
if reset is None:
log.warn('Unknown password reset token: {token}.'.format(**self.request.matchdict))
# No matching password reset found
raise NotFound
user = self.session.query(User).get(reset.user_id)
if user is None:
log.warn('Unknown user "{0}" for password reset.'.format(reset.user_id))
raise NotFound
return {
'action_url': route_url('reset_password_process', self.request),
'title': u'Vaihda salasana',
'token': reset.token,
'username': user.username,
}
def send_confirmation_message(self):
"""Sends an email confirmation message to the user."""
username = self.request.POST.get('username', '').strip()
redirect_url = route_url('reset_password', self.request)
log = logging.getLogger('nuorisovaalitadmin')
if not username:
self.request.session.flash(u'Anna käyttäjätunnus.')
else:
user = self.session.query(User).filter(User.username == username).first()
if user is None:
self.request.session.flash(u'Annettua käyttäjätunnusta ei löydy.')
else:
# Create a password reset request that is valid for 24 hours
reset = PasswordReset(user.id, datetime.now() + timedelta(hours=24))
self.session.add(reset)
message = self.create_message(user, reset)
from_address = self.request.registry.settings['nuorisovaalitadmin.from_address'].strip()
# TODO add sendmail to project to include it here
send_mail(from_address, [user.email], message)
self.request.session.flash(u'Ohjeet salasanan vaihtamiseen on lähetetty sähköpostissa.')
redirect_url = self.request.application_url
log.info('Sending password reset instructions to {0}.'.format(user.email))
return HTTPFound(location=redirect_url)
def create_message(self, user, reset):
"""Returns an email.message.Message object representing the password
reset message.
"""
from_address = self.request.registry.settings['nuorisovaalitadmin.from_address'].strip()
date_format = self.request.registry.settings['nuorisovaalitadmin.date_format'].strip()
subject = user.username
message = Message()
message['From'] = Header(from_address, 'utf-8')
message['To'] = Header(u'{0} <{1}>'.format(user.username, user.email), 'utf-8')
message['Subject'] = Header(subject, 'utf-8')
message.set_payload(textwrap.dedent(u'''
Hyvä {username},
Nuorisovaalit 2011 -ylläpitosivustolta on tehty pyyntö
salasanasi uusimiseksi.
Jos teit pyynnön itse, voit uusia salasanasi avaamalla
seuraavan linkin selaimessa:
{reset_url}
Linkki vanhentuu {expiration}.
Mikäli tämä viesti on mielestäsi aiheeton voit poistaa ja
unohtaa sen. Salasanaasi ei ole muutettu.
#.........这里部分代码省略.........