Skip to content

Commit

Permalink
[QCDP24-32] implemented state filter
Browse files Browse the repository at this point in the history
  • Loading branch information
awset committed Sep 10, 2024
1 parent 67816a4 commit 84ca85e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ckanext/datarequests/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,21 @@ class DataRequest(model.core.StatefulObjectMixin, model.DomainObject):
def get(cls, **kw):
'''Finds all the instances required.'''
query = model.Session.query(cls).autoflush(False)
query = query.filter(or_(cls.state == model.core.State.ACTIVE, cls.state == None))
return query.filter_by(**kw).all()

@classmethod
def datarequest_exists(cls, title):
'''Returns true if there is a Data Request with the same title (case insensitive)'''
query = model.Session.query(cls).autoflush(False)
query = query.filter(or_(cls.state == model.core.State.ACTIVE, cls.state == None))
return query.filter(func.lower(cls.title) == func.lower(title)).first() is not None

@classmethod
def get_ordered_by_date(cls, requesting_organisation=None, user_id=None, closed=None, q=None, desc=False, status=None):
'''Personalized query'''
query = model.Session.query(cls).autoflush(False)
query = query.filter(or_(cls.state == model.core.State.ACTIVE, cls.state == None))

params = {}

Expand Down Expand Up @@ -121,7 +124,7 @@ def get_ordered_by_date(cls, requesting_organisation=None, user_id=None, closed=
@classmethod
def get_open_datarequests_number(cls):
'''Returns the number of data requests that are open'''
return model.Session.query(func.count(cls.id)).filter_by(closed=False).scalar()
return model.Session.query(func.count(cls.id)).filter_by(closed=False).filter(or_(cls.state == model.core.State.ACTIVE, cls.state == None)).scalar()


class Comment(model.DomainObject):
Expand Down

0 comments on commit 84ca85e

Please sign in to comment.