Sort Permissions in Group List

This commit is contained in:
tanshu 2016-10-14 15:51:06 +05:30
parent b90f1294b0
commit 4529cd5fca
5 changed files with 8 additions and 11 deletions

View File

@ -185,10 +185,6 @@ class Group(Base):
def by_id(cls, id): def by_id(cls, id):
return DBSession.query(cls).filter(cls.id == id).one() 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): class Role(Base):
__tablename__ = 'auth_roles' __tablename__ = 'auth_roles'

View File

@ -6,7 +6,7 @@ from pyramid.view import view_config
import transaction import transaction
from brewman.models import DBSession from brewman.models import DBSession
from brewman.models.auth import Group, Role 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(route_name='group_list', permission='Users')
@view_config(request_method='GET', route_name='group_id', 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') @view_config(request_method='GET', route_name='api_group', renderer='json', request_param='list', permission='Users')
def show_list(request): def show_list(request):
list = Group.list() list = DBSession.query(Group).order_by(Group.name).all()
groups = [] 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)} group = {'Name': item.name, 'Permissions': [], 'Url': request.route_url('group_id', id=item.id)}
for permission in item.roles: for permission in item.roles:
group['Permissions'].append(permission.name) group['Permissions'].append(permission.name)

View File

@ -122,7 +122,7 @@ class UserView(object):
def user_info(self, id): def user_info(self, id):
if id is None: if id is None:
account = {'Name': '', 'LockedOut': False, 'Groups': []} 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}) account['Groups'].append({'GroupID': item.id, 'Name': item.name, 'Enabled': False})
return account return account
@ -133,7 +133,7 @@ class UserView(object):
if self.has_permission: if self.has_permission:
account = {'UserID': user.id, 'Name': user.name, 'Password': '', 'LockedOut': user.locked_out, 'Groups': []} 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( account['Groups'].append(
{'GroupID': item.id, 'Name': item.name, 'Enabled': True if item in user.groups else False}) {'GroupID': item.id, 'Name': item.name, 'Enabled': True if item in user.groups else False})
elif self.user.id == user.id: elif self.user.id == user.id:

View File

@ -10,7 +10,7 @@ def batch_term(request):
count = request.GET.get('count', None) count = request.GET.get('count', None)
count = None if count is None or count == '' else int(count) count = None if count is None or count == '' else int(count)
date = request.GET.get('date', None) 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 = [] list = []
for index, item in enumerate(Batch.list(filter, include_nil=False, date=date)): 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, text = "{0} ({1}) {2:.2f}@{3:.2f} from {4}".format(item.product.name, item.product.units,

View File

@ -1,4 +1,4 @@
pyramid<1.6 pyramid
waitress waitress
transaction transaction
zope.sqlalchemy zope.sqlalchemy