Beispiel #1
0
    def values(self):
        """Dictionary of values to be sent to the CMS.

        We use a negative CDR ID to avoid conflicts with live summaries.
        """

        if not hasattr(self, "_values"):
            opts = dict(parms=dict(DateFirstPub="", isPP="Y"))
            result = self.doc.filter(self.VENDOR_FILTERS, **opts)
            root = result.result_tree.getroot()
            xsl = Doc.load_single_filter(self.doc.session, self.CMS_FILTER)
            args = self.doc.session, self.doc.id, xsl, root
            self._values = self.ASSEMBLE(*args)
            self._values["cdr_id"] = -self._values["cdr_id"]
            self.__control.show_progress("filtered document...")
        return self._values
Beispiel #2
0
    def transform(self):
        """Compiled filter to generate JSON for the drug documents."""

        if not hasattr(self, "_transform"):
            self._transform = Doc.load_single_filter(self.session, self.FILTER)
        return self._transform
Beispiel #3
0
parser.add_argument("--base", help="override base URL for Drupal site")
parser.add_argument("--password", help="override password for PDQ account")
parser.add_argument("--dumpfile", help="where to store the serialized doc")
parser.add_argument("--id", type=int, help="CDR ID for Summary", required=True)
opts = parser.parse_args()
auth = ("PDQ", opts.password) if opts.password else None

# Make sure we are allowed to publish to the CMS.
session = Session(opts.session, tier=opts.tier)
if not session.can_do("USE PUBLISHING SYSTEM"):
    raise Exception("Not authorized")

# Prepare the document.
doc = Doc(session, id=opts.id)
print(("Pushing {} document {}".format(doc.doctype.name, doc.cdr_id)))
root = Control.fetch_exported_doc(session, doc.id, "pub_proc_cg")
xsl = Doc.load_single_filter(session, FILTERS[doc.doctype.name])
values = ASSEMBLE[doc.doctype.name](session, doc.id, xsl, root)
if opts.dumpfile:
    with open(opts.dumpfile, "w") as fp:
        fp.write(dumps(values))

# Store the document and mark it publishable.
client = DrupalClient(session, auth=auth, base=opts.base, tier=opts.tier)
nid = client.push(values)
documents = [(doc.id, nid, values.get("language", "en"))]
errors = client.publish(documents)
print(("pushed {} as Drupal node {:d}".format(doc.cdr_id, nid)))
if errors:
    print(errors)