def fix_hrefs(doc): if doc.get('renditions'): for key, rendition in doc['renditions'].items(): if rendition.get('media'): rendition['href'] = app.upload_url(rendition['media']) for assoc in doc.get('associations', {}).values(): fix_hrefs(assoc)
def _store_image(image, filename=None, _id=None): binary = io.BytesIO() image.save(binary, 'jpeg', quality=THUMBNAIL_QUALITY) binary.seek(0) media_id = app.media.put(binary, filename=filename, _id=_id, resource=ASSETS_RESOURCE, content_type='image/jpeg') if not media_id: # media with the same id exists media_id = _id binary.seek(0) return { 'media': str(media_id), 'href': app.upload_url(media_id), 'width': image.width, 'height': image.height, 'mimetype': 'image/jpeg' }
def publish_event(event, orig): logger.debug('publishing event %s', event) # populate attachments href if event.get('files'): for file_ref in event['files']: if file_ref.get('media'): file_ref.setdefault('href', app.upload_url(file_ref['media'])) _id = event['guid'] service = superdesk.get_resource_service('agenda') if not orig: # new event agenda = {} set_agenda_metadata_from_event(agenda, event) agenda['dates'] = get_event_dates(event) _id = service.create([agenda])[0] else: # replace the original document if event.get('state') in [WORKFLOW_STATE.CANCELLED, WORKFLOW_STATE.KILLED] or \ event.get('pubstatus') == 'cancelled': # it has been cancelled so don't need to change the dates # update the event, the version and the state updates = { 'event': event, 'version': event.get('version', event.get(app.config['VERSION'])), 'state': event['state'] } service.patch(event['guid'], updates) superdesk.get_resource_service('agenda').notify_agenda_update( 'event_unposted', orig) elif event.get('state') in [ WORKFLOW_STATE.RESCHEDULED, WORKFLOW_STATE.POSTPONED ]: # schedule is changed, recalculate the dates, planning id and coverages from dates will be removed updates = {} set_agenda_metadata_from_event(updates, event) updates['dates'] = get_event_dates(event) updates['coverages'] = None updates['planning_items'] = None service.patch(event['guid'], updates) superdesk.get_resource_service('agenda').notify_agenda_update( 'event_updated', orig) elif event.get('state') == WORKFLOW_STATE.SCHEDULED: # event is reposted (possibly after a cancel) updates = { 'event': event, 'version': event.get('version', event.get(app.config['VERSION'])), 'state': event['state'], 'dates': get_event_dates(event), } set_agenda_metadata_from_event(updates, event) service.patch(event['guid'], updates) superdesk.get_resource_service('agenda').notify_agenda_update( 'event_updated', orig) return _id