continue mime_type = data.get('mimetype') if mime_type is None: # these default values need to be used if mime_type is not found mime_type = 'image/jpeg' if type_ == 'image' or type_ == 'grafikk' else 'video/mpeg' caption = self.strip_invalid_chars(data.get( 'description_text', '')) self._add_media(body_content, type_, mime_type, source, caption) self._add_meta_media_counter(head, len(media_data)) def _format_body_end(self, article, body_end): try: emails = [s.strip() for s in article['sign_off'].split('/')] except KeyError: return if emails: tagline = etree.SubElement(body_end, 'tagline') previous = None for email in emails: if not email: continue a = etree.SubElement(tagline, 'a', {'href': 'mailto:{}'.format(email)}) a.text = email if previous is not None: previous.tail = '/' previous = a PublishService.register_file_extension('ntbnitf', 'xml')
# the value of image/media is not used yet but may be in the future featured = data.get('_featured') if mime_type is None: # these default values need to be used if mime_type is not found mime_type = 'image/jpeg' if type_ == 'image' or type_ == 'grafikk' else 'video/mpeg' caption = self.strip_invalid_chars(data.get('description_text')) self._add_media(body_content, type_, mime_type, source, caption, featured) self._add_meta_media_counter(head, len(media_data)) def _format_body_end(self, article, body_end): try: emails = [s.strip() for s in article['sign_off'].split('/')] except KeyError: return if emails: tagline = etree.SubElement(body_end, 'tagline') previous = None for email in emails: if not email: continue a = etree.SubElement(tagline, 'a', {'href': 'mailto:{}'.format(email)}) a.text = email if previous is not None: previous.tail = '/' previous = a PublishService.register_file_extension(NTBNITFFormatter.FORMAT_TYPE, 'xml')
from .ntb_nitf import NTBNITFFormatter class NTBNITFMultiServiceFormatter(NTBNITFFormatter): """This NITF formatter generates single file with all services.""" FORMAT_TYPE = 'ntbnitf' # default ntb nitf formatter def _format_service(self, article): try: service_names = ", ".join( service.get("name", "") for service in article['anpa_category']) return service_names except (KeyError): pass class NTBNITFMultiServiceMediaFormatter(NTBNITFMultiServiceFormatter): FORMAT_TYPE = 'ntbnitfmedia' def _get_media_source(self, data): return self._get_original_href(data) PublishService.register_file_extension( NTBNITFMultiServiceFormatter.FORMAT_TYPE, 'xml') PublishService.register_file_extension( NTBNITFMultiServiceMediaFormatter.FORMAT_TYPE, 'xml')