brewman/brewman/factories.py
Amritanshu 1448120941 Removed: Pyramid Debug Toolbar dependency removed.
Recipe: Recipe list and Add / Delete recipe created.
Breaking: Major updates to old databases needed as structure has changed significantly
Product table is not a inherited table similar to ledger table
table prefixes for entities removed
renamed a few tables
removed file types not used from the manifest
README.txt now contains the installation procedure on an Ubuntu 14.04 machine
Product.ShowForPurchase column removed
Product.Discountinued renamed to !Product.IsActive
2014-04-29 15:38:44 +05:30

42 lines
1.2 KiB
Python

from pyramid.security import Everyone
from pyramid.security import Authenticated
from pyramid.security import Allow
from brewman.models.auth import Role
class RootFactory(object):
@property
def __acl__(self):
acl = [
(Allow, Everyone, 'view'),
(Allow, Authenticated, 'Authenticated')]
for permission in Role.list():
acl.append((Allow, permission.name, permission.name))
return acl
def __init__(self, request):
pass
def pluralize(word, num=None):
if num is None or num != 1:
if word.endswith('y'):
return word[:-1] + 'ies'
elif word[-1] in 'sx' or word[-2:] in ['sh', 'ch']:
return word + 'es'
elif word.endswith('an'):
return word[:-2] + 'en'
else:
return word + 's'
return word
def add_route(config, name, url, has_list=True, variable='id'):
config.add_route(name + '_' + variable, url + '/{' + variable + '}')
config.add_route(name, url)
if has_list:
config.add_route(name + '_list', pluralize(url))
config.add_route('api_' + name + '_' + variable, '/api' + url + '/{' + variable + '}')
config.add_route('api_' + name, '/api' + url)