示例#1
0
文件: items.py 项目: exhuma/tinvent
    def index(self, categories=None, status=None ):
        identity = request.environ.get( 'repoze.who.identity' )
        user = identity['user']

        me_contact = Contact.find_by_user( user )

        if not me_contact:
           raise ValueError( "Unable to retrieve user-to-contact mapping. For some reason the contact mapping the current user to a contact_id has vanished." )

        return dict( page='index', user=user,
              me_contact = me_contact,
              categories=DBSession.query(Category) )
示例#2
0
    def view(self, contact_id):
        identity = request.environ.get( 'repoze.who.identity' )
        user = identity['user']
        me_contact = Contact.find_by_user(user)

        contact_query = DBSession.query( Contact )
        contact_query = contact_query.filter_by( user_id=user.user_id )
        contact_query = contact_query.filter_by( contact_id=contact_id )
        contact = contact_query.first()

        your_items_query = DBSession.query( Item )
        your_items_query = your_items_query.filter_by( holder_id=contact.contact_id )
        your_items_query = your_items_query.filter_by( owner_id=me_contact.contact_id )

        his_items_query = DBSession.query( Item )
        his_items_query = his_items_query.filter_by( holder_id=me_contact.contact_id )
        his_items_query = his_items_query.filter_by( owner_id=contact.contact_id )

        return dict( page='index', user=user, contact=contact,
              his_items_query=his_items_query,
              your_items_query=your_items_query )
示例#3
0
文件: items.py 项目: exhuma/tinvent
    def view(self, item_id):
        identity = request.environ.get( 'repoze.who.identity' )
        user = identity['user']
        me_contact = Contact.find_by_user( user )
        item = DBSession.query(Item)\
              .filter_by( item_id=item_id )\
              .first()
        if not item:
           raise ValueError( "Item not found!" )
        if item.holder_id != me_contact.contact_id and item.owner_id != me_contact.contact_id:
           raise ValueError( "You neither own nor hold this item! Access Denied!" )

        return dict( item=item )
示例#4
0
 def setup(self):
     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
文件: all.py 项目: exhuma/tinvent
 def find_by_user(self, user):
    the_contact = DBSession.query( self )\
            .filter_by( user_id=user.user_id )\
            .filter_by( other_user_id=user.user_id)\
            .first()
    return the_contact
示例#6
0
 def test_query_obj(self):
     obj = DBSession.query(self.klass).one()
     for key, value in self.attrs.iteritems():
         assert_equals(getattr(obj, key), value)
示例#7
0
 def tearDown(self):
     DBSession.rollback()
示例#8
0
文件: auth.py 项目: exhuma/tinvent
 def by_user_name(cls, username):
     """Return the user object whose user name is ``username``."""
     return DBSession.query(cls).filter(cls.user_name==username).first()
示例#9
0
文件: auth.py 项目: exhuma/tinvent
 def by_email_address(cls, email):
     """Return the user object whose email address is ``email``."""
     return DBSession.query(cls).filter(cls.email_address==email).first()