parent_dn = ','.join(explode_dn(dn)[1:]) except Exception: raise Exception(u"Invalid DN.") rdn = explode_dn(dn)[0] node = LDAPNode(parent_dn, props) if node is None: raise Exception(u"Parent not found. Can't continue.") node[rdn] = LDAPNode() node[rdn].attrs['objectClass'] = ['organizationalUnit'] node() return u"Created '%s'" % rdn registerTile('content', 'cone.ugm:browser/templates/general_settings.pt', class_=ProtectedContentTile, interface=GeneralSettings, permission='login', strict=False) @tile('editform', interface=GeneralSettings, permission="manage") class GeneralSettingsForm(Form): __metaclass__ = plumber __plumbing__ = SettingsPart, YAMLForm action_resource = u'edit' form_template = 'cone.ugm.browser:forms/general_settings.yaml' def save(self, widget, data): model = self.model for attr_name in ['default_membership_assignment_widget']:
from cone.tile import ( tile, registerTile, ) from cone.app.browser.layout import ProtectedContentTile from cone.app.browser.form import ( Form, YAMLForm, ) from cone.app.browser.settings import SettingsPart from cone.mdb.model import Database registerTile('content', 'cone.mdb:browser/templates/database.pt', interface=Database, class_=ProtectedContentTile, permission='login') @tile('editform', interface=Database, permission="manage") class DatabaseSettingsForm(Form): __metaclass__ = plumber __plumbing__ = SettingsPart, YAMLForm action_resource = u'edit' form_template_path = os.path.join(os.path.dirname(__file__), 'forms/database.yaml') def save(self, widget, data): self.model.attrs.path = data.fetch('databaseform.path').extracted
from cone.tile import registerTile from cone.app.browser.layout import ProtectedContentTile from cone.mdb.model import Repositories registerTile('content', 'cone.app:browser/templates/listing.pt', interface=Repositories, class_=ProtectedContentTile, permission='login')
from cone.app.browser.actions import ActionContext from cone.app.browser.exception import format_traceback from cone.app.interfaces import ILiveSearch from cone.tile import registerTile from cone.tile import render_tile from pyramid.exceptions import Forbidden from pyramid.response import Response from pyramid.view import view_config import json import logging import sys import traceback import types registerTile('bdajax', 'bdajax:bdajax_bs3.pt', permission='login') @view_config(name='ajaxaction', accept='application/json', renderer='json') def ajax_tile(model, request): """bdajax ``ajaxaction`` implementation for cone. * Renders tile with name ``bdajax.action``. * Uses definitions from ``request.environ['cone.app.continuation']`` for continuation definitions. """ try: name = request.params['bdajax.action'] ActionContext(model, request, name) rendered = render_tile(model, request, name) continuation = request.environ.get('cone.app.continuation')
from cone.app.browser.form import ( Form, YAMLForm, ) from cone.app.browser.settings import SettingsPart from cone.app.browser.utils import make_url from cone.app.browser.ajax import ( ajax_continue, ajax_message, AjaxAction, ) registerTile('content', 'cone.mdb:browser/templates/solr.pt', interface=Solr, class_=ProtectedContentTile, permission='login') @tile('rebuild', interface=Solr, permission="manage") class Rebuild(Tile): def render(self): conf = self.model.attrs url = 'http://%s:%s/%s/' % (conf.server, conf.port, conf.basepath) PySolr(url).delete(q='*:*') repositories = self.model.root['repositories'] count = 0 for repository in repositories.values(): for media in repository.values():
YAMLForm, ) from cone.app.browser.authoring import ( AddPart, EditPart, ) from cone.mdb.model import ( RepositoryAdapter, add_repository, update_repository, ) registerTile('content', 'cone.app:browser/templates/listing.pt', interface=RepositoryAdapter, class_=ProtectedContentTile, permission='login', strict=False) class RepositoryForm(object): __metaclass__ = plumber __plumbing__ = YAMLForm form_template_path = os.path.join(os.path.dirname(__file__), 'forms/repository.yaml') def id_mode(self, widget, data): return self.action_resource == 'add' and 'edit' or 'display' def valid_id(self, widget, data):
ExtractionError, ) from yafowil.common import ( generic_extractor, generic_required_extractor, select_renderer, select_extractor, ) from yafowil.utils import ( tag, cssid, cssclasses, ) registerTile('referencebrowser', 'cone.app:browser/templates/referencebrowser.pt', permission='view', strict=False) registerTile('referencebrowser_pathbar', 'cone.app:browser/templates/referencebrowser_pathbar.pt', permission='view', class_=PathBar, strict=False) @tile('referencelisting', 'templates/referencelisting.pt', strict=False) class ReferenceListing(ContentsTile): @property def batch(self): batch = ContentsBatch(self.contents) batch.name = 'referencebatch'
from cone.tile import registerTile from cone.app.browser.layout import ProtectedContentTile from c3s.app.model import ( C3SApp, Band, Track, ) from pyramid.view import static static_view = static('static') registerTile('content', 'cone.app:browser/templates/listing.pt', interface=C3SApp, class_=ProtectedContentTile, permission='login', strict=False) registerTile('content', 'cone.app:browser/templates/listing.pt', interface=Band, class_=ProtectedContentTile, permission='login', strict=False) registerTile('content', 'c3s.app:browser/templates/track.pt', interface=Track, class_=ProtectedContentTile,
from pyramid.static import static_view from cone.tile import registerTile static_resources = static_view('static', use_subpath=True) registerTile('logo', 'templates/logo.pt', permission='login') registerTile('footer', 'templates/footer.pt', permission='login')
_('parent_not_found', "Parent not found. Can't continue.")) raise Exception(message) node[rdn] = LDAPNode() node[rdn].attrs['objectClass'] = ['organizationalUnit'] node() self.model.invalidate() message = localizer.translate( _('created_principal_container', default="Created ${rdn}", mapping={'rdn': rdn})) return message registerTile('content', 'cone.ugm:browser/templates/general_settings.pt', class_=ProtectedContentTile, interface=GeneralSettings, permission='manage') @tile('editform', interface=GeneralSettings, permission="manage") class GeneralSettingsForm(Form): __metaclass__ = plumber __plumbing__ = SettingsBehavior, YAMLForm action_resource = u'edit' form_template = 'cone.ugm.browser:forms/general_settings.yaml' @property def message_factory(self): return _
term = term.lower() for node in self.listable_children: if not has_permission('view', node, self.request): continue if term: md = node.metadata if md.get('title', '').lower().find(term) == -1 and \ md.get('creator', 'unknown').lower().find(term) == -1: continue children.append(node) self.request.environ['_filtered_children'] = children return children def sorted_children(self, sort, order): children = self.filtered_children if sort in self.sort_keys: children = sorted(children, key=self.sort_keys[sort]) if order == 'asc': children.reverse() return children registerTile('listing', 'templates/listing.pt', permission='list') @view_config('listing', permission='list') def listing(model, request): """Listing view """ return render_main_template(model, request, 'listing')
child['showchildren'] = curnode tree['children'].append(child) def navtree(self): root = self.navtreeitem(None, None, '') model = self.model.root path = nodepath(self.model) self.fillchildren(model, path, root) return root def rendertree(self, children, level=1): return render_template('cone.app.browser:templates/navtree_recue.pt', model=self.model, request=self.request, context=self, children=children, level=level) @tile('byline', 'templates/byline.pt', strict=False) class Byline(Tile): """Byline tile. """ def format_date(self, dt): return format_date(dt) registerTile('listing', 'cone.app:browser/templates/listing.pt', class_=ProtectedContentTile, permission='login', strict=False)
from cone.tile import Tile from cone.tile import registerTile from cone.tile import render_template from cone.tile import render_tile from cone.tile import tile from node.utils import LocationIterator from odict import odict from pyramid.i18n import TranslationStringFactory from pyramid.security import authenticated_userid from pyramid.security import has_permission _ = TranslationStringFactory("cone.app") registerTile("unauthorized", "templates/unauthorized.pt", permission="login") registerTile("logo", "templates/logo.pt", permission="login") registerTile("livesearch", "templates/livesearch.pt", permission="login") registerTile("footer", "templates/footer.pt", permission="login") class ProtectedContentTile(Tile): """A tile rendering the loginform instead default if user is not authenticated. Normally used for 'content' tiles if page should render login form in place instead of throwing Unauthorized. """ def __call__(self, model, request): if not authenticated_userid(request):
from cone.app.browser.table import Table from cone.tile import Tile from cone.tile import registerTile from cone.tile import tile from pyramid.i18n import TranslationStringFactory from pyramid.i18n import get_localizer from pyramid.view import view_config from yafowil.base import factory import logging logger = logging.getLogger("cone.app") _ = TranslationStringFactory("cone.app") registerTile("sharing", "templates/sharing.pt", permission="manage_permissions") @view_config("sharing", permission="manage_permissions") def sharing(model, request): """Sharing view """ return render_main_template(model, request, "sharing") @tile("local_acl", "templates/table.pt", permission="manage_permissions") class SharingTable(Table): table_id = "localacltable" table_tile_name = "local_acl" default_sort = "principal"
'author': f(data, u'author'), 'description': f(data, u'description'), 'keywords': f(data, u'keywords'), 'relations': f(data, u'relations'), 'effective': f(data, u'effective'), 'expires': f(data, u'expires'), 'alttag': f(data, u'alttag'), 'data': f(data, u'data'), 'visibility': f(data, u'visibility'), } return data registerTile('content', 'templates/revision.pt', interface=RevisionAdapter, class_=ProtectedContentTile, permission='login', strict=False) @tile('addform', interface=RevisionAdapter, permission="add") class RevisionAddForm(RevisionForm, Form): __metaclass__ = plumber __plumbing__ = AddPart def save(self, widget, data): revision = add_revision( self.request, self.model.__parent__, self.revision_data(data)) self.model.__name__ = revision.__name__
from cone.app.utils import principal_data from cone.app.utils import safe_decode from cone.tile import Tile from cone.tile import registerTile from cone.tile import render_template from cone.tile import render_tile from cone.tile import tile from node.utils import LocationIterator from odict import odict from pyramid.i18n import TranslationStringFactory from pyramid.security import authenticated_userid from pyramid.security import has_permission _ = TranslationStringFactory('cone.app') registerTile('unauthorized', 'templates/unauthorized.pt', permission='login') registerTile('logo', 'templates/logo.pt', permission='login') registerTile('livesearch', 'templates/livesearch.pt', permission='login') registerTile('footer', 'templates/footer.pt', permission='login') class ProtectedContentTile(Tile): """A tile rendering the loginform instead default if user is not authenticated. Normally used for 'content' tiles if page should render login form in place instead of throwing Unauthorized. """ def __call__(self, model, request): if not authenticated_userid(request): return render_tile(model, request, 'loginform')
return '<pre>%s</pre>' % ret @view_config(context=Exception, accept='application/json', renderer='json') def ajax_internal_server_error(request): tb = format_traceback() continuation = AjaxContinue([AjaxMessage(tb, 'error', None)]).definitions return { 'mode': 'NONE', 'selector': 'NONE', 'payload': '', 'continuation': continuation, } registerTile('bdajax', 'bdajax:bdajax.pt', permission='login') @view_config(name='ajaxaction', accept='application/json', renderer='json') def ajax_tile(model, request): """bdajax ``ajaxaction`` implementation for cone. * Renders tile with name ``bdajax.action``. * Uses definitions from ``request.environ['cone.app.continuation']`` for continuation definitions. """ try: name = request.params.get('bdajax.action') rendered = render_tile(model, request, name) continuation = request.environ.get('cone.app.continuation')
tile, registerTile, ) from cone.app.browser.form import ( Form, YAMLForm, ) from cone.app.browser.settings import SettingsBehavior from chronotope.model import Settings _ = TranslationStringFactory('chronotope') registerTile('content', 'templates/settings.pt', interface=Settings, permission='manage') @tile('editform', interface=Settings, permission='manage') @plumbing(YAMLForm, SettingsBehavior) class SettingsForm(Form): action_resource = 'edit' form_name = 'chronotopesettingsform' form_template = 'chronotope.browser:forms/settings.yaml' @property def message_factory(self): return _ def save(self, widget, data):
from yafowil.common import select_extractor from yafowil.utils import Tag from yafowil.utils import cssclasses from yafowil.utils import cssid import types _ = TranslationStringFactory('cone.app') # XXX: define i18n translation callback for app tag = Tag(lambda x: x) registerTile('referencebrowser', 'templates/referencebrowser.pt', permission='view') def make_refbrowser_query(request, **kw): params = { 'root': request.params['root'], 'referencable': request.params['referencable'], 'selected': request.params['selected'], } params.update(kw) return make_query(**params) @tile('referencebrowser_pathbar', 'templates/referencebrowser_pathbar.pt', permission='view')
from repoze.bfg.view import bfg_view from cone.tile import ( registerTile, render_tile, ) registerTile('bdajax', 'bdajax:bdajax.pt', permission='login', strict=False) @bfg_view(name='ajaxaction', accept='application/json', renderer='json') def ajax_tile(model, request): """Render an ajax action by name. Request must provide the parameter ``name`` containing the view or tile name. """ # XXX: prefix action name with tile to indicate tile rendering, otherwise # render view name = request.params.get('bdajax.action') rendered = render_tile(model, request, name) return { 'mode': request.params.get('bdajax.mode'), 'selector': request.params.get('bdajax.selector'), 'payload': rendered, } def dummy_livesearch_callback(model, request): """Dummy callback for Livesearch. Set as default.
from cone.app.browser.actions import ActionContext from cone.app.browser.exception import format_traceback from cone.app.interfaces import ILiveSearch from cone.tile import registerTile from cone.tile import render_tile from pyramid.response import Response from pyramid.view import view_config import json import logging import sys import traceback import types registerTile("bdajax", "bdajax:bdajax_bs3.pt", permission="login") @view_config(name="ajaxaction", accept="application/json", renderer="json") def ajax_tile(model, request): """bdajax ``ajaxaction`` implementation for cone. * Renders tile with name ``bdajax.action``. * Uses definitions from ``request.environ['cone.app.continuation']`` for continuation definitions. """ try: name = request.params["bdajax.action"] ActionContext(model, request, name) rendered = render_tile(model, request, name) continuation = request.environ.get("cone.app.continuation")
@property def info(self): factory = self.request.params.get('factory') allowed = self.model.nodeinfo.addables if not factory or not allowed or not factory in allowed: return None return getNodeInfo(factory) @bfg_view('edit', permission='login') def edit(model, request): return render_main_template(model, request, contenttilename='edit') registerTile('edit', 'cone.app:browser/templates/edit.pt', class_=ProtectedContentTile, permission='login', strict=False) @tile('add_dropdown', 'templates/add_dropdown.pt', strict=False) class AddDropdown(Tile): @property 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:
from cone.app.browser.layout import ProtectedContentTile from cone.tile import registerTile from cone.example.model import ExamplePlugin registerTile( name='content', path='cone.example:browser/templates/example.pt', interface=ExamplePlugin, class_=ProtectedContentTile, permission='login')
from cone.tile import ( tile, Tile, registerTile, render_tile, ) from cone.app.browser.layout import ProtectedContentTile registerTile('content', 'cone.ugm:browser/templates/columns.pt', class_=ProtectedContentTile, permission='login', strict=False) class Column(Tile): """Abstract column. """ def _render(self, model, name): return render_tile(model, self.request, name)