def export_contacts(self): logged = DBSession.query( model.User).filter(model.User.user_name == request.identity['repoze.who.userid']).first() data = { 'user': logged.user_name, 'contacts': [{ 'contact_name': item.display_name, 'contact_number': item.phone_number } for item in logged.address_book] } return data
def save_contact(self, **kw): c = model.Contact() c.display_name = kw['name'] c.phone_number = kw['number'] DBSession.add(c) logged = DBSession.query( model.User).filter(model.User.user_name == request.identity['repoze.who.userid']).first() logged.address_book.append(c) DBSession.add(logged) DBSession.flush() transaction.commit() redirect('/contacts') flash(_('Contact %s added!') % kw['name'])
def contacts(self): if request.identity: logged = DBSession.query(model.User).filter( model.User.user_name == request.identity['repoze.who.userid']).first() items = [{ 'contact_id': item.contact_id, 'name': item.display_name, 'phone': item.phone_number } for item in logged.address_book] """Handle the front-page.""" return dict(form=DeleteContactForm, items=items, username=logged.user_name, contact_lenght=len(items)) else: redirect('/') flash(_("You must be logged in"), 'error')
def by_user_name(cls, username): """Return the user object whose user name is ``username``.""" return DBSession.query(cls).filter_by(user_name=username).first()
def by_email_address(cls, email): """Return the user object whose email address is ``email``.""" return DBSession.query(cls).filter_by(email_address=email).first()
def test_query_obj(self): """Model objects can be queried""" obj = DBSession.query(self.klass).one() for key, value in self.attrs.items(): eq_(getattr(obj, key), value)
def delete_contact(self, **kw): DBSession.query(model.Contact).filter( model.Contact.contact_id == int(kw['contact_id'])).delete() transaction.commit() redirect('/contacts') flash(_("Contact %s deleted successfully!") % kw['contact_name'])