def post(self): if self.form.is_valid(): user = orm_User.validate( self.form.els.login_id.value, self.form.els.password.value ) if user: if user.inactive: session_user.add_message('error', 'That user is inactive.') else: load_session_user(user) log.application('user %s logged in; session id: %s; remote_ip: %s', user.login_id, rg.session.id, rg.request.remote_addr) session_user.add_message('notice', 'You logged in successfully!') if user.reset_required: url = url_for('auth:ChangePassword') else: url = after_login_url() redirect(url) else: log.application('user login failed; user login: %s; session id: %s; remote_ip: %s', self.form.elements.login_id.value, rg.session.id, rg.request.remote_addr) session_user.add_message('error', 'Login failed! Please try again.') elif self.form.is_submitted(): # form was submitted, but invalid self.form.assign_user_errors() self.default()
def delete_record(self): try: CommonCrudBase.delete_record(self) except IntegrityError: session_user.add_message( 'warning', 'could not delete, the {0} is in use'.format(self.objname) ) redirect(url_for(self.endpoint, action='manage', session_key=self.session_key))
def init(self): self.add_text('widget_type', 'Type', required=True) self.add_text('color', 'Color', required=True) self.add_text('quantity', 'Quantity', required=True) sg = self.add_elgroup('submit-group', class_='submit-only') sg.add_submit('submit') cancel_url = link_to('Cancel', url_for('WidgetCrud', action='manage'), title='Go back to the manage page') sg.add_static('cancel', None, cancel_url)
def add_submit(self, crud_view=None): sg = self.add_elgroup('submit-group', class_='submit-only') sg.add_submit('submit') crud_view = crud_view or self.__class__.__name__ + 'Crud' sg.add_static( 'cancel', None, link_to('Cancel', url_for(crud_view, action='manage'), title='Go back to the manage page')) return sg
def extract_data(self, rec): edit_link = link_to('(edit)', url_for( self.endpoint, action='edit', objid=rec.id, session_key=self.grid.session_key, ), class_='edit_link', title='edit record') return literal(edit_link)
def extract_data(self, rec): edit_link = link_to('(edit)', url_for( self.endpoint, action='edit', objid=rec.id, session_key=self.grid.session_key, ), class_='edit_link', title='edit record') delete_link = link_to('(delete)', url_for( self.endpoint, action='delete', objid=rec.id, session_key=self.grid.session_key, ), class_='delete_link', title='delete record') links = [delete_link, edit_link] return literal(''.join(links))
def post(self): if self.form.is_valid(): orm_User.get(session_user.id).update_password(self.form.elements.password.value) session_user.reset_required = False session_user.add_message('notice', 'Your password has been changed successfully.') url = after_login_url() if rg.request.url == url_for('auth:ChangePassword') \ else rg.request.url redirect(url) elif self.form.is_submitted(): # form was submitted, but invalid self.form.assign_user_errors() self.default()
def extract_data(self, rec): edit_link = '' if self.has_edit: edit_link = link_to('(edit)', url_for(self.grid.endpoint, action='edit', objid=rec.id, session_key=self.grid.session_key), class_='edit_link', title='edit record') delete_link = '' if self.has_delete: delete_link = link_to('(delete)', url_for( self.grid.endpoint, action='delete', objid=rec.id, session_key=self.grid.session_key), class_='delete_link', title='delete record') return literal('{0}{1}'.format( delete_link, edit_link, ))
def create_url(self, record): return url_for( 'auth:PermissionMap', objid=record.id, )
def form_when_completed(self): redirect(url_for( self.endpoint, action='manage', session_key=self.session_key ))
def default(self): rg.session.invalidate() url = url_for('auth:Login') redirect(url)
def abort(self, msg='invalid reset request'): session_user.add_message('error', '%s, use the form below to resend reset link' % msg) url = url_for('auth:LostPassword') redirect(url)
def test_routes(self): self.assertEqual('https://localhost:8080/scRipt/url1', url_for('mod:Url1', True)) self.assertEqual('https://localhost:8080/scRipt/url1', url_for('mod:Url1', _https=True)) self.assertEqual('http://localhost:8080/scRipt/url1', url_for('mod:Url1', _https=False))
def test_routes(self): self.assertEqual('/url1', url_for('mod:Url1')) self.assertEqual('/url1?foo=bar', url_for('mod:Url1', foo='bar')) self.assertEqual('http://localhost/url1', url_for('mod:Url1', True)) self.assertEqual('https://localhost/url1', url_for('mod:Url1', _https=True)) self.assertEqual('http://localhost/url1', url_for('mod:Url1', _https=False))