Skip to content

Commit

Permalink
Merge 84b614d into 10904b4
Browse files Browse the repository at this point in the history
  • Loading branch information
nrvikas committed Feb 4, 2020
2 parents 10904b4 + 84b614d commit 86c09f7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
5 changes: 5 additions & 0 deletions client/components/Planning/PlanningEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ export class PlanningEditorComponent extends React.Component {
this.props.defaultDesk,
this.props.preferredCoverageDesks);

newCoverage.coverage_id = newCoverage.coverage_id + '-duplicate';
if (['picture', 'Picture'].includes(newCoverage.planning.g2_content_type) && coverage.planning.xmp_file) {
newCoverage.planning.xmp_file = coverage.planning.xmp_file;
}

if (coverage.workflow_status === WORKFLOW_STATE.CANCELLED) {
newCoverage.planning.workflow_status_reason = null;
}
Expand Down
33 changes: 32 additions & 1 deletion server/planning/planning/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,10 @@ def remove_coverage_entity(self, coverage_entity, original_planning, entity_type

def add_coverages(self, updates, original):
for coverage in (updates.get('coverages') or []):
coverage_id = coverage.get('coverage_id')
coverage_id = coverage.get('coverage_id', '')
if not coverage_id or TEMP_ID_PREFIX in coverage_id:
if 'duplicate' in coverage_id:
self.duplicate_xmp_file(coverage)
# coverage to be created
coverage['coverage_id'] = generate_guid(type=GUID_NEWSML)
coverage['firstcreated'] = utcnow()
Expand Down Expand Up @@ -1114,6 +1116,35 @@ def set_xmp_file_info(self, updates_coverage):
updates_coverage['planning']['xmp_file']
))

def duplicate_xmp_file(self, coverage):
cov_plan = coverage.get('planning') or {}
if not (cov_plan.get('xmp_file') and get_coverage_type_name(cov_plan.get('g2_content_type')) in ['Picture',
'picture']):
return

file_id = coverage['planning']['xmp_file']
xmp_file = get_resource_service('planning_files').find_one(req=None, _id=file_id)
coverage_msg = 'Duplicating Coverage: {}'.format(coverage['coverage_id'])
if not xmp_file:
logger.error('XMP File {} attached to coverage not found. {}'.format(file_id, coverage_msg))
return

xmp_file = app.media.get(xmp_file['media'], resource='planning_files')
if not xmp_file:
logger.error('Media file for XMP File {} not found. {}'.format(file_id, coverage_msg))
return

try:
buf = BytesIO()
buf.write(xmp_file.read())
buf.seek(0)
media_id = app.media.put(buf, resource='planning_files', filename=xmp_file.name,
content_type='application/octet-stream')
except Exception as e:
logger.exception('Error creating media file. {}. Exception: {}'.format(coverage_msg, e))
planning_file_ids = get_resource_service('planning_files').post([{'media': media_id}])
coverage['planning']['xmp_file'] = planning_file_ids[0]


event_type = deepcopy(superdesk.Resource.rel('events', type='string'))
event_type['mapping'] = not_analyzed
Expand Down
5 changes: 3 additions & 2 deletions server/planning/planning/planning_duplicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from superdesk.metadata.item import GUID_NEWSML
from superdesk.utc import utcnow, utc_to_local
from flask import request
from planning.common import ITEM_STATE, WORKFLOW_STATE
from planning.common import ITEM_STATE, WORKFLOW_STATE, TEMP_ID_PREFIX
from copy import deepcopy


Expand Down Expand Up @@ -86,8 +86,9 @@ def _duplicate_planning(self, original):
for cov in new_plan.get('coverages') or []:
cov.pop('assigned_to', None)
cov.get('planning', {}).pop('workflow_status_reason', None)
cov.pop('scheduled_updates', None)
cov.get('planning', {})['scheduled'] = new_plan.get('planning_date')
cov['coverage_id'] = generate_guid(type=GUID_NEWSML)
cov['coverage_id'] = TEMP_ID_PREFIX + 'duplicate'
cov['workflow_status'] = WORKFLOW_STATE.DRAFT
cov['news_coverage_status'] = {'qcode': 'ncostat:int'}

Expand Down

0 comments on commit 86c09f7

Please sign in to comment.