Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def callObject(self, request, ob):
orig = ob
if not IHTTPException.providedBy(ob):
ob = component.queryMultiAdapter((ob, request),
name=request.method)
checker = selectChecker(ob)
if checker is not None:
checker.check(ob, '__call__')
ob = getattr(ob, request.method, None)
if ob is None:
raise GrokMethodNotAllowed(orig, request)
return mapply(ob, request.getPositionalArguments(), request)
parent.moveObjectToPosition(obj_id, position)
except ValueError:
pass
elif child.hasAttribute('insert-after'):
insert_after = child.getAttribute('insert-after')
if insert_after == '*':
parent.moveObjectsToBottom(obj_id)
else:
try:
position = parent.getObjectPosition(insert_after)
parent.moveObjectToPosition(obj_id, position + 1)
except ValueError:
pass
obj = getattr(self.context, obj_id)
importer = queryMultiAdapter((obj, self.environ), INode)
if importer:
importer.node = child
def serialize_item(self, proxy):
json_data = {}
json_schema = {}
fti = proxy.fti
overview = queryMultiAdapter(
(proxy, self.controlpanel.request), name="overview"
)
form = overview.form_instance
json_schema = get_jsonschema_for_controlpanel(
self.controlpanel,
self.controlpanel.context,
self.controlpanel.request,
form,
)
for name, item in form.fields.items():
serializer = queryMultiAdapter(
(item.field, fti, self.controlpanel.request), IFieldSerializer
)
if serializer:
value = serializer()
if getCanonical:
canonical = getCanonical()
if context != canonical:
return
# Criteria already changed, we don't want to mess them
if list(criteria.keys()):
return
widgets = context.unrestrictedTraverse('@@default_widgets.xml')
if not widgets:
return
xml = widgets()
environ = SnapshotImportContext(context, 'utf-8')
importer = queryMultiAdapter((context, environ), IBody)
if not importer:
return
importer.body = xml
def importObjects(obj, parent_path, context):
""" Import subobjects recursively.
"""
if not can_import(obj):
logger.info("Skipping import of {}".format(repr(obj)))
return
if api.is_portal(obj):
# explicitly instantiate the importer to avoid adapter clash of
# Products.CMFCore.exportimport.properties.PropertiesXMLAdapter
importer = SenaiteSiteXMLAdapter(obj, context)
else:
importer = queryMultiAdapter((obj, context), IBody)
path = "%s%s" % (parent_path, get_id(obj))
__traceback_info__ = path
if importer:
if importer.name:
path = "%s%s" % (parent_path, importer.name)
filename = "%s%s" % (path, importer.suffix)
body = context.readDataFile(filename)
if body is not None:
importer.filename = filename # for error reporting
importer.body = body
if getattr(obj, "objectValues", False):
for sub in obj.objectValues():
importObjects(sub, path + "/", context)
def __call__(self, *args, **kwargs):
if hasattr(self.request, 'REQUEST_METHOD'):
json_view = queryMultiAdapter((self.context, self.request),
name=u'api')
if self.request['REQUEST_METHOD'] == 'POST':
if getattr(self.request, 'files[]', None) is not None:
files = self.request['files[]']
title = self.request['title[]']
description = self.request['description[]']
rights = self.request['rights[]']
uploaded = self.upload([files], [title], [description], [rights])
if uploaded and json_view:
upped = []
for item in uploaded:
upped.append(json_view.getContextInfo(item))
return json_view.dumps(upped)
return json_view()
return super(Media_Uploader, self).__call__(*args, **kwargs)
def lookup_field_serializer(context, field):
objects = (field, context, context.REQUEST)
# first, try to lookup a serializer named with the full
# dottedname of the field, e.g.:
# "my.package.behaviors.IPreview.preview_image"
name = '.'.join((field.interface.__identifier__, field.__name__))
serializer = queryMultiAdapter(objects, IFieldSerializer, name=name)
if serializer is not None:
return serializer
# then, lookup the default serializer for this type of field.
return getMultiAdapter(objects, IFieldSerializer)
log.warning("Unable traverse to '%s'!" % context_path)
continue
# plone.resource file system resource
if IResourceDirectory.providedBy(context):
try:
content_obj = context[view_name]
except:
log.warning("Unable traverse to '%s'!" % fullview_name)
continue
else:
content_obj = context.restrictedTraverse(view_name, None)
# get object's view content
if ismethod(content_obj) or isfunction(content_obj):
view = queryMultiAdapter((context, self.request), name=view_name)
content_obj = view.context()
content = self._render_obj(content_obj)
if content is None:
continue
filename = fullview_name
if is_page:
filename = filename.rstrip('/')
if self.add_index or IFolder.providedBy(content_obj):
filename = os.path.join(filename, 'index.html')
elif not filename.endswith('.htm') and not filename.endswith('.html'):
filename = filename + '.html'
# where to write view content (based on view path)
path = urlparse(self.context.portal_url())[2]
filename = '/'.join((path, filename))
# write view content on the disk
def get_schema_data(self, data, validate_all):
schema_data = {}
errors = []
for schema in iterSchemata(self.context):
write_permissions = mergedTaggedValueDict(schema, WRITE_PERMISSIONS_KEY)
for name, field in getFields(schema).items():
field_data = schema_data.setdefault(schema, {})
if field.readonly:
continue
if name in data:
dm = queryMultiAdapter((self.context, field), IDataManager)
if not dm.canWrite():
continue
if not self.check_permission(write_permissions.get(name)):
continue
# set the field to missing_value if we receive null
if data[name] is None:
if not field.required:
if dm.get():
self.mark_field_as_changed(schema, name)
dm.set(field.missing_value)
else:
errors.append(
{
"field": field.__name__,
def _create_item(self, pos, **kw):
"""
Create diagram item and place it within parent's boundaries.
"""
parent = self._parent
view = self.view
try:
adapter = component.queryMultiAdapter((parent, self._factory.item_class()), IGroup)
if parent and adapter and adapter.can_contain():
kw['parent'] = parent
item = super(GroupPlacementTool, self)._create_item(pos, **kw)
adapter = component.queryMultiAdapter((parent, item), IGroup)
if parent and item and adapter:
adapter.group()
canvas = view.canvas
parent.request_update(matrix=False)
finally:
self._parent = None
view.dropzone_item = None
view.window.set_cursor(None)
return item