def youtube_id(self): """Token for the URL to play the video.""" if not hasattr(self, "_youtube_id"): doc = Doc(self.SESSION, id=self.id) node = doc.root.find("PhysicalMedia/VideoData/HostingID") self._youtube_id = Doc.get_text(node, "").strip() or None return self._youtube_id
def parameters(self): if not hasattr(self, "_parameters"): self._parameters = dict() for node in self.__node.findall("SubsetFilterParm"): name = Doc.get_text(node.find("ParmName")) value = Doc.get_text(node.find("ParmValue"), "") self._parameters[name] = value return self._parameters
def filter(self, doc, filter_spec, **opts): prefix, name = filter_spec.split(":", 1) if prefix == "name": doc_id = Doc.id_from_title(name) self.register_filter(Doc(self.session, id=doc_id)) else: self.register_filter_set(name) return doc.filter(filter_spec, **opts)
def markup_for_name(name): """Highlight insertion/deletion markup for the term name. Pass: name - parsed XML node for the term name string """ doc = Doc(Concept.GUEST, xml=etree.tostring(name)) result = doc.filter(Concept.FILTER) return html.fromstring(str(result.result_tree).strip())
def row(self): """HTML markup for this comment.""" if not hasattr(self, "_row"): wrapper = etree.Element("GlossaryTermDef") wrapper.append(self.__node) doc = Doc(Concept.GUEST, xml=etree.tostring(wrapper)) result = doc.filter(Concept.FILTER) self._row = html.fromstring(str(result.result_tree)) return self._row
def transform(self): """XSL/T filter used for this load.""" if not hasattr(self, "_transform"): title = f"Index {self.type.capitalize()} Dictionary" doc_id = Doc.id_from_title(title, self.cursor) doc = Doc(Session("guest", tier=self.tier), id=doc_id) self._transform = etree.XSLT(doc.root) self.logger.info("Loaded %r filter", title) return self._transform
def doc(self): """CDR `Doc` object for the Media document.""" if not hasattr(self, "_doc"): self._doc_en = Doc(self.control.session, id=self.control.idpair[0]) self._doc_es = Doc(self.control.session, id=self.control.idpair[1]) #self._doc = Doc(self.control.session, id=self.control.id) if self._doc_en.doctype.name != "Media": self.control.bail("Not a Media document") self._doc = [ self._doc_en, self._doc_es ] return self._doc
def docs(self): """ List of documents requested or published for this job For a job which is being created, this will be populated from the `docs` argument passed into the constructor. For a job which is already in the database and which has been published, the list will be pulled from the `pub_proc_doc` table. For a job which is in the database, queued but not yet run, the list will have the documents explicitly requested at job creation time, but will not yet have the documents which will be picked up by the control document's query logic for this job type. It might seem redundant to create new Doc objects for an unsaved job's documents, but in most cases the Doc objects passed to the constructor will only have document IDs, and no version information. We can't really get the date/time cutoff used to pick the right version without creating a new object. """ if not hasattr(self, "_docs"): docs = [] if self.id: query = Query("pub_proc_doc", "doc_id", "doc_version") query.where(query.Condition("pub_proc", self.id)) for doc_id, version in query.execute(self.cursor).fetchall(): docs.append(Doc(self.session, id=doc_id, version=version)) else: cutoff = self.parms.get("MaxDocUpdatedDate") if not cutoff or cutoff == "JobStartDateTime": cutoff = self.started opts = dict(before=cutoff) for requested in self.__opts.get("docs", []): opts["id"] = requested.id if self.force: opts["version"] = "last" elif requested.version: if not (self.permissive or requested.publishable): args = requested.cdr_id, requested.version message = "{}V{} is not publishable".format(*args) raise Exception(message) opts["version"] = requested.version else: opts["version"] = "lastp" try: doc = Doc(self.session, **opts) if not self.force and doc.active_status != "A": raise Exception("{} is blocked".format(doc.id)) docs.append(doc) except Exception as e: raise Exception("{}: {}".format(requested.cdr_id, e)) self._docs = docs return self._docs
def id(self): """CDR ID for the image document.""" if not hasattr(self, "_id"): node = self.node.find("MediaID") try: self._id = Doc.extract_id(node.get(f"{{{Doc.NS}}}ref")) except: self._id = None if not hasattr(self, "_text"): self._text = Doc.get_text(node, "").strip() return self._id
def text(self): """Text to be displayed above the image.""" if not hasattr(self, "_text"): node = self.node.find("MediaID") self._text = Doc.get_text(node, "").strip() if not hasattr(self, "_id"): try: self._id = Doc.extract_id(node.get(self.CDR_REF)) except: self._id = None return self._text
def aliases(self): """Sequence of other names for this drug term.""" if not hasattr(self, "_aliases"): self._aliases = [] for node in self.doc.findall("OtherName"): self._aliases.append([ self.id, Doc.get_text(node.find("OtherTermName", "")).strip(), Doc.get_text(node.find("OtherNameType", "")).strip(), self.LANGUAGE, ]) return self._aliases
def text(self): """String describing the video, displayed at the top.""" if not hasattr(self, "_text"): self._text = None node = self.node.find("SpecificMediaTitle") if node is not None: self._text = Doc.get_text(node, "").strip() if not self._text: node = self.node.find("VideoID") if node is not None: self._text = Doc.get_text(node, "").strip() return self._text
def register_filter(self, filter_doc): if not filter_doc.title in Tests.COVERED: Tests.COVERED.add(filter_doc.title) xml = filter_doc.get_filter(filter_doc.id).xml root = etree.fromstring(xml) for name in ("import", "include"): qname = Doc.qname(name, Filter.NS) for node in root.iter(qname): href = node.get("href").replace("%20", " ") if href.startswith("cdr:name:"): title = href.split(":name:", 1)[1] doc_id = Doc.id_from_title(title) self.register_filter(Doc(self.session, id=doc_id))
def __init__(self, control, node): self.control = control self.date = self.type = None self.comments = [] for child in node: if child.tag == "TypeOfDISChangeValue": self.type = Doc.get_text(child) elif child.tag == "Date": self.date = Doc.get_text(child) elif child.tag == "Comment": if control.comments: comment = Doc.get_text(child) if comment: self.comments.append(comment)
def terms(self): """Dictionary of terms surrounding the user's pick in the tree.""" if not hasattr(self, "_terms"): doc = Doc(self.control.session, id=self.id) tree = doc.get_tree(depth=1) self._terms = {} for id, name in tree.names.items(): focus = id == self.id self._terms[id] = Term(self, id, name, focus) for r in tree.relationships: self._terms[r.parent].add_child(self._terms[r.child]) self._terms[r.child].add_parent(self._terms[r.parent]) return self._terms
def options(self): """ Dictionary of fixed settings for this job type """ if not hasattr(self, "_options"): self._options = dict(AbortOnError="Yes", PublishIfWarnings="No") path = "SubsetOptions/SubsetOption" for child in self.__node.findall(path): name = Doc.get_text(child.find("OptionName")) value = Doc.get_text(child.find("OptionValue")) self._options[name] = value return self._options
def media_link_ids(self): """MediaLink IDs for the images of a summary. Extracting the MediaID (ref) attribute and converting the ID to an integer """ if not hasattr(self, "_media_link_ids"): self._media_link_ids = Doc.get_text(self.doc.root.find("MediaID")) media_doc_ids = self.doc.root.findall(".//MediaLink/MediaID") self._media_link_ids = [] for media_doc in media_doc_ids: self._media_link_ids.append( Doc.extract_id(media_doc.values()[0])) return self._media_link_ids
def nodes(self): """Sequence of HTML elements to be added to the report. We use XSL/T filtering to generate the HTML fragments for the report for this summary, which we then parse so they can be added to the page object. """ if not hasattr(self, "_nodes"): opts = dict(id=self.id, version=self.version) doc = Doc(self.control.session, **opts) result = doc.filter(*self.FILTERS, parms=self.parms) html = str(result.result_tree).strip() self._nodes = self.H.fragments_fromstring(html) return self._nodes
def parms(self): """ Dictionary of user-controllable settings with defaults """ if not hasattr(self, "_parms"): self._parms = {} path = "SubsetParameters/SubsetParameter" for child in self.__node.findall(path): name = Doc.get_text(child.find("ParmName")) value = Doc.get_text(child.find("ParmValue")) if name in self._parms: raise Exception("Duplicate parm {!r}".format(name)) self._parms[name] = value return self._parms
def pattern(self): """String for the regular expression used for validation.""" if not hasattr(self, "_pattern"): node = self.__node.find("ParmInfoPattern") self._pattern = Doc.get_text(node) return self._pattern
def method(self): """Name of the method used to validate these values.""" if not hasattr(self, "_method"): node = self.__node.find("ParmInfoMethod") self._method = Doc.get_text(node) return self._method
def help(self): """String for the explanation of the parameter.""" if not hasattr(self, "_help"): help = Doc.get_text(self.__node.find("ParmInfoHelp")) self._help = help.replace("\r", "") return self._help
def description(self): """String explaining how this subset is to be used.""" if not hasattr(self, "_description"): node = self.__node.find("SubsetDescription") self._description = Doc.get_text(node, "") return self._description
def description(self): """String containing the description of this system's usage.""" if not hasattr(self, "_description"): node = self.doc.root.find("SystemDescription") self._description = Doc.get_text(node, "").strip() return self._description
def title(self): """String for the using document's title.""" if not hasattr(self, "_title"): doc = Doc(self.__media.control.session, id=self.doc_id) self._title = doc.title.split(";")[0].strip() return self._title
def spanish_response(self): """Response to request to use Spanish media content.""" path = "PermissionInformation/SpanishTranslationPermissionResponse" if not hasattr(self, "_spanish_response"): self._spanish_response = Doc.get_text(self.doc.root.find(path)) return self._spanish_response
def response_date(self): """Date the response to the request was received.""" if not hasattr(self, "_response_date"): path = "PermissionInformation/PermissionResponseDate" self._response_date = Doc.get_text(self.doc.root.find(path)) return self._response_date
def english_request(self): """Request for use of English media content.""" if not hasattr(self, "_english_request"): path = "PermissionInformation/PermissionRequested" self._english_request = Doc.get_text(self.doc.root.find(path)) return self._english_request
def expiration_date(self): """Date on which the permission expires.""" if not hasattr(self, "_expiration_date"): path = "PermissionInformation/PermissionExpirationDate" self._expiration_date = Doc.get_text(self.doc.root.find(path)) return self._expiration_date
def request_date(self): """Date the request was submitted.""" if not hasattr(self, "_request_date"): path = "PermissionInformation/PermissionRequestDate" self._request_date = Doc.get_text(self.doc.root.find(path)) return self._request_date