Ejemplo n.º 1
0
 def _process(self):
     f = request.files["file"]
     try:
         img = Image.open(f)
     except IOError:
         flash(_("You cannot upload this file as a logo."), "error")
         return jsonify_data(content=None)
     if img.format.lower() not in {"jpeg", "png", "gif"}:
         flash(_("The file has an invalid format ({format})").format(format=img.format), "error")
         return jsonify_data(content=None)
     if img.mode == "CMYK":
         flash(
             _(
                 "The logo you uploaded is using the CMYK colorspace and has been converted to RGB. Please check if "
                 "the colors are correct and convert it manually if necessary."
             ),
             "warning",
         )
         img = img.convert("RGB")
     image_bytes = BytesIO()
     img.save(image_bytes, "PNG")
     image_bytes.seek(0)
     content = image_bytes.read()
     self.event.logo = content
     self.event.logo_metadata = {
         "hash": crc32(content),
         "size": len(content),
         "filename": os.path.splitext(secure_filename(f.filename, "logo"))[0] + ".png",
         "content_type": "image/png",
     }
     flash(_("New logo saved"), "success")
     logger.info("New logo '%s' uploaded by %s (%s)", f.filename, session.user, self.event)
     return jsonify_data(content=_logo_data(self.event))
Ejemplo n.º 2
0
 def _process(self):
     f = request.files['logo']
     try:
         img = Image.open(f)
     except IOError:
         flash(_('You cannot upload this file as a logo.'), 'error')
         return jsonify_data(content=None)
     if img.format.lower() not in {'jpeg', 'png', 'gif'}:
         flash(
             _('The file has an invalid format ({format})').format(
                 format=img.format), 'error')
         return jsonify_data(content=None)
     if img.mode == 'CMYK':
         flash(
             _('The logo you uploaded is using the CMYK colorspace and has been converted to RGB. Please check if '
               'the colors are correct and convert it manually if necessary.'
               ), 'warning')
         img = img.convert('RGB')
     image_bytes = BytesIO()
     img.save(image_bytes, 'PNG')
     image_bytes.seek(0)
     content = image_bytes.read()
     self.event_new.logo = content
     self.event_new.logo_metadata = {
         'hash': crc32(content),
         'size': len(content),
         'filename':
         os.path.splitext(secure_filename(f.filename, 'logo'))[0] + '.png',
         'content_type': 'image/png'
     }
     flash(_('New logo saved'), 'success')
     logger.info("New logo '%s' uploaded by %s (%s)", f.filename,
                 session.user, self.event_new)
     return jsonify_data(content=get_logo_data(self.event_new))
Ejemplo n.º 3
0
 def _process(self):
     self.event.logo = None
     self.event.logo_metadata = None
     flash(_('Logo deleted'), 'success')
     logger.info("Logo of {} deleted by {}".format(self.event,
                                                   session.user))
     return jsonify_data(content=None)
Ejemplo n.º 4
0
 def _process(self):
     f = request.files['logo']
     try:
         img = Image.open(f)
     except IOError:
         flash(_('You cannot upload this file as a logo.'), 'error')
         return jsonify_data(content=None)
     if img.format.lower() not in {'jpeg', 'png', 'gif'}:
         flash(_('The file has an invalid format ({format})').format(format=img.format), 'error')
         return jsonify_data(content=None)
     if img.mode == 'CMYK':
         flash(_('The logo you uploaded is using the CMYK colorspace and has been converted to RGB. Please check if '
                 'the colors are correct and convert it manually if necessary.'), 'warning')
         img = img.convert('RGB')
     image_bytes = BytesIO()
     img.save(image_bytes, 'PNG')
     image_bytes.seek(0)
     content = image_bytes.read()
     self.event.logo = content
     self.event.logo_metadata = {
         'hash': crc32(content),
         'size': len(content),
         'filename': os.path.splitext(secure_filename(f.filename, 'logo'))[0] + '.png',
         'content_type': 'image/png'
     }
     flash(_('New logo saved'), 'success')
     logger.info("New logo '%s' uploaded by %s (%s)", f.filename, session.user, self.event)
     return jsonify_data(content=get_logo_data(self.event))
Ejemplo n.º 5
0
 def _process(self):
     self.event.stylesheet = None
     self.event.stylesheet_metadata = None
     layout_settings.set(self.event, 'use_custom_css', False)
     flash(_('CSS file deleted'), 'success')
     logger.info("CSS file for %s deleted by %s", self.event, session.user)
     return jsonify_data(content=None)
Ejemplo n.º 6
0
 def _process(self):
     files = request.files.getlist('image')
     num = 0
     for f in files:
         filename = secure_client_filename(f.filename)
         data = BytesIO()
         shutil.copyfileobj(f, data)
         data.seek(0)
         try:
             image_type = Image.open(data).format.lower()
         except OSError:
             # Invalid image data
             continue
         data.seek(0)
         # XXX: mpo is basically JPEG and JPEGs from some cameras are (wrongfully) detected as mpo
         if image_type == 'mpo':
             image_type = 'jpeg'
         elif image_type not in {'jpeg', 'gif', 'png'}:
             flash(_("The image '{name}' has an invalid type ({type}); only JPG, GIF and PNG are allowed.")
                   .format(name=f.filename, type=image_type), 'error')
             continue
         content_type = 'image/' + image_type
         image = ImageFile(event=self.event, filename=filename, content_type=content_type)
         image.save(data)
         num += 1
         db.session.flush()
         logger.info('Image %s uploaded by %s', image, session.user)
         signals.event_management.image_created.send(image, user=session.user)
     flash(ngettext('The image has been uploaded', '{count} images have been uploaded', num)
           .format(count=len(files)), 'success')
     return jsonify_data(image_list=_render_image_list(self.event))
Ejemplo n.º 7
0
 def _process(self):
     files = request.files.getlist('file')
     for f in files:
         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
             continue
         data.seek(0)
         if image_type not in {'jpeg', 'gif', 'png'}:
             continue
         content_type = 'image/' + image_type
         image = ImageFile(event_new=self.event_new,
                           filename=filename,
                           content_type=content_type)
         image.save(data)
         db.session.flush()
         logger.info('Image %s uploaded by %s', image, session.user)
         signals.event_management.image_created.send(image,
                                                     user=session.user)
     flash(
         ngettext("The image has been uploaded",
                  "{count} images have been uploaded",
                  len(files)).format(count=len(files)), 'success')
     return jsonify_data(image_list=_render_image_list(self._conf))
Ejemplo n.º 8
0
 def _process(self):
     files = request.files.getlist('image')
     num = 0
     for f in files:
         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
             continue
         data.seek(0)
         # XXX: mpo is basically JPEG and JPEGs from some cameras are (wrongfully) detected as mpo
         if image_type == 'mpo':
             image_type = 'jpeg'
         elif image_type not in {'jpeg', 'gif', 'png'}:
             flash(_("The image '{name}' has an invalid type ({type}); only JPG, GIF and PNG are allowed.")
                   .format(name=f.filename, type=image_type), 'error')
             continue
         content_type = 'image/' + image_type
         image = ImageFile(event=self.event, filename=filename, content_type=content_type)
         image.save(data)
         num += 1
         db.session.flush()
         logger.info('Image %s uploaded by %s', image, session.user)
         signals.event_management.image_created.send(image, user=session.user)
     flash(ngettext("The image has been uploaded", "{count} images have been uploaded", num)
           .format(count=len(files)), 'success')
     return jsonify_data(image_list=_render_image_list(self.event))
Ejemplo n.º 9
0
 def _process(self):
     files = request.files.getlist("image")
     for f in files:
         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
             continue
         data.seek(0)
         if image_type not in {"jpeg", "gif", "png"}:
             continue
         content_type = "image/" + image_type
         image = ImageFile(event_new=self.event_new, filename=filename, content_type=content_type)
         image.save(data)
         db.session.flush()
         logger.info("Image %s uploaded by %s", image, session.user)
         signals.event_management.image_created.send(image, user=session.user)
     flash(
         ngettext("The image has been uploaded", "{count} images have been uploaded", len(files)).format(
             count=len(files)
         ),
         "success",
     )
     return jsonify_data(image_list=_render_image_list(self.event_new))
Ejemplo n.º 10
0
 def _process(self):
     files = request.files.getlist('file')
     for f in files:
         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
             continue
         data.seek(0)
         if image_type not in {'jpeg', 'gif', 'png'}:
             continue
         content_type = 'image/' + image_type
         image = ImageFile(event_id=self._conf.id, filename=filename, content_type=content_type)
         image.save(data)
         db.session.add(image)
         db.session.flush()
         logger.info('Image {} uploaded by {}'.format(image, session.user))
         signals.event_management.image_created.send(image, user=session.user)
     flash(ngettext("The image has been uploaded", "{count} images have been uploaded", len(files))
           .format(count=len(files)), 'success')
     return jsonify_data(image_list=_render_image_list(self._conf))
Ejemplo n.º 11
0
 def _process(self):
     self.event.stylesheet = None
     self.event.stylesheet_metadata = None
     layout_settings.set(self.event, 'use_custom_css', False)
     flash(_('CSS file deleted'), 'success')
     logger.info("CSS file for %s deleted by %s", self.event, session.user)
     return jsonify_data(content=None)
Ejemplo n.º 12
0
 def _process(self):
     enabled = request.form['enabled'] == '1'
     if enabled:
         # nothing else to do here. menu items are added to the DB when retrieving the menu
         flash(_('Menu customization has been enabled.'), 'success')
     else:
         for entry in MenuEntry.query.with_parent(self.event):
             db.session.delete(entry)
         flash(_('Menu customization has been disabled.'), 'success')
     layout_settings.set(self.event, 'use_custom_menu', enabled)
     logger.info('Menu customization for %s %s by %s', self.event,
                 'enabled' if enabled else 'disabled', session.user)
     return jsonify(enabled=enabled)
Ejemplo n.º 13
0
 def _process(self):
     f = request.files['css_file']
     self.event.stylesheet = to_unicode(f.read()).strip()
     self.event.stylesheet_metadata = {
         'hash': crc32(self.event.stylesheet),
         'size': len(self.event.stylesheet),
         'filename': secure_filename(f.filename, 'stylesheet.css')
     }
     db.session.flush()
     flash(_('New CSS file saved. Do not forget to enable it ("Use custom CSS") after verifying that it is correct '
             'using the preview.'), 'success')
     logger.info('CSS file for %s uploaded by %s', self.event, session.user)
     return jsonify_data(content=get_css_file_data(self.event))
Ejemplo n.º 14
0
 def _process(self):
     enabled = request.form['enabled'] == '1'
     if enabled:
         # nothing else to do here. menu items are added to the DB when retrieving the menu
         flash(_('Menu customization has been enabled.'), 'success')
     else:
         for entry in MenuEntry.find(event_id=int(self._conf.id)):
             db.session.delete(entry)
         flash(_('Menu customization has been disabled.'), 'success')
     layout_settings.set(self._conf, 'use_custom_menu', enabled)
     logger.info('Menu customization for {} {} by {}'.format(self._conf, 'enabled' if enabled else 'disabled',
                                                             session.user))
     return jsonify(enabled=enabled)
Ejemplo n.º 15
0
 def _process(self):
     enabled = request.form['enabled'] == '1'
     if enabled:
         # nothing else to do here. menu items are added to the DB when retrieving the menu
         flash(_('Menu customization has been enabled.'), 'success')
     else:
         for entry in MenuEntry.query.with_parent(self.event):
             db.session.delete(entry)
         flash(_('Menu customization has been disabled.'), 'success')
     layout_settings.set(self.event, 'use_custom_menu', enabled)
     logger.info('Menu customization for %s %s by %s', self.event, 'enabled' if enabled else 'disabled',
                 session.user)
     return jsonify(enabled=enabled)
Ejemplo n.º 16
0
 def _process(self):
     f = request.files['css_file']
     self.event.stylesheet = to_unicode(f.read()).strip()
     self.event.stylesheet_metadata = {
         'hash': crc32(self.event.stylesheet),
         'size': len(self.event.stylesheet),
         'filename': secure_filename(f.filename, 'stylesheet.css')
     }
     db.session.flush()
     flash(_('New CSS file saved. Do not forget to enable it ("Use custom CSS") after verifying that it is correct '
             'using the preview.'), 'success')
     logger.info('CSS file for %s uploaded by %s', self.event, session.user)
     return jsonify_data(content=get_css_file_data(self.event))
Ejemplo n.º 17
0
 def _process(self):
     f = request.files["file"]
     self.event.stylesheet = to_unicode(f.read()).strip()
     self.event.stylesheet_metadata = {
         "hash": crc32(self.event.stylesheet),
         "size": len(self.event.stylesheet),
         "filename": secure_filename(f.filename, "stylesheet.css"),
     }
     db.session.flush()
     flash(
         _(
             'New CSS file saved. Do not forget to enable it ("Use custom CSS") after verifying that it is correct '
             "using the preview."
         ),
         "success",
     )
     logger.info("CSS file for %s uploaded by %s", self.event, session.user)
     return jsonify_data(content=_css_file_data(self.event))
Ejemplo n.º 18
0
 def _process(self):
     self.event.logo = None
     self.event.logo_metadata = None
     flash(_('Logo deleted'), 'success')
     logger.info("Logo of %s deleted by %s", self.event, session.user)
     return jsonify_data(content=None)
Ejemplo n.º 19
0
 def _process(self):
     self.event_new.logo = None
     self.event_new.logo_metadata = None
     flash(_('Logo deleted'), 'success')
     logger.info("Logo of %s deleted by %s", self.event_new, session.user)
     return jsonify_data(content=None)