Exemple #1
0
 def complete(cls, prefix, limit=5, instance_filter=True):
     q = meta.Session.query(User)
     prefix = prefix.lower()
     q = q.filter(or_(func.lower(User.user_name).like(prefix + u"%"),
                      func.lower(User.display_name).like(prefix + u"%")))
     q = q.limit(limit)
     completions = q.all()
     if ifilter.has_instance() and instance_filter:
         inst = ifilter.get_instance()
         completions = filter(lambda u: u.is_member(inst), completions)
     return completions
Exemple #2
0
 def by_id(cls, id, instance_filter=True):
     try:
         q = meta.Session.query(cls)
         q = q.filter(cls.id == id)
         if ifilter.has_instance() and instance_filter:
             q = q.filter((cls.instance_id ==
                           ifilter.get_instance().id))
         return q.limit(1).first()
     except Exception, e:
         log.warn("by_id(%s): %s" % (id, e))
         return None
Exemple #3
0
 def complete(cls, prefix, limit=5, instance_filter=True):
     q = meta.Session.query(User)
     prefix = prefix.lower()
     q = q.filter(or_(func.lower(User.user_name).like(prefix + u"%"),
                      func.lower(User.display_name).like(prefix + u"%")))
     q = q.limit(limit)
     completions = q.all()
     if ifilter.has_instance() and instance_filter:
         inst = ifilter.get_instance()
         completions = filter(lambda u: u.is_member(inst), completions)
     return completions
Exemple #4
0
 def find(cls, title_or_id, instance_filter=True, include_deleted=False):
     """
     Note: include_deleted doesn't have any effect, as badges can not be
     marked as deleted. This parameter is only there for coherence reasons
     with other models' find methods, as this is expected in
     `model.refs.to_entity`.
     """
     q = meta.Session.query(cls)
     try:
         q = q.filter(cls.id == int(title_or_id))
     except ValueError:
         q = q.filter(cls.title == title_or_id)
     if ifilter.has_instance() and instance_filter:
         q = q.filter(cls.instance_id == ifilter.get_instance().id)
     return q.first()
Exemple #5
0
 def find_all(cls, unames, instance_filter=True, include_deleted=False):
     from membership import Membership
     q = meta.Session.query(User)
     q = q.filter(User.user_name.in_(unames))
     if not include_deleted:
         q = q.filter(or_(User.delete_time == None,  # noqa
                          User.delete_time > datetime.utcnow()))
     if ifilter.has_instance() and instance_filter:
         q = q.join(Membership)
         q = q.filter(or_(Membership.expire_time == None,  # noqa
                          Membership.expire_time > datetime.utcnow()))
         q = q.filter(Membership.instance == ifilter.get_instance())
     # log.debug("QueryAll: %s" % q)
     # log.debug("LEN: %s" % len(q.all()))
     return q.all()
Exemple #6
0
 def find_all(cls, unames, instance_filter=True, include_deleted=False):
     from membership import Membership
     q = meta.Session.query(User)
     q = q.filter(User.user_name.in_(unames))
     if not include_deleted:
         q = q.filter(or_(User.delete_time == None,
                          User.delete_time > datetime.utcnow()))
     if ifilter.has_instance() and instance_filter:
         q = q.join(Membership)
         q = q.filter(or_(Membership.expire_time == None,
                          Membership.expire_time > datetime.utcnow()))
         q = q.filter(Membership.instance == ifilter.get_instance())
     #log.debug("QueryAll: %s" % q)
     #log.debug("LEN: %s" % len(q.all()))
     return q.all()
Exemple #7
0
 def find(cls, user_name, instance_filter=True, include_deleted=False):
     from membership import Membership
     try:
         q = meta.Session.query(User)
         try:
             q = q.filter(User.id == int(user_name))
         except ValueError:
             q = q.filter(User.user_name == unicode(user_name))
         if not include_deleted:
             q = q.filter(or_(User.delete_time == None,  # noqa
                              User.delete_time > datetime.utcnow()))
         if ifilter.has_instance() and instance_filter:
             q = q.join(Membership)
             q = q.filter(or_(Membership.expire_time == None,  # noqa
                              Membership.expire_time > datetime.utcnow()))
             q = q.filter(Membership.instance == ifilter.get_instance())
         return q.limit(1).first()
     except Exception, e:
         log.debug("find(%s): %s" % (user_name, e))
         return None
Exemple #8
0
 def find(cls, user_name, instance_filter=True, include_deleted=False):
     from membership import Membership
     try:
         q = meta.Session.query(User)
         try:
             q = q.filter(User.id == int(user_name))
         except ValueError:
             q = q.filter(User.user_name == unicode(user_name))
         if not include_deleted:
             q = q.filter(or_(User.delete_time == None,
                              User.delete_time > datetime.utcnow()))
         if ifilter.has_instance() and instance_filter:
             q = q.join(Membership)
             q = q.filter(or_(Membership.expire_time == None,
                              Membership.expire_time > datetime.utcnow()))
             q = q.filter(Membership.instance == ifilter.get_instance())
         return q.limit(1).first()
     except Exception, e:
         log.warn("find(%s): %s" % (user_name, e))
         return None
Exemple #9
0
 def current_delegated(self, instance_filter=True):
     ds = filter(lambda d: not d.is_revoked(), self.delegated)
     if ifilter.has_instance() and instance_filter:
         ds = filter(lambda d: d.scope.instance == ifilter.get_instance(),
                     ds)
     return ds
Exemple #10
0
 def current_delegated(self, instance_filter=True):
     ds = filter(lambda d: not d.is_revoked(), self.delegated)
     if ifilter.has_instance() and instance_filter:
         ds = filter(lambda d: d.scope.instance == ifilter.get_instance(),
                     ds)
     return ds