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):
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'

View File

@ -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)

View File

@ -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:

View File

@ -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,

View File

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