def registration(self, username=None, email=None, password=None): if username is None and email is None and password is None: return dict(page="registration") else: DBSession.add( User(user_name=username, email_address=email, password=password)) redirect("/login")
def contacts_json(self): if request.identity: current_user = User.by_email_address( request.identity['repoze.who.userid']) contacts = DBSession.query(PhoneBook).filter( PhoneBook.id_user == current_user.user_id).order_by( PhoneBook.name).all() return dict(page="contacts", contacts=contacts) else: redirect("/login")
def add_contact(self, id=None, name=None, number=None): if request.identity: if name is None and number is None: return dict(page="add_contact") else: if id is None: current_user = User.by_email_address( request.identity['repoze.who.userid']) DBSession.add( PhoneBook(id_user=current_user.user_id, name=name, number=number)) else: row = DBSession.query(PhoneBook).filter( PhoneBook.id == id).first() row.name = name row.number = number redirect("contacts/") else: redirect("/login")
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 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()
def delete_contact(self, id=None): if request.identity: DBSession.query(PhoneBook).filter(PhoneBook.id == id).delete() redirect("/contacts") else: redirect("/login")
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()