def _parse_job_results(results, feed_data): """Parse the job results from the backend to create the feed data. :param results: The results from the backend, a list of dicts. :type results: list :param feed_data: The feed data structure. :type feed_data: dict :return: Yield a dictionary with the correct values for the feed entry. """ if results and results["result"]: results = results["result"] f_get = feed_data.get for result in results: counts = _get_job_counts(copy.deepcopy(result)) result.update(counts) content_links = copy.deepcopy(f_get("content_links", None)) if content_links: for c_link in content_links: c_link["href"] = c_link["href"] % result c_link["label"] = c_link["label"] % result result["content_links"] = content_links job_date = feed.convert_date(result["created_on"]["$date"]) # pylint: disable=star-args content = u"" content += \ feed.TEMPLATES_ENV.get_template( f_get("template_name")).render(**result) parsed_res = { "content": content, "links": [{ "href": f_get("alternate_url") % result, "rel": "alternate" }], "published": job_date, "title": f_get("entry_title") % result, "updated": job_date, "url": f_get("frontend_url") % result } yield parsed_res
def _parse_job_results(results, feed_data): """Parse the job results from the backend to create the feed data. :param results: The results from the backend, a list of dicts. :type results: list :param feed_data: The feed data structure. :type feed_data: dict :return: Yield a dictionary with the correct values for the feed entry. """ if results and results["result"]: results = results["result"] f_get = feed_data.get for result in results: counts = _get_job_counts(copy.deepcopy(result)) result.update(counts) content_links = copy.deepcopy(f_get("content_links", None)) if content_links: for c_link in content_links: c_link["href"] = c_link["href"] % result c_link["label"] = c_link["label"] % result result["content_links"] = content_links job_date = feed.convert_date(result["created_on"]["$date"]) # pylint: disable=star-args content = u"" content += \ feed.TEMPLATES_ENV.get_template( f_get("template_name")).render(**result) parsed_res = { "content": content, "links": [ { "href": f_get("alternate_url") % result, "rel": "alternate" } ], "published": job_date, "title": f_get("entry_title") % result, "updated": job_date, "url": f_get("frontend_url") % result } yield parsed_res
def _common_boot_parse(result, feed_data): """Common boot reports parsing function. :param result: The result from the backend. :type result: dict :param feed_data: Data structure for the feed. :type feed_data: dict :return: A dictionary with the correct keys to be used for a feed entry. """ f_get = feed_data.get boot_date = feed.convert_date(result["created_on"]["$date"]) # If we have links that should be added to the feed content, # extract them and update the href values with the result ones. # Then inject the content_links into the result data structure to # be used by the template. content_links = copy.deepcopy(f_get("content_links", None)) if content_links: for c_link in content_links: c_link["href"] = c_link["href"] % result c_link["label"] = c_link["label"] % result result["content_links"] = content_links content = u"" content += \ feed.TEMPLATES_ENV.get_template( f_get("template_name")).render(**result) parsed_res = { "content": content, "links": [ { "href": f_get("alternate_url") % result, "rel": "alternate" } ], "published": boot_date, "title": f_get("entry_title") % result, "updated": boot_date, "url": f_get("frontend_url") % result } return parsed_res