示例#1
0
def add_abstract_files(abstract, files, log_action=True):
    if not files:
        return
    for f in files:
        filename = secure_filename(f.filename, 'attachment')
        content_type = mimetypes.guess_type(
            f.filename)[0] or f.mimetype or 'application/octet-stream'
        abstract_file = AbstractFile(filename=filename,
                                     content_type=content_type,
                                     abstract=abstract)
        abstract_file.save(f.stream)
        db.session.flush()
    if log_action:
        logger.info('%d abstract file(s) added to %s by %s', len(files),
                    abstract, session.user)
        num = len(files)
        if num == 1:
            msg = 'Added file to abstract {}'.format(abstract.verbose_title)
        else:
            msg = 'Added {} files to abstract {}'.format(
                num, abstract.verbose_title)
        abstract.event.log(
            EventLogRealm.reviewing,
            EventLogKind.positive,
            'Abstracts',
            msg,
            session.user,
            data={'Files': ', '.join(f.filename for f in abstract.files)})
示例#2
0
def add_abstract_files(abstract, files, log_action=True):
    if not files:
        return
    for f in files:
        filename = secure_filename(f.filename, 'attachment')
        content_type = mimetypes.guess_type(f.filename)[0] or f.mimetype or 'application/octet-stream'
        abstract_file = AbstractFile(filename=filename, content_type=content_type, abstract=abstract)
        abstract_file.save(f.stream)
        db.session.flush()
    if log_action:
        logger.info('%d abstract file(s) added to %s by %s', len(files), abstract, session.user)
        num = len(files)
        if num == 1:
            msg = 'Added file to abstract {}'.format(abstract.verbose_title)
        else:
            msg = 'Added {} files to abstract {}'.format(num, abstract.verbose_title)
        abstract.event.log(EventLogRealm.reviewing, EventLogKind.positive, 'Abstracts', msg, session.user,
                           data={'Files': ', '.join(f.filename for f in abstract.files)})
示例#3
0
 def _process_args(self):
     RHAbstractBase._process_args(self)
     self.abstract_file = AbstractFile.get_one(request.view_args['file_id'])
示例#4
0
 def _checkParams(self, params):
     RHAbstractBase._checkParams(self, params)
     self.abstract_file = AbstractFile.get_one(request.view_args['file_id'])
示例#5
0
 def _process_args(self):
     RHAbstractBase._process_args(self)
     self.abstract_file = AbstractFile.get_one(request.view_args['file_id'])
示例#6
0
    def _migrate_abstract(self, old_abstract):
        submitter = self.user_from_legacy(old_abstract._submitter._user,
                                          system_user=True)
        submitted_dt = old_abstract._submissionDate
        modified_dt = (old_abstract._modificationDate if
                       (submitted_dt - old_abstract._modificationDate) >
                       timedelta(seconds=10) else None)
        description = getattr(old_abstract, '_fields', {}).get('content', '')
        description = convert_to_unicode(
            getattr(description, 'value',
                    description))  # str or AbstractFieldContent

        type_ = old_abstract._contribTypes[0]
        type_id = None
        try:
            type_id = self.event_ns.legacy_contribution_type_map[
                type_].id if type_ else None
        except KeyError:
            self.print_warning(
                'Abstract {} - invalid contrib type {}, setting to None'.
                format(old_abstract._id,
                       convert_to_unicode(getattr(type_, '_name',
                                                  str(type_)))))

        abstract = Abstract(friendly_id=int(old_abstract._id),
                            title=convert_to_unicode(old_abstract._title),
                            description=description,
                            submitter=submitter,
                            submitted_dt=submitted_dt,
                            submitted_contrib_type_id=type_id,
                            submission_comment=convert_to_unicode(
                                old_abstract._comments),
                            modified_dt=modified_dt)
        self.print_info('%[white!]Abstract %[cyan]{}%[reset]: {}'.format(
            abstract.friendly_id, abstract.title))
        self.event.abstracts.append(abstract)
        self.event_ns.abstract_map[old_abstract] = abstract

        accepted_type_id = None
        accepted_track_id = None

        old_contribution = getattr(old_abstract, '_contribution', None)
        if old_contribution:
            assert old_contribution.__class__.__name__ == 'AcceptedContribution'
            if old_abstract._currentStatus.__class__.__name__ == 'AbstractStatusAccepted':
                old_contrib_type = old_abstract._currentStatus._contribType
                try:
                    accepted_type_id = (
                        self.event_ns.
                        legacy_contribution_type_map[old_contrib_type].id
                        if old_contrib_type else None)
                except KeyError:
                    self.print_warning(
                        '%[yellow!]Contribution {} - invalid contrib type {}, setting to None'
                        .format(old_contribution.id,
                                convert_to_unicode(old_contrib_type._name)))

                old_accepted_track = old_abstract._currentStatus._track
                accepted_track_id = int(
                    old_accepted_track.id) if old_accepted_track else None

        if old_contribution and old_contribution.id is not None:
            self.event_ns.legacy_contribution_abstracts[
                old_contribution] = abstract

        try:
            accepted_track = (
                self.event_ns.track_map_by_id.get(accepted_track_id)
                if accepted_track_id is not None else None)
        except KeyError:
            self.print_error(
                '%[yellow!]Abstract #{} accepted in invalid track #{}'.format(
                    abstract.friendly_id, accepted_track_id))
            accepted_track = None

        # state
        old_state = old_abstract._currentStatus
        old_state_name = old_state.__class__.__name__
        self.event_ns.old_abstract_state_map[abstract] = old_state
        abstract.state = self.STATE_MAP[old_state_name]

        if abstract.state == AbstractState.accepted:
            abstract.accepted_contrib_type_id = accepted_type_id
            abstract.accepted_track = accepted_track

        if abstract.state in self.JUDGED_STATES:
            abstract.judge = self.user_from_legacy(old_state._responsible,
                                                   system_user=True)
            abstract.judgment_dt = as_utc(old_state._date)

        # files
        for old_attachment in getattr(old_abstract, '_attachments',
                                      {}).itervalues():
            storage_backend, storage_path, size, md5 = self._get_local_file_info(
                old_attachment)
            if storage_path is None:
                self.print_error(
                    '%[red!]File not found on disk; skipping it [{}]'.format(
                        convert_to_unicode(old_attachment.fileName)))
                continue
            content_type = mimetypes.guess_type(
                old_attachment.fileName)[0] or 'application/octet-stream'
            filename = secure_filename(
                convert_to_unicode(old_attachment.fileName), 'attachment')
            attachment = AbstractFile(filename=filename,
                                      content_type=content_type,
                                      size=size,
                                      md5=md5,
                                      storage_backend=storage_backend,
                                      storage_file_id=storage_path)
            abstract.files.append(attachment)

        # internal comments
        for old_comment in old_abstract._intComments:
            comment = AbstractComment(
                user=self.user_from_legacy(old_comment._responsible,
                                           system_user=True),
                text=convert_to_unicode(old_comment._content),
                created_dt=old_comment._creationDate,
                modified_dt=old_comment._modificationDate)
            abstract.comments.append(comment)

        # tracks
        reallocated = set(r._track for r in getattr(
            old_abstract, '_trackReallocations', {}).itervalues())
        for old_track in old_abstract._tracks.values():
            abstract.reviewed_for_tracks.add(
                self.event_ns.track_map.get(old_track))
            if old_track not in reallocated:
                abstract.submitted_for_tracks.add(
                    self.event_ns.track_map.get(old_track))

        # reviews/judgments
        self._migrate_abstract_reviews(abstract, old_abstract)
        # persons
        self._migrate_abstract_persons(abstract, old_abstract)
        # email log
        self._migrate_abstract_email_log(abstract, old_abstract)

        # contribution/abstract fields
        abstract.field_values = list(
            self._migrate_abstract_field_values(old_abstract))
        return abstract
示例#7
0
    def _migrate_abstracts(self):
        old_by_id = {oa.friendly_id: oa for oa in self.event.old_abstracts}
        abstract_map = {}
        old_abstract_state_map = {}
        as_duplicate_reviews = set()
        for zodb_abstract in self.amgr._abstracts.itervalues():
            old_abstract = old_by_id[int(zodb_abstract._id)]
            submitter = self._user_from_legacy(zodb_abstract._submitter._user,
                                               janitor=True)
            submitted_dt = zodb_abstract._submissionDate
            modified_dt = (zodb_abstract._modificationDate if
                           (submitted_dt - zodb_abstract._modificationDate) >
                           timedelta(seconds=10) else None)
            try:
                accepted_track = (
                    self.track_map_by_id[old_abstract.accepted_track_id]
                    if old_abstract.accepted_track_id is not None else None)
            except KeyError:
                self.importer.print_error(cformat(
                    '%{yellow!}Abstract #{} accepted in invalid track #{}'
                ).format(old_abstract.friendly_id,
                         old_abstract.accepted_track_id),
                                          event_id=self.event.id)
                accepted_track = None
            abstract = Abstract(id=old_abstract.id,
                                friendly_id=old_abstract.friendly_id,
                                title=convert_to_unicode(zodb_abstract._title),
                                description=old_abstract.description,
                                submitter=submitter,
                                submitted_dt=submitted_dt,
                                submitted_contrib_type_id=old_abstract.type_id,
                                submission_comment=convert_to_unicode(
                                    zodb_abstract._comments),
                                modified_dt=modified_dt)
            self.importer.print_info(
                cformat('%{white!}Abstract:%{reset} {}').format(
                    abstract.title))
            self.event.abstracts.append(abstract)
            abstract_map[zodb_abstract] = abstract

            # files
            for old_attachment in getattr(zodb_abstract, '_attachments',
                                          {}).itervalues():
                storage_backend, storage_path, size = self.importer._get_local_file_info(
                    old_attachment)
                if storage_path is None:
                    self.importer.print_error(cformat(
                        '%{red!}File not found on disk; skipping it [{}]'
                    ).format(convert_to_unicode(old_attachment.fileName)),
                                              event_id=self.event.id)
                    continue
                content_type = mimetypes.guess_type(
                    old_attachment.fileName)[0] or 'application/octet-stream'
                filename = secure_filename(
                    convert_to_unicode(old_attachment.fileName), 'attachment')
                attachment = AbstractFile(filename=filename,
                                          content_type=content_type,
                                          size=size,
                                          storage_backend=storage_backend,
                                          storage_file_id=storage_path)
                abstract.files.append(attachment)

            # internal comments
            for old_comment in zodb_abstract._intComments:
                comment = AbstractComment(
                    user=self._user_from_legacy(old_comment._responsible),
                    text=convert_to_unicode(old_comment._content),
                    created_dt=old_comment._creationDate,
                    modified_dt=old_comment._modificationDate)
                abstract.comments.append(comment)

            # state
            old_state = zodb_abstract._currentStatus
            old_state_name = old_state.__class__.__name__
            old_abstract_state_map[abstract] = old_state
            abstract.state = self.STATE_MAP[old_state_name]
            if abstract.state == AbstractState.accepted:
                abstract.accepted_contrib_type_id = old_abstract.accepted_type_id
                abstract.accepted_track = accepted_track

            if abstract.state in self.JUDGED_STATES:
                abstract.judge = self._user_from_legacy(old_state._responsible,
                                                        janitor=True)
                abstract.judgment_dt = as_utc(old_state._date)

            # tracks
            reallocated = set(r._track for r in getattr(
                zodb_abstract, '_trackReallocations', {}).itervalues())
            for old_track in zodb_abstract._tracks.values():
                abstract.reviewed_for_tracks.add(self.track_map[old_track])
                if old_track not in reallocated:
                    abstract.submitted_for_tracks.add(
                        self.track_map[old_track])

            # judgments (reviews)
            self._migrate_abstract_reviews(abstract, zodb_abstract,
                                           old_abstract, as_duplicate_reviews)
            # persons
            self._migrate_abstract_persons(abstract, zodb_abstract)
            # email log
            self._migrate_abstract_email_log(abstract, zodb_abstract)

        # merges/duplicates
        for abstract in self.event.abstracts:
            old_state = old_abstract_state_map[abstract]
            if abstract.state == AbstractState.merged:
                abstract.merged_into = abstract_map[old_state._target]
            elif abstract.state == AbstractState.duplicate:
                abstract.duplicate_of = abstract_map[old_state._original]

        # mark-as-duplicate judgments
        for review, old_abstract in as_duplicate_reviews:
            try:
                review.proposed_related_abstract = abstract_map[old_abstract]
            except KeyError:
                self.importer.print_error(cformat(
                    '%{yellow!}Abstract #{} marked as duplicate of invalid abstract #{}'
                ).format(review.abstract.friendly_id, old_abstract._id),
                                          event_id=self.event.id)
                # delete the review; it would violate our CHECKs
                review.abstract = None
                # not needed but avoids some warnings about the object not in the session
                review.track = None
                review.user = None
示例#8
0
文件: abstract.py 项目: OmeGak/indico
 def _checkParams(self, params):
     RHAbstractBase._checkParams(self, params)
     self.abstract_file = AbstractFile.get_one(request.view_args['file_id'])