def create_paper_revision(paper, submitter, files): revision = PaperRevision(paper=paper, submitter=submitter) for f in files: filename = secure_filename(f.filename, 'paper') content_type = mimetypes.guess_type(f.filename)[0] or f.mimetype or 'application/octet-stream' pf = PaperFile(filename=filename, content_type=content_type, paper_revision=revision, _contribution=paper.contribution) pf.save(f.stream) db.session.flush() db.session.expire(revision._contribution, ['_paper_last_revision']) notify_paper_revision_submission(revision) logger.info('Paper revision %r submitted by %r', revision, session.user) paper.event.log(EventLogRealm.reviewing, EventLogKind.positive, 'Papers', "Paper revision {} submitted for contribution {} ({})" .format(revision.id, paper.contribution.title, paper.contribution.friendly_id), session.user) return revision
def create_paper_revision(paper, submitter, files): revision = PaperRevision(paper=paper, submitter=submitter) for f in files: filename = secure_client_filename(f.filename) content_type = mimetypes.guess_type(f.filename)[0] or f.mimetype or 'application/octet-stream' pf = PaperFile(filename=filename, content_type=content_type, paper_revision=revision, _contribution=paper.contribution) pf.save(f.stream) db.session.flush() db.session.expire(revision._contribution, ['_paper_last_revision']) notify_paper_revision_submission(revision) logger.info('Paper revision %r submitted by %r', revision, session.user) paper.event.log(EventLogRealm.reviewing, EventLogKind.positive, 'Papers', "Paper revision {} submitted for contribution {} ({})" .format(revision.id, paper.contribution.title, paper.contribution.friendly_id), session.user) return revision
def _paper_file_from_legacy(lpf): return PaperFile(filename=lpf.filename, content_type=lpf.content_type, size=lpf.size, storage_backend=lpf.storage_backend, storage_file_id=lpf.storage_file_id, created_dt=_to_utc(lpf.created_dt), _contribution=lpf.contribution)
def _migrate_resource(self, contribution, revision, resource, created_dt, ignored_checksums): storage_backend, storage_path, size, md5 = self._get_local_file_info( resource, force_access=True) content_type = mimetypes.guess_type( resource.fileName)[0] or 'application/octet-stream' if not storage_path: self.print_error("%[red!]File not accessible [{}]".format( convert_to_unicode(resource.fileName))) return paper_file = PaperFile(filename=resource.fileName, content_type=content_type, size=size, md5=md5, storage_backend=storage_backend, storage_file_id=storage_path, created_dt=created_dt) # check whether the same file has been uploaded to a subsequent revision if md5: self.checksum_map[md5] = paper_file collision = self.file_checksums.get(md5) if collision: ignored_checksums.add(md5) self.print_warning( '%[yellow!]File {} (rev. {}) already in revision {}'. format(convert_to_unicode(resource.fileName), revision.id if revision else None, collision.id)) return else: self.file_checksums[md5] = revision else: self.print_error( "%[red!]File not accessible; can't MD5 it [{}]".format( convert_to_unicode(paper_file.filename))) paper_file._contribution = contribution paper_file.paper_revision = revision db.session.add(paper_file) return paper_file
def _migrate_resource(self, old_contrib, contribution, revision, resource, created_dt, ignored_checksums): storage_backend, storage_path, size = self._get_local_file_info( resource) content_type = mimetypes.guess_type( resource.fileName)[0] or 'application/octet-stream' paper_file = PaperFile(filename=resource.fileName, content_type=content_type, size=size, storage_backend=storage_backend, storage_file_id=storage_path, created_dt=created_dt, paper_revision=revision) # check whether the same file has been uploaded to a subsequent revision try: with paper_file.open() as f: checksum = crc32(f.read()) self.checksum_map[checksum] = paper_file collision = self.file_checksums.get(checksum) if collision: ignored_checksums.add(checksum) self.print_warning( '%[yellow!]File {} (rev. {}) already in revision {}'. format(resource.filename, revision.id if revision else None, collision.id)) return else: self.file_checksums[checksum] = revision except (RuntimeError, StorageError): self.print_error( "%[red!]File not accessible; can't CRC it [{}]".format( convert_to_unicode(paper_file.filename))) paper_file._contribution = contribution db.session.add(paper_file) return paper_file
def _process_args(self): RHPaperBase._process_args(self) self.file = PaperFile.get_or_404(request.view_args['file_id'])
def _checkParams(self, params): RHPaperBase._checkParams(self, params) self.file = PaperFile.get_one(request.view_args['file_id'])
def _process_args(self): RHPaperBase._process_args(self) self.file = PaperFile.get_one(request.view_args['file_id'])