本文整理匯總了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.
#.........這裏部分代碼省略.........