Пример #1
0
 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
Пример #2
0
 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'])
Пример #3
0
 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')
Пример #4
0
 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
Пример #5
0
 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()
Пример #6
0
 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()
Пример #7
0
 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)
Пример #8
0
 def tearDown(self):
     """Tear down test fixture for each model test method."""
     DBSession.rollback()
Пример #9
0
 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'])