def delete_contact(self, contact_id): """Deletes a single contact""" contact = DBSession.query(Contact).filter_by(id=contact_id).one() if contact.user_id == get_user_id(): DBSession.query(model.Number).filter_by(contact_id=contact.id).\ delete() DBSession.delete(contact) redirect('/')
def add_contact(self, first_name, last_name, number): contact = Contact() contact.first_name = first_name contact.last_name = last_name user = DBSession.query(User).filter_by(user_id=get_user_id()).one() contact.user = user n = Number() n.number = number n.contact = contact DBSession.add(n) DBSession.add(contact) redirect('/')
def setUp(self): """Setup test fixture for each model test method.""" try: new_attrs = {} new_attrs.update(self.attrs) new_attrs.update(self.do_get_dependencies()) self.obj = self.klass(**new_attrs) DBSession.add(self.obj) DBSession.flush() return self.obj except: DBSession.rollback() raise
def index(self): """Handle the front-page.""" user_id = get_user_id() contacts = DBSession.query(Contact).filter_by(user_id=user_id).all() return dict(page='contacts', contacts=contacts)
def export(self): contacts = DBSession.query(Contact).\ filter_by(user_id=get_user_id()).all() return {'contacts': contacts, 'user_id': get_user_id()}
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 tearDown(self): """Tear down test fixture for each model test method.""" DBSession.rollback()