diff --git a/ordr2/models/orders.py b/ordr2/models/orders.py index 36d7dea..9003107 100644 --- a/ordr2/models/orders.py +++ b/ordr2/models/orders.py @@ -6,7 +6,7 @@ from collections import namedtuple from datetime import datetime from sqlalchemy import ( Column, - Date, + DateTime, Enum, Float, Integer, @@ -47,9 +47,9 @@ class Consumable(Base): unit_price = Column(Float, nullable=False) currency = Column(Text, nullable=False, default='EUR') comment = Column(Text, nullable=False, default='') - date_created = Column(Date, nullable=False, default=datetime.utcnow) + date_created = Column(DateTime, nullable=False, default=datetime.utcnow) date_modified = Column( - Date, + DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow @@ -83,13 +83,13 @@ class Order(Base): account = Column(Text, nullable=False, default='') comment = Column(Text, nullable=False, default='') - created_date = Column(Date, nullable=False, default=datetime.utcnow) + created_date = Column(DateTime, nullable=False, default=datetime.utcnow) created_by = Column(Text, nullable=False) - approval_date = Column(Date, nullable=True) + approval_date = Column(DateTime, nullable=True) approval_by = Column(Text, nullable=False, default='') - ordered_date = Column(Date, nullable=True) + ordered_date = Column(DateTime, nullable=True) ordered_by = Column(Text, nullable=False, default='') - completed_date = Column(Date, nullable=True) + completed_date = Column(DateTime, nullable=True) completed_by = Column(Text, nullable=False, default='') diff --git a/ordr2/resources/admin.py b/ordr2/resources/admin.py index f93f1ce..1b79ee2 100644 --- a/ordr2/resources/admin.py +++ b/ordr2/resources/admin.py @@ -1,3 +1,5 @@ +from sqlalchemy import or_ + from pyramid.security import Allow, Authenticated, Deny, DENY_ALL, Everyone from .base import BaseResource, PaginationResourceMixin @@ -34,6 +36,7 @@ class UserList(BaseResource, PaginationResourceMixin): def prepare_filtered_query(self, dbsession, filter_params): ''' setup the base filtered query ''' query = dbsession.query(self.sql_model_class) + role_name = filter_params.get('role', None) try: role_name = role_name.lower() @@ -42,6 +45,20 @@ class UserList(BaseResource, PaginationResourceMixin): except (AttributeError, ValueError): role_name = None self.filters['role'] = role_name + + search = filter_params.get('search', None) + if search: + term = '%{}%'.format(search) + query = query.filter( + or_( + self.sql_model_class.user_name.ilike(term), + self.sql_model_class.first_name.ilike(term), + self.sql_model_class.last_name.ilike(term), + self.sql_model_class.email.ilike(term) + ) + ) + self.filters['search'] = search + return query @@ -98,6 +115,7 @@ class ConsumableList(BaseResource, PaginationResourceMixin): def prepare_filtered_query(self, dbsession, filter_params): ''' setup the base filtered query ''' query = dbsession.query(self.sql_model_class) + category_name = filter_params.get('category', None) try: category_name = category_name.lower() @@ -106,6 +124,19 @@ class ConsumableList(BaseResource, PaginationResourceMixin): except (AttributeError, ValueError): category_name = None self.filters['category'] = category_name + + search = filter_params.get('search', None) + if search: + term = '%{}%'.format(search) + query = query.filter( + or_( + self.sql_model_class.cas_description.ilike(term), + self.sql_model_class.vendor.ilike(term), + self.sql_model_class.catalog_nr.ilike(term) + ) + ) + self.filters['search'] = search + return query diff --git a/ordr2/resources/orders.py b/ordr2/resources/orders.py index e3c0af6..a41998d 100644 --- a/ordr2/resources/orders.py +++ b/ordr2/resources/orders.py @@ -1,3 +1,5 @@ +from sqlalchemy import or_ + from pyramid.security import Allow, Authenticated, Deny, DENY_ALL, Everyone from .base import BaseResource, PaginationResourceMixin @@ -54,6 +56,20 @@ class OrderList(BaseResource, PaginationResourceMixin): query = query.filter_by(created_by=user_name) self.filters['user'] = user_name + search = filter_params.get('search', None) + if search: + term = '%{}%'.format(search) + query = query.filter( + or_( + self.sql_model_class.cas_description.ilike(term), + self.sql_model_class.vendor.ilike(term), + self.sql_model_class.catalog_nr.ilike(term), + self.sql_model_class.account.ilike(term), + self.sql_model_class.created_by.ilike(term) + ) + ) + self.filters['search'] = search + return query diff --git a/ordr2/templates/admin/consumable_list.jinja2 b/ordr2/templates/admin/consumable_list.jinja2 index 7fa1102..ffcdd4e 100644 --- a/ordr2/templates/admin/consumable_list.jinja2 +++ b/ordr2/templates/admin/consumable_list.jinja2 @@ -14,11 +14,20 @@ Consumables - {{ macros.filter_box('Category', 'category', categories) }} + {{ macros.filter_box('Category', 'category', categories, {'search':None}) }}