Esempio n. 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))
Esempio n. 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))
Esempio n. 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)
Esempio n. 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)
Esempio n. 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))