コード例 #1
0
 def format(self, article, subscriber, codes=None):
     formatted_article = deepcopy(article)
     pub_seq_num = superdesk.get_resource_service(
         'subscribers').generate_sequence_number(subscriber)
     doc = {}
     try:
         # If there is a dateline inject it into the body
         if formatted_article.get(
                 FORMAT) == FORMATS.HTML and formatted_article.get(
                     'dateline', {}).get('text'):
             soup = BeautifulSoup(formatted_article.get('body_html'),
                                  "html.parser")
             ptag = soup.find('p')
             if ptag is not None:
                 ptag.insert(
                     0,
                     NavigableString('{} '.format(
                         formatted_article.get('dateline').get('text'))))
                 formatted_article['body_html'] = str(soup)
             doc['message_html'] = render_template(
                 'email_article_body.html', article=formatted_article)
         else:
             doc['message_html'] = None
         doc['message_text'] = render_template('email_article_body.txt',
                                               article=formatted_article)
         doc['message_subject'] = render_template(
             'email_article_subject.txt', article=formatted_article)
     except Exception as ex:
         raise FormatterError.EmailFormatterError(ex, FormatterError)
     return [(pub_seq_num, json.dumps(doc))]
コード例 #2
0
 def format(self, article, subscriber, codes=None):
     formatted_article = deepcopy(article)
     pub_seq_num = superdesk.get_resource_service('subscribers').generate_sequence_number(subscriber)
     doc = {}
     try:
         if formatted_article.get(FORMAT) == FORMATS.HTML:
             if formatted_article.get('dateline', {}).get('text'):
                 # If there is a dateline inject it into the body
                 self._inject_dateline(formatted_article)
             doc['message_html'] = render_template('email_article_body.html', article=formatted_article)
         else:
             doc['message_html'] = None
         doc['message_text'] = render_template('email_article_body.txt', article=formatted_article)
         doc['message_subject'] = render_template('email_article_subject.txt', article=formatted_article)
     except Exception as ex:
         raise FormatterError.EmailFormatterError(ex, FormatterError)
     return [(pub_seq_num, json.dumps(doc))]
コード例 #3
0
 def format(self, article, subscriber, codes=None):
     formatted_article = deepcopy(article)
     pub_seq_num = superdesk.get_resource_service(
         "subscribers").generate_sequence_number(subscriber)
     doc = {}
     try:
         if formatted_article.get(FORMAT) == FORMATS.HTML:
             if formatted_article.get("dateline", {}).get("text"):
                 # If there is a dateline inject it into the body
                 self._inject_dateline(formatted_article)
             doc["message_html"] = render_template(
                 "email_article_body.html", article=formatted_article)
         else:
             doc["message_html"] = None
         doc["message_text"] = render_template("email_article_body.txt",
                                               article=formatted_article)
         doc["message_subject"] = render_template(
             "email_article_subject.txt", article=formatted_article)
         doc["renditions"] = ((formatted_article.get("associations", {})
                               or {}).get("featuremedia", {})
                              or {}).get("renditions")
     except Exception as ex:
         raise FormatterError.EmailFormatterError(ex, FormatterError)
     return [(pub_seq_num, json.dumps(doc))]