Beispiel #1
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))
Beispiel #2
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))
Beispiel #3
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))
Beispiel #4
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))
Beispiel #5
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))
Beispiel #6
0
 def run(self, new_event, cloners, shared_data):
     from indico.modules.events.layout.models.images import ImageFile
     for old_image in self._find_images():
         new_image = ImageFile(filename=old_image.filename, content_type=old_image.content_type)
         new_event.layout_images.append(new_image)
         with old_image.open() as fd:
             new_image.save(fd)
         db.session.flush()
Beispiel #7
0
 def clone(self, new_event, options):
     from indico.modules.events.layout.models.images import ImageFile
     if 'images' not in options:
         return
     for old_image in get_images_for_event(self.event):
         new_image = ImageFile(event_id=new_event.id,
                               filename=old_image.filename,
                               content_type=old_image.content_type)
         with old_image.open() as fd:
             new_image.save(fd)
         db.session.add(new_image)
         db.session.flush()
         logger.info('Added image during event cloning: {}'.format(new_image))
Beispiel #8
0
 def clone(self, new_event, options):
     from indico.modules.events.layout.models.images import ImageFile
     if 'images' not in options:
         return
     for old_image in get_images_for_event(self.event):
         new_image = ImageFile(event_id=new_event.id,
                               filename=old_image.filename,
                               content_type=old_image.content_type)
         with old_image.open() as fd:
             new_image.save(fd)
         db.session.add(new_image)
         db.session.flush()
         logger.info(
             'Added image during event cloning: {}'.format(new_image))
Beispiel #9
0
    def migrate(self):
        for picture in self._iter_pictures(self.conf):
            local_file = picture._localFile
            content_type = mimetypes.guess_type(local_file.fileName)[0] or 'application/octet-stream'
            storage_backend, storage_path, size, md5 = self._get_local_file_info(local_file)

            if storage_path is None:
                self.print_warning('%[yellow][{}]%[reset] -> %[red!]Not found in filesystem'.format(
                    local_file.id))
                continue

            filename = secure_filename(convert_to_unicode(local_file.fileName), 'image')
            image = ImageFile(event_id=self.event.id,
                              filename=filename,
                              content_type=content_type,
                              created_dt=now_utc(),
                              size=size,
                              md5=md5,
                              storage_backend=storage_backend,
                              storage_file_id=storage_path)

            map_entry = LegacyImageMapping(event_id=self.event.id, legacy_image_id=local_file.id, image=image)
            db.session.add(image)
            db.session.add(map_entry)

            if not self.quiet:
                self.print_success('%[cyan][{}]%[reset] -> %[blue!]{}'.format(local_file.id, image))
Beispiel #10
0
    def migrate_event_images(self):
        self.print_step('migrating event images')
        for event, picture in committing_iterator(self._iter_pictures()):
            local_file = picture._localFile
            content_type = mimetypes.guess_type(local_file.fileName)[0] or 'application/octet-stream'
            storage_backend, storage_path, size = self._get_local_file_info(local_file)

            if storage_path is None:
                self.print_warning(cformat('%{yellow}[{}]%{reset} -> %{red!}Not found in filesystem').format(
                    local_file.id), event_id=event.id)
                continue

            filename = secure_filename(convert_to_unicode(local_file.fileName), 'image')
            image = ImageFile(event_id=event.id,
                              filename=filename,
                              content_type=content_type,
                              created_dt=now_utc(),
                              size=size,
                              storage_backend=storage_backend,
                              storage_file_id=storage_path)

            db.session.add(image)
            db.session.flush()

            map_entry = LegacyImageMapping(event_id=event.id, legacy_image_id=local_file.id, image_id=image.id)

            db.session.add(map_entry)

            if not self.quiet:
                self.print_success(cformat('%{cyan}[{}]%{reset} -> %{blue!}{}').format(local_file.id, image),
                                   event_id=event.id)
Beispiel #11
0
def _rewrite_event_asset_url(event, url):
    """Rewrite URLs of assets such as event images.

    Only assets contained within the event will be taken into account
    """
    scheme, netloc, path, qs, anchor = urlsplit(url)
    netloc = netloc or current_app.config['SERVER_NAME']
    scheme = scheme or 'https'

    # internal URLs (same server)
    if netloc == current_app.config['SERVER_NAME']:
        # this piece of Flask magic finds the endpoint that corresponds to
        # the URL and checks that it points to an image belonging to this event
        endpoint_info = endpoint_for_url(path)
        if endpoint_info:
            endpoint, data = endpoint_info
            if endpoint == 'event_images.image_display' and int(
                    data['confId']) == event.id:
                image_file = ImageFile.get(data['image_id'])
                if image_file and image_file.event == event:
                    return f'images/{image_file.id}-{image_file.filename}', image_file
    # if the URL is not internal or just not an image,
    # we embed the contents using a data URI
    data_uri = _create_data_uri(urlunsplit((scheme, netloc, path, qs, '')),
                                urlsplit(path)[-1])
    return data_uri, None
Beispiel #12
0
def _rewrite_event_asset_url(event, url):
    """Rewrite URLs of assets such as event images.

    Only assets contained within the event will be taken into account
    """
    scheme, netloc, path, qs, anchor = urlparse.urlsplit(url)
    netloc = netloc or current_app.config['SERVER_NAME']
    scheme = scheme or 'https'

    # internal URLs (same server)
    if netloc == current_app.config['SERVER_NAME']:
        # this piece of Flask magic finds the endpoint that corresponds to
        # the URL and checks that it points to an image belonging to this event
        endpoint_info = endpoint_for_url(path)
        if endpoint_info:
            endpoint, data = endpoint_info
            if endpoint == 'event_images.image_display' and int(data['confId']) == event.id:
                image_file = ImageFile.get(data['image_id'])
                if image_file and image_file.event == event:
                    return 'images/{}-{}'.format(image_file.id, image_file.filename), image_file
    # if the URL is not internal or just not an image,
    # we embed the contents using a data URI
    data_uri = _create_data_uri(urlparse.urlunsplit((scheme, netloc, path, qs, '')), urlparse.urlsplit(path)[-1])
    return data_uri, None
Beispiel #13
0
 def _checkParams(self, params):
     RHManageImagesBase._checkParams(self, params)
     self.image = ImageFile.find_first(id=request.view_args['image_id'], event_id=self._conf.getId())
     if not self.image:
         raise NotFound
Beispiel #14
0
 def _checkParams(self, params):
     RHConferenceBaseDisplay._checkParams(self, params)
     image_id = request.view_args["image_id"]
     self.image = ImageFile.get_one(image_id)
Beispiel #15
0
 def _find_images(self):
     from indico.modules.events.layout.models.images import ImageFile
     return ImageFile.find(event_id=self.event.id)
Beispiel #16
0
def get_images_for_event(event):
    """Return all non-deleted images uploaded to a specific event
    """
    return ImageFile.find_all(event_id=event.id)
Beispiel #17
0
 def _process_args(self):
     RHConferenceBaseDisplay._process_args(self)
     image_id = request.view_args['image_id']
     self.image = ImageFile.get_one(image_id)
Beispiel #18
0
 def _checkParams(self, params):
     RHConferenceBaseDisplay._checkParams(self, params)
     image_id = request.view_args['image_id']
     self.image = ImageFile.get_one(image_id)
Beispiel #19
0
 def has_data(self):
     return ImageFile.has_rows()
Beispiel #20
0
 def _process_args(self):
     RHDisplayEventBase._process_args(self)
     image_id = request.view_args['image_id']
     self.image = ImageFile.get_or_404(image_id)
Beispiel #21
0
 def _checkParams(self, params):
     RHManageImagesBase._checkParams(self, params)
     self.image = ImageFile.find_first(id=request.view_args['image_id'],
                                       event_id=self._conf.getId())
     if not self.image:
         raise NotFound
Beispiel #22
0
 def _process_args(self):
     RHDisplayEventBase._process_args(self)
     image_id = request.view_args['image_id']
     self.image = ImageFile.get_one(image_id)
Beispiel #23
0
def get_images_for_event(event):
    """Return all non-deleted images uploaded to a specific event
    """
    return ImageFile.find_all(event_id=event.id)
Beispiel #24
0
 def has_data(self):
     return ImageFile.has_rows()
Beispiel #25
0
 def _find_images(self):
     from indico.modules.events.layout.models.images import ImageFile
     return ImageFile.find(event_id=self.event.id)