示例#1
0
    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))
示例#2
0
    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))
示例#3
0
 def _process(self):
     f = request.files['file']
     filename = secure_filename(f.filename, 'image')
     data = BytesIO()
     shutil.copyfileobj(f, data)
     data.seek(0)
     try:
         image_type = Image.open(data).format.lower()
     except OSError:
         # Invalid image data
         return jsonify(error="Invalid image data!")
     data.seek(0)
     if image_type not in {'jpeg', 'gif', 'png'}:
         return jsonify(error="File format not accepted!")
     content_type = 'image/' + image_type
     image = DesignerImageFile(template=self.template, filename=filename, content_type=content_type)
     self.template.background_image = image
     image.save(data)
     flash(_("The image has been uploaded"), 'success')
     return jsonify_data(image_url=image.download_url)
示例#4
0
 def _process(self):
     f = request.files['file']
     filename = secure_filename(f.filename, 'image')
     data = BytesIO()
     shutil.copyfileobj(f, data)
     data.seek(0)
     try:
         image_type = Image.open(data).format.lower()
     except IOError:
         # Invalid image data
         return jsonify(error="Invalid image data!")
     data.seek(0)
     if image_type not in {'jpeg', 'gif', 'png'}:
         return jsonify(error="File format not accepted!")
     content_type = 'image/' + image_type
     image = DesignerImageFile(template=self.template, filename=filename, content_type=content_type)
     self.template.background_image = image
     image.save(data)
     flash(_("The image has been uploaded"), 'success')
     return jsonify_data(image_url=image.download_url)
示例#5
0
    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))
 def _migrate_background(self, old_bg, tpl):
     storage_backend, storage_path, size = self.importer._get_local_file_info(
         old_bg)
     if storage_path is None:
         self.importer.print_error(
             '%[red!]File not found on disk; skipping it [{}]'.format(
                 convert_to_unicode(old_bg.fileName)),
             event_id=self.event_id)
         return
     content_type = mimetypes.guess_type(
         old_bg.fileName)[0] or 'application/octet-stream'
     filename = secure_filename(convert_to_unicode(old_bg.fileName),
                                'attachment')
     return DesignerImageFile(filename=filename,
                              content_type=content_type,
                              size=size,
                              storage_backend=storage_backend,
                              storage_file_id=storage_path)
示例#7
0
 def _process_args(self):
     RHModifyDesignerTemplateBase._process_args(self)
     self.image = DesignerImageFile.find_one(id=request.view_args['image_id'], template=self.template)
示例#8
0
 def _process_args(self):
     RHModifyDesignerTemplateBase._process_args(self)
     self.image = DesignerImageFile.find_one(id=request.view_args['image_id'], template=self.template)
示例#9
0
 def _checkParams(self, params):
     RHModifyDesignerTemplateBase._checkParams(self, params)
     self.image = DesignerImageFile.find_one(
         id=request.view_args['image_id'], template=self.template)
示例#10
0
 def render(cls, item):
     buf = DesignerImageFile.get(item['image_id']).open()
     return Image.open(buf)