def _process(self): title = "{} (copy)".format(self.template.title) new_template = DesignerTemplate(title=title, type=self.template.type, data=self.template.data, **self.target_dict) if self.template.background_image: background = self.template.background_image new_background = DesignerImageFile( filename=background.filename, content_type=background.content_type, template=new_template) with background.open() as f: new_background.save(f) else: new_background = None new_template.background_image = new_background flash( _("Created copy of template '{}'").format(self.template.title), 'success') return jsonify_data( html=_render_template_list(self.target, event=self.event_or_none))
def _migrate_templates(self, manager): for tpl_id, old_tpl in getattr( manager, '_{}__templates'.format(self.manager_class)).iteritems(): old_background_map = {} old_tpl_data = getattr(old_tpl, '_{}__templateData'.format(self.tpl_class)) translated_data = self._translate_tpl_data(old_tpl_data) if translated_data is None: continue tpl = DesignerTemplate(type=self.type, **translated_data) for old_bg_id, old_bg in getattr( old_tpl, '_{}__backgrounds'.format(self.tpl_class)).viewitems(): image = self._migrate_background(old_bg, tpl) if image: old_background_map[int(old_bg_id)] = image tpl.images.append(image) self.importer.print_success( cformat('\t %{cyan!}{}').format(image), event_id=self.event_id) old_positions_map = getattr( old_tpl, '_{}__bgPositions'.format(self.tpl_class), None) old_used_bg_id = int(old_tpl_data[3]) if old_used_bg_id >= 0: new_bg_image = old_background_map.get(old_used_bg_id) if new_bg_image: tpl.background_image = new_bg_image else: self.importer.print_warning( cformat("%{yellow!}Background '{}' not found").format( old_used_bg_id), event_id=self.event_id) if old_positions_map: old_position = old_positions_map.get(old_used_bg_id) if old_position: tpl.data['background_position'] = unicode( old_position.lower()) else: self.importer.print_warning(cformat( '%{yellow!}Position setting for non-existing background' ), event_id=self.event_id) if 'background_position' not in tpl.data: tpl.data['background_position'] = 'stretch' if self.event is None: tpl.category = Category.get_root() else: tpl.event_new = self.event self.importer.print_success(cformat('%{blue!}{}').format(tpl), event_id=self.event_id)
def _process(self): title = "{} (copy)".format(self.template.title) new_template = DesignerTemplate(title=title, type=self.template.type, data=self.template.data, **self.target_dict) if self.template.background_image: background = self.template.background_image new_background = DesignerImageFile(filename=background.filename, content_type=background.content_type, template=new_template) with background.open() as f: new_background.save(f) else: new_background = None new_template.background_image = new_background flash(_("Created copy of template '{}'").format(self.template.title), 'success') return jsonify_data(html=_render_template_list(self.target, event=self.event_or_none))
def _process(self): title = f'{self.template.title} (copy)' new_template = DesignerTemplate(title=title, type=self.template.type, **self.target_dict) data = deepcopy(self.template.data) image_items = [ item for item in data['items'] if item['type'] == 'fixed_image' ] for image_item in image_items: old_image = DesignerImageFile.get(image_item['image_id']) new_image = DesignerImageFile(filename=old_image.filename, content_type=old_image.content_type, template=new_template) with old_image.open() as f: new_image.save(f) image_item['image_id'] = new_image.id new_template.data = data if self.template.background_image: background = self.template.background_image new_background = DesignerImageFile( filename=background.filename, content_type=background.content_type, template=new_template) with background.open() as f: new_background.save(f) else: new_background = None new_template.background_image = new_background flash( _("Created copy of template '{}'").format(self.template.title), 'success') return jsonify_data( html=_render_template_list(self.target, event=self.event_or_none))