def __init__(self, transfer, raise_exceptions=True): # remember the transfer self.transfer = transfer self.raise_exceptions = raise_exceptions # look if we have a harvesting type adapter # try: # self.harvesting_type = \ # self.transfer.harvesting_type(self.transfer) # except TypeError: # self.harvesting_type = None # fetch the preprocessor adapter # self.data_cleaner = self.transfer.data_cleaner(self.transfer) self.cleaned_data = None # self.field_config = get_field_config(self.transfer) self.harvesting_context = self.transfer if self.transfer: if getattr(self.transfer, 'base_object', None): self.harvesting_context = content.get( UID=self.transfer.base_object, ) # determine the source format serializer string for rdflib from our # own interface. Todo this is a bit ugly if self.transfer.source_type: self.rdf_format_key = \ IFaceToRDFFormatKey[self.transfer.source_type] self.rdf_format = RDF_FORMAT_METADATA[self.rdf_format_key] self.serialize_format = self.rdf_format['serialize_as'] self.mime_type = self.rdf_format['mime_type'] self.tripel_tempdb = None # Temporary tripel store self.tripeldb = None # Tripestore for dcapt-ap.de data self._target_graph = None # Target graph instance
def paste_error_func(task): item_url = "" context = content_api.get(UID=task['context']) if context: item_url = context.absolute_url() msg = ("<span>There was an error when pasting item in " "<a href='{url}'>{url}</a></span>").format(url=item_url) return msg
def edit_description_func(task): item_url = "" context = content_api.get(UID=task['context']) if context: item_url = context.absolute_url() msg = ("<span>Saving changes to <a href='{url}'>{url}</a></span>").format( url=item_url) return msg
def edit_error_func(task): item_url = "" context = content_api.get(UID=task['context']) if context: item_url = context.absolute_url() msg = ("<span>An error occurred when trying to save changes to " "<a href='{url}'>{url}</a></span>").format(url=item_url) return msg
def __call__(self, context): values = find(object_provides=IQCSample.__identifier__) qcsample_ids = [v.UID for v in values] items = [] for uid in qcsample_ids: a = get(UID=uid) items.append(SimpleVocabulary.createTerm(a.veracis_id)) return SimpleVocabulary(items)
def paste_description_func(task): item_url = "" context = content_api.get(UID=task['context']) if context: item_url = context.absolute_url() msg = ("<span>Pasting item in <a href='{url}'>{url}</a></span>").format( url=item_url) return msg
def paste_success_func(task): item_url = "" context = content_api.get(UID=task['context']) if context: item_url = context.absolute_url() msg = ("<p>Content was pasted at <a href='{url}'>{url}</a></p>").format( url=item_url) return msg
def edit_success_func(task): item_url = "" context = content_api.get(UID=task['context']) if context: item_url = context.absolute_url() msg = ( "<p>Changes to <a href='{url}'>{url}</a> have been saved.</p>").format( url=item_url) return msg
def delete_description_func(task): id = task.get("id", "") folder_url = "" context = content_api.get(UID=task['context']) if context: folder_url = context.absolute_url() msg = ("<span>Deleting item with id '<strong>{id}</strong>' " "from <a href='{url}'>{url}</a></span>").format(id=id, url=folder_url) return msg
def add_success_func(task): obj_uid = task.get("obj_uid") obj_url = "" if obj_uid: obj = content_api.get(UID=obj_uid) obj_url = obj.absolute_url() msg = ("<p>Your new content has been created, you can visit it " "from here: <a href='{url}'>{url}</a></p>").format(url=obj_url) return msg
def add_error_func(task): context = content_api.get(UID=task['context']) obj_data = task.get("obj_data") folder_url = "" if context: folder_url = context.absolute_url() msg = ("<span>An error occurred when trying to add '" "<strong>{title}</strong>' to <a href='{url}'>{url}</a></span>" ).format(title=obj_data.get('title', ""), url=folder_url) return msg
def add_description_func(task): context = content_api.get(UID=task['context']) obj_data = task.get("obj_data") folder_url = "" if context: folder_url = context.absolute_url() msg = ("<span>Adding '<strong>{title}</strong>' to " "<a href='{url}'>{url}</a></span>").format(title=obj_data.get( 'title', ""), url=folder_url) return msg
def delete_error_func(task): id = task.get("id", "") folder_url = "" context = content_api.get(UID=task['context']) if context: folder_url = context.absolute_url() msg = ( "<span>An error occurred when trying to delete item with id '" "<strong>{id}</strong>' from <a href='{url}'>{url}</a></span>").format( id=id, url=folder_url) return msg
def delete_success_func(task): id = task.get("id", "") title = task.get("title", "") folder_url = "" context = content_api.get(UID=task['context']) if context: folder_url = context.absolute_url() msg = ("<span>Item with id '<strong>{id}</strong>' and title " "'<strong>{title}</strong>' has been deleted from " "<a href='{url}'>{url}</a></span>").format(id=id, title=title, url=folder_url) return msg
def rename_description_func(task): item_url = "" context = content_api.get(UID=task['context']) if context: item_url = context.absolute_url() msg = ("<span>Renaming item <a href='{url}'>{url}</a>.").format( url=item_url) old_title = task.get("old_title") new_title = task.get("new_title") if old_title != new_title: msg += " New title: <strong>%s</strong>." % new_title old_id = task.get("old_id") new_id = task.get("new_id") if old_id != new_id: msg += " New ID: <strong>%s</strong>." % new_id msg += "</span>" return msg
def rename_error_func(task): item_url = "" context = content_api.get(UID=task['context']) if context: item_url = context.absolute_url() msg = ("<span>An error occurred when trying to rename item " "<a href='{url}'>{url}</a>.").format(url=item_url) old_title = task.get("old_title") new_title = task.get("new_title") if old_title != new_title: msg += " The new title was: <strong>%s</strong>." % new_title old_id = task.get("old_id") new_id = task.get("new_id") if old_id != new_id: msg += " The new ID was: <strong>%s</strong>." % new_id msg += "</span>" return msg
def rename_success_func(task): context = content_api.get(UID=task['context']) item_url = "" if context: item_url = context.absolute_url() msg = ("<p>Item <a href='{url}'>{url}</a> has been successfully " "renamed.</p>").format(url=item_url) old_title = task.get("old_title") new_title = task.get("new_title") if old_title != new_title: msg += ("<p>Old title: <strong>{old_title}</strong>. " "New title: <strong>{new_title}</strong>.</p>").format( old_title=old_title, new_title=new_title) old_id = task.get("old_id") new_id = task.get("new_id") if old_id != new_id: msg += ("<p>Old ID: <strong>{old_id}</strong>. " "New ID: <strong>{new_id}</strong>.</p>").format(old_id=old_id, new_id=new_id) return msg
def marshall_references(self, context): """Marshall the referenced objects.""" for ref_name in self.structure.referenced: if self.structure.referenced[ref_name]['type'] != list: uid = getattr(context, ref_name, None) if not uid: continue uid_list = [uid] else: uid_list = getattr(context, ref_name, None) if not uid_list: continue resources = [] for uid in uid_list: ref = content.get(UID=uid) if not ref: continue referenced_marshaller = queryMultiAdapter( (ref, self.marshall_target), interface=IMarshallSource, default=DX2Any(ref, self.marshall_target), ) if referenced_marshaller: # referenced object should be a literal instead of a object literals = referenced_marshaller.marshall_as_literal() if literals is not None: self.marshall_target.add_property( self.resource, ref_name, literals, ) else: referenced_marshaller.marshall() resources.append(referenced_marshaller.resource) if resources: self.marshall_target.set_links( self.resource, ref_name, resources, )
def should_reload(self, task): result = False current_location = self.request.get("current_location", None) if current_location: try: current_location = json.loads(current_location) except Exception: current_location = dict() url = "" if current_location: if "origin" in current_location and "pathname" in current_location: url = current_location["origin"] + current_location["pathname"] elif "href" in current_location: url = current_location["href"] else: url = "" if url: # First some conditions when view should never be reloaded if "++add++" not in url and not url.endswith("edit"): if url.endswith("@@task-details"): qs = current_location["search"] if "task_id" in qs and task.get("task_id") in qs: result = True elif "task_id" not in qs: result = True else: action = task.get("action", None) context = task.get("context", None) if context: context = content_api.get(UID=context) if not context: context = self.context if (action == constants.ADD and context.absolute_url() == url): result = True elif action == constants.RENAME: if (context.absolute_url() == url or context.aq_parent.absolute_url() == url): # We are currently at the folder holding the # renamed object. result = True else: old_id = task.get("old_id", "") old_url = "%s/%s" % ( context.aq_parent.absolute_url(), old_id) if url == old_url: # We are currently at the old object # that was renamed. result = True elif (action == constants.DELETE and context.absolute_url() == url): result = True elif (action == constants.PASTE and context.absolute_url() == url): result = True elif action == constants.EDIT: if context.absolute_url() == url: result = True elif context.aq_parent.absolute_url() == url: # Only redirect if the edit was done for the title for iface, fields in task.get("changes"): if (iface == "plone.app.dexterity.behaviors.metadata.IBasic" and "IDublinCore.title" in fields): result = True return result
def test_image(self): try: result = content.get(UID=self._test_image) except Exception as e: return None return result