def test_Properties(self): # ``Properties`` object can be used for any kind of mapping. props = Properties() props['foo'] = 'foo' self.assertEqual(props['foo'], 'foo') self.assertEqual(props.get('bar', default='default'), 'default') props.bar = 'bar' self.assertEqual(props.bar, 'bar') self.assertTrue('bar' in props) self.assertEqual(sorted(props.keys()), ['bar', 'foo']) self.assertEqual(o_getattr(props, '_data'), {'foo': 'foo', 'bar': 'bar'}) props_copy = copy.copy(props) self.assertFalse(props_copy is props) self.assertEqual(props_copy.__class__, Properties) self.assertEqual( o_getattr(props_copy, '_data'), o_getattr(props, '_data') ) props_deepcopy = copy.deepcopy(props) self.assertFalse(props_deepcopy is props) self.assertEqual(props_deepcopy.__class__, Properties) self.assertEqual( o_getattr(props_deepcopy, '_data'), o_getattr(props, '_data') )
def test_ActionContext(self): model = BaseNode() request = self.layer.new_request() ac = ActionContext(model, request, 'tile') self.assertTrue(request.environ['action_context'] is ac) self.assertTrue(get_action_context(request) is ac) self.assertEqual(ac.scope, 'tile') request.params['bdajax.action'] = 'ajaxaction' self.assertEqual(ac.scope, 'ajaxaction') request.params['bdajax.action'] = 'layout' self.assertEqual(ac.scope, 'content') request.params['contenttile'] = 'contenttile' self.assertEqual(ac.scope, 'contenttile') class PropNode(BaseNode): properties = None node = PropNode() node.properties = Properties() node.properties.default_child = 'a' node['a'] = PropNode() node['a'].properties = Properties() node['a'].properties.default_content_tile = 'default' request = self.layer.new_request() ac = ActionContext(node, request, 'content') self.assertEqual(ac.scope, 'default')
def js(self): js = Properties() js.public = ['public.js', 'https://remote.foo/public.js'] js.protected = [ 'protected.js', 'https://remote.foo/protected.js' ] return js
def css(self): css = Properties() css.public = ['public.css', 'https://remote.foo/public.css'] css.protected = [ 'protected.css', 'https://remote.foo/protected.css' ] return css
def properties(self): props = Properties() props.in_navtree = True props.action_list = True props.action_add = True props.action_edit = True return props
def properties(self): props = Properties() props.in_navtree = True props.wf_state = True props.wf_name = u'dummy' # XXX: check in repoze.workflow the intended way for naming # transitions props.wf_transition_names = { 'initial_2_final': 'Finalize', } return props
def test_Properties(self): # ``Properties`` object can be used for any kind of mapping. props = Properties() props['foo'] = 'foo' self.assertEqual(props['foo'], 'foo') self.assertEqual(props.get('bar', default='default'), 'default') props.bar = 'bar' self.assertEqual(props.bar, 'bar') self.assertTrue('bar' in props) self.assertEqual(sorted(props.keys()), ['bar', 'foo'])
def make_item(self, info_name, info): model = self.model request = self.request props = Properties() query = make_query(factory=info_name) url = make_url(request, node=model, resource='add', query=query) props.url = url target = make_url(request, node=model, query=query) props.target = target props.title = info.title icon = info.icon if not icon: icon = app_config().default_node_icon props.icon = icon return props
def items(self): ret = list() addables = self.model.nodeinfo.addables if not addables: return ret for addable in addables: info = getNodeInfo(addable) if not info: continue query = make_query(factory=addable) url = make_url(self.request, node=self.model, resource='add', query=query) target = make_url(self.request, node=self.model, query=query) props = Properties() props.url = url props.target = target props.title = info.title props.icon = info.icon ret.append(props) return ret
def properties(self): props = Properties() props.in_navtree = False props.editable = False props.mainmenu_empty_title = True props.default_child = 'users' return props
def test_MergedAssets(self): request = self.layer.new_request() assets = MergedAssets(request) assets.merged_js_assets = Properties() assets.merged_js_assets.public = [(static_resources, 'script1.js')] assets.merged_js_assets.protected = [(static_resources, 'script2.js')] assets.merged_css_assets = Properties() assets.merged_css_assets.public = [(static_resources, 'style1.css')] assets.merged_css_assets.protected = [(static_resources, 'style2.css')] assets.merged_print_css_assets = Properties() assets.merged_print_css_assets.public = [(static_resources, 'print1.css')] assets.merged_print_css_assets.protected = [(static_resources, 'print2.css')] expected = 'console.log("script1");\n\n' self.assertEqual(assets.merged_js, expected) expected = '.style1 { display: block; }\n\n' self.assertEqual(assets.merged_css, expected) expected = '.print1 { display: none; }\n\n' self.assertEqual(assets.merged_print_css, expected) with self.layer.authenticated('max'): res = assets.merged_js expected = 'console.log("script1");\n\nconsole.log("script2");\n\n' self.assertEqual(res, expected) with self.layer.authenticated('max'): res = assets.merged_css expected = '.style1 { display: block; }\n\n.style2 { display: block; }\n\n' self.assertEqual(res, expected) with self.layer.authenticated('max'): res = assets.merged_print_css expected = '.print1 { display: none; }\n\n.print2 { display: none; }\n\n' self.assertEqual(res, expected)
def transitions(self): self.do_transition() ret = list() try: workflow = self.workflow transitions = workflow.get_transitions( self.model, self.request, from_state=self.model.state) except (WorkflowError, AttributeError) as e: logger.error("transitions error: %s" % str(e)) return ret workflow_tsf = self.model.workflow_tsf for transition in transitions: query = make_query(do_transition=transition['name']) target = make_url(self.request, node=self.model, query=query) props = Properties() props.target = target if workflow_tsf: props.title = workflow_tsf(transition['name']) else: props.title = transition['name'] ret.append(props) return ret
def properties(self): props = Properties() props.in_navtree = True props.action_up = True props.action_up_tile = 'content' props.action_add = True props.default_content_tile = 'listing' return props
from pyramid.static import static_view from yafowil.common import ascii_extractor from cone.app.model import Properties static_resources = static_view('static', use_subpath=True) # user and group form field definitions for yafowil # overwrite or extend in integration __init__ # XXX: future -> yafowil form field properties editor # XXX: far future -> yafowil JS form editor # XXX: user and group form schema definitions should then be resolved in order # yafowil browser based cfg -> default cfg -> general default form_field_definitions = Properties() form_field_definitions.user = dict() form_field_definitions.group = dict() _user = form_field_definitions.user _group = form_field_definitions.group _user['default'] = dict() _user['default']['chain'] = 'field:label:error:text' _user['default']['required'] = False _user['default']['protected'] = False _user['id'] = dict() _user['id']['chain'] = 'field:*ascii:*exists:label:error:text' _user['id']['props'] = dict() _user['id']['props']['ascii'] = True
from pyramid.security import ( Everyone, Allow, Deny, ALL_PERMISSIONS, ) from cone.app.model import Properties admin_permissions = ['view', 'add', 'edit', 'delete', 'manage_membership'] UGM_DEFAULT_ACL = [ (Allow, 'role:editor', ['view', 'manage_membership']), (Allow, 'role:admin', admin_permissions), (Allow, 'role:owner', admin_permissions), (Allow, 'role:manager', admin_permissions + ['manage']), (Allow, Everyone, ['login']), (Deny, Everyone, ALL_PERMISSIONS), ] # user and group factory defaults factory_defaults = Properties() factory_defaults.user = dict() factory_defaults.group = dict() factory_defaults.role = dict()
def properties(self): props = Properties() props.editable = True return props
from pyramid.authentication import AuthTktAuthenticationPolicy from pyramid.authorization import ACLAuthorizationPolicy from pyramid.config import Configurator from pyramid.static import static_view from yafowil.resources import YafowilResources as YafowilResourcesBase from zope.component import getGlobalSiteManager import importlib import logging import pyramid_chameleon import pyramid_zcml import sys logger = logging.getLogger('cone.app') # configuration cfg = Properties() # used main template cfg.main_template = 'cone.app.browser:templates/main.pt' # default node icon cfg.default_node_icon = 'glyphicon glyphicon-asterisk' # XXX: move resource registration to browser package # XXX: support developmenet and production mode # JS resources cfg.js = Properties() cfg.js.public = [ '++resource++bdajax/overlay.js', '++resource++bdajax/bdajax.js', '++resource++bdajax/bdajax_bs3.js', 'static/public.js'
from node.ext.ldap import LDAPProps from node.ext.ldap import testLDAPConnectivity from node.ext.ldap.ugm import GroupsConfig from node.ext.ldap.ugm import RolesConfig from node.ext.ldap.ugm import UsersConfig from node.ext.ldap.ugm._api import EXPIRATION_DAYS from node.utils import instance_property from odict import odict from pyramid.i18n import TranslationStringFactory import logging logger = logging.getLogger('cone.ldap') _ = TranslationStringFactory('cone.ldap') # settings config ldap_cfg = Properties() # gets set by main hook ldap_cfg.server_config = '' ldap_cfg.users_config = '' ldap_cfg.groups_config = '' ldap_cfg.roles_config = '' # user and group factory defaults factory_defaults = Properties() factory_defaults.user = dict() factory_defaults.group = dict() factory_defaults.role = dict() class LDAPServerSettings(UGMSettings):
def js(self): js = Properties() js.public = ['public.js', 'https://remote.foo/public.js'] js.protected = ['protected.js', 'https://remote.foo/protected.js'] return js
def css(self): css = Properties() css.public = ['public.css', 'https://remote.foo/public.css'] css.protected = ['protected.css', 'https://remote.foo/protected.css'] return css
def properties(self): props = Properties() return props
from cone.app.model import BaseNode from cone.app.model import Metadata from cone.app.model import Properties from cone.app.model import XMLProperties from cone.ugm.localmanager import LocalManagerConfigAttributes from cone.ugm.utils import general_settings from node.utils import instance_property from pyramid.i18n import TranslationStringFactory import os _ = TranslationStringFactory('cone.ugm') ugm_cfg = Properties() ugm_cfg.ugm_settings = '' ugm_cfg.lm_settings = '' # XXX: move cone.ugm.model.factory_defaults here class UGMSettings(BaseNode): config_file = None def __call__(self): self.attrs() @instance_property def attrs(self): config_file = self.config_file if not os.path.isfile(config_file): msg = 'Configuration file {} not exists.'.format(config_file) raise ValueError(msg)
from pyramid.static import static_view from yafowil.resources import YafowilResources as YafowilResourcesBase from zope.component import adapter from zope.component import getGlobalSiteManager from zope.interface import Interface from zope.interface import implementer import logging import model import os import pyramid_zcml logger = logging.getLogger('cone.app') # configuration cfg = Properties() # authentication provider (expect ``node.ext.ugm.Ugm`` API) cfg.auth = None # used main template cfg.main_template = 'cone.app.browser:templates/main.pt' # default node icon cfg.default_node_icon = 'glyphicon glyphicon-asterisk' # JS resources cfg.js = Properties() cfg.js.public = [ '++resource++bdajax/overlay.js', '++resource++bdajax/bdajax.js',
def properties(self): props = Properties() props.icon = 'glyphicon glyphicon-info-sign' return props
from pyramid.config import Configurator from pyramid.authentication import AuthTktAuthenticationPolicy from pyramid.authorization import ACLAuthorizationPolicy from zope.component import getGlobalSiteManager from cone.app.model import ( AppRoot, AppSettings, Properties, ) from cone.app.browser import forbidden_view # XXX: is this needed anywhere? If not, let's remove it. APP_PATH = os.environ.get('APP_PATH', '') # configuration cfg = Properties() # authentication providers (expect ``node.ext.ugm.Ugm`` like API) cfg.auth = list() # used main template cfg.main_template = 'cone.app.browser:templates/main.pt' # default node icon cfg.default_node_icon = 'static/images/default_node_icon.png' # JS resources cfg.js = Properties() cfg.js.public = [ 'static/cdn/jquery.min.js', 'static/cdn/jquery.tools.min.js',
def properties(self): props = Properties() props.in_navtree = True return props
def properties(self): props = Properties() props.icon = 'glyphicon glyphicon-info-sign' props.mainmenu_display_children = True return props