From 4529cd5fcadf2aa4870ca14658dad05cc6ea9d7b Mon Sep 17 00:00:00 2001 From: tanshu Date: Fri, 14 Oct 2016 15:51:06 +0530 Subject: [PATCH] Sort Permissions in Group List --- brewman/models/auth.py | 4 ---- brewman/views/auth/group.py | 7 ++++--- brewman/views/auth/user.py | 4 ++-- brewman/views/services/batch.py | 2 +- requirements.txt | 2 +- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/brewman/models/auth.py b/brewman/models/auth.py index 5e6e1396..dfba95e0 100644 --- a/brewman/models/auth.py +++ b/brewman/models/auth.py @@ -185,10 +185,6 @@ class Group(Base): def by_id(cls, id): return DBSession.query(cls).filter(cls.id == id).one() - @classmethod - def list(cls): - return DBSession.query(cls).order_by(cls.name).all() - class Role(Base): __tablename__ = 'auth_roles' diff --git a/brewman/views/auth/group.py b/brewman/views/auth/group.py index 5b4a7c9a..e76601c8 100644 --- a/brewman/views/auth/group.py +++ b/brewman/views/auth/group.py @@ -6,7 +6,7 @@ from pyramid.view import view_config import transaction from brewman.models import DBSession from brewman.models.auth import Group, Role -from brewman.models.validation_exception import ValidationError, TryCatchFunction +from brewman.models.validation_exception import TryCatchFunction @view_config(route_name='group_list', permission='Users') @view_config(request_method='GET', route_name='group_id', permission='Users') @@ -74,9 +74,10 @@ def show_blank(request): @view_config(request_method='GET', route_name='api_group', renderer='json', request_param='list', permission='Users') def show_list(request): - list = Group.list() + list = DBSession.query(Group).order_by(Group.name).all() + groups = [] - for item in list: + for item in sorted(list, key=lambda permission:permission.name): group = {'Name': item.name, 'Permissions': [], 'Url': request.route_url('group_id', id=item.id)} for permission in item.roles: group['Permissions'].append(permission.name) diff --git a/brewman/views/auth/user.py b/brewman/views/auth/user.py index 5aae7271..8a54afa9 100644 --- a/brewman/views/auth/user.py +++ b/brewman/views/auth/user.py @@ -122,7 +122,7 @@ class UserView(object): def user_info(self, id): if id is None: account = {'Name': '', 'LockedOut': False, 'Groups': []} - for item in Group.list(): + for item in DBSession.query(Group).order_by(Group.name).all(): account['Groups'].append({'GroupID': item.id, 'Name': item.name, 'Enabled': False}) return account @@ -133,7 +133,7 @@ class UserView(object): if self.has_permission: account = {'UserID': user.id, 'Name': user.name, 'Password': '', 'LockedOut': user.locked_out, 'Groups': []} - for item in Group.list(): + for item in DBSession.query(Group).order_by(Group.name).all(): account['Groups'].append( {'GroupID': item.id, 'Name': item.name, 'Enabled': True if item in user.groups else False}) elif self.user.id == user.id: diff --git a/brewman/views/services/batch.py b/brewman/views/services/batch.py index 70158dea..b3342336 100644 --- a/brewman/views/services/batch.py +++ b/brewman/views/services/batch.py @@ -10,7 +10,7 @@ def batch_term(request): count = request.GET.get('count', None) count = None if count is None or count == '' else int(count) date = request.GET.get('date', None) - date = None if count is None or count == '' else datetime.datetime.strptime(date, '%d-%b-%Y') + date = None if date is None or date == '' else datetime.datetime.strptime(date, '%d-%b-%Y') list = [] for index, item in enumerate(Batch.list(filter, include_nil=False, date=date)): text = "{0} ({1}) {2:.2f}@{3:.2f} from {4}".format(item.product.name, item.product.units, diff --git a/requirements.txt b/requirements.txt index 6fce6af9..75404471 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -pyramid<1.6 +pyramid waitress transaction zope.sqlalchemy