Esempio n. 1
0
 def contribution_count(cls):
     from indico.modules.events.contributions.models.contributions import Contribution
     query = (db.select([
         db.func.count(Contribution.id)
     ]).where((Contribution.session_block_id == cls.id)
              & ~Contribution.is_deleted).correlate_except(Contribution))
     return db.column_property(query, deferred=True)
Esempio n. 2
0
    def _filter_list_entries(self, query, filters):
        criteria = []
        field_filters = filters.get('fields')
        item_filters = filters.get('items')
        extra_filters = filters.get('extra')

        if not (field_filters or item_filters or extra_filters):
            return query

        if field_filters:
            for contribution_type_id, field_values in field_filters.items():
                criteria.append(
                    Abstract.field_values.any(
                        db.and_(
                            AbstractFieldValue.contribution_field_id ==
                            contribution_type_id,
                            AbstractFieldValue.data.op('#>>')('{}').in_(
                                field_values))))

        if item_filters:
            static_filters = {
                'accepted_track': Abstract.accepted_track_id,
                'accepted_contrib_type': Abstract.accepted_contrib_type_id,
                'submitted_contrib_type': Abstract.submitted_contrib_type_id,
                'submitted_for_tracks': Abstract.submitted_for_tracks,
                'reviewed_for_tracks': Abstract.reviewed_for_tracks
            }
            for key, column in static_filters.items():
                ids = set(item_filters.get(key, ()))
                if not ids:
                    continue
                column_criteria = []
                if '_for_tracks' in key:
                    if None in ids:
                        column_criteria.append(~column.any())
                        ids.discard(None)
                    if ids:
                        column_criteria.append(column.any(Track.id.in_(ids)))
                else:
                    if None in ids:
                        column_criteria.append(column.is_(None))
                        ids.discard(None)
                    if ids:
                        column_criteria.append(column.in_(ids))
                criteria.append(db.or_(*column_criteria))
            if 'state' in item_filters:
                states = [
                    AbstractState(int(state))
                    for state in item_filters['state']
                ]
                criteria.append(Abstract.state.in_(states))
        if extra_filters:
            if extra_filters.get('multiple_tracks'):
                submitted_for_count = (db.select(
                    [db.func.count()]).as_scalar().where(
                        Abstract.submitted_for_tracks.prop.primaryjoin))
                criteria.append(submitted_for_count > 1)
            if extra_filters.get('comments'):
                criteria.append(Abstract.submission_comment != '')
        return query.filter(db.and_(*criteria))
Esempio n. 3
0
 def subcontribution_count(cls):
     from indico.modules.events.contributions.models.subcontributions import SubContribution
     query = (db.select([
         db.func.count(SubContribution.id)
     ]).where((SubContribution.contribution_id == cls.id)
              & ~SubContribution.is_deleted).correlate_except(
                  SubContribution).scalar_subquery())
     return db.column_property(query, deferred=True)
Esempio n. 4
0
 def duration(cls):
     from indico.modules.events.contributions import Contribution
     from indico.modules.events.sessions.models.blocks import SessionBlock
     from indico.modules.events.timetable.models.breaks import Break
     return db.case(
         {
             TimetableEntryType.SESSION_BLOCK.value:
             db.select([SessionBlock.duration]).where(
                 SessionBlock.id == cls.session_block_id).correlate_except(
                     SessionBlock).as_scalar(),
             TimetableEntryType.CONTRIBUTION.value:
             db.select([Contribution.duration]).where(
                 Contribution.id == cls.contribution_id).correlate_except(
                     Contribution).as_scalar(),
             TimetableEntryType.BREAK.value:
             db.select([Break.duration]).where(Break.id == cls.break_id).
             correlate_except(Break).as_scalar(),
         },
         value=cls.type)
Esempio n. 5
0
    def _filter_list_entries(self, query, filters):
        criteria = []
        field_filters = filters.get('fields')
        item_filters = filters.get('items')
        extra_filters = filters.get('extra')

        if not (field_filters or item_filters or extra_filters):
            return query

        if field_filters:
            for contribution_type_id, field_values in field_filters.iteritems():
                criteria.append(Abstract.field_values.any(db.and_(
                    AbstractFieldValue.contribution_field_id == contribution_type_id,
                    AbstractFieldValue.data.op('#>>')('{}').in_(field_values)
                )))

        if item_filters:
            static_filters = {
                'accepted_track': Abstract.accepted_track_id,
                'accepted_contrib_type': Abstract.accepted_contrib_type_id,
                'submitted_contrib_type': Abstract.submitted_contrib_type_id,
                'submitted_for_tracks': Abstract.submitted_for_tracks,
                'reviewed_for_tracks': Abstract.reviewed_for_tracks
            }
            for key, column in static_filters.iteritems():
                ids = set(item_filters.get(key, ()))
                if not ids:
                    continue
                column_criteria = []
                if '_for_tracks' in key:
                    if None in ids:
                        column_criteria.append(~column.any())
                        ids.discard(None)
                    if ids:
                        column_criteria.append(column.any(Track.id.in_(ids)))
                else:
                    if None in ids:
                        column_criteria.append(column.is_(None))
                        ids.discard(None)
                    if ids:
                        column_criteria.append(column.in_(ids))
                criteria.append(db.or_(*column_criteria))
            if 'state' in item_filters:
                states = [AbstractState(int(state)) for state in item_filters['state']]
                criteria.append(Abstract.state.in_(states))
        if extra_filters:
            if extra_filters.get('multiple_tracks'):
                submitted_for_count = (db.select([db.func.count()])
                                       .as_scalar()
                                       .where(Abstract.submitted_for_tracks.prop.primaryjoin))
                criteria.append(submitted_for_count > 1)
            if extra_filters.get('comments'):
                criteria.append(Abstract.submission_comment != '')
        return query.filter(db.and_(*criteria))
Esempio n. 6
0
 def duration(cls):
     from indico.modules.events.contributions import Contribution
     from indico.modules.events.sessions.models.blocks import SessionBlock
     from indico.modules.events.timetable.models.breaks import Break
     return db.case({
         TimetableEntryType.SESSION_BLOCK.value:
             db.select([SessionBlock.duration])
             .where(SessionBlock.id == cls.session_block_id)
             .correlate_except(SessionBlock)
             .as_scalar(),
         TimetableEntryType.CONTRIBUTION.value:
             db.select([Contribution.duration])
             .where(Contribution.id == cls.contribution_id)
             .correlate_except(Contribution)
             .as_scalar(),
         TimetableEntryType.BREAK.value:
             db.select([Break.duration])
             .where(Break.id == cls.break_id)
             .correlate_except(Break)
             .as_scalar(),
     }, value=cls.type)
Esempio n. 7
0
 def attachment_count(cls):
     from indico.modules.attachments.models.attachments import Attachment
     from indico.modules.attachments.models.folders import AttachmentFolder
     query = (db.select([db.func.count(Attachment.id)])
              .select_from(db.join(Attachment, AttachmentFolder, Attachment.folder_id == AttachmentFolder.id))
              .where(db.and_(
                  ~AttachmentFolder.is_deleted,
                  ~Attachment.is_deleted,
                  (getattr(AttachmentFolder, cls.ATTACHMENT_FOLDER_ID_COLUMN) == cls.id)
              ))
              .correlate_except(AttachmentFolder, Attachment))
     return db.column_property(query, deferred=True)
Esempio n. 8
0
def _make_attachment_count_column_property(cls):
    from indico.modules.attachments.models.attachments import Attachment
    from indico.modules.attachments.models.folders import AttachmentFolder
    assert cls.attachment_count is None
    query = (db.select([db.func.count(Attachment.id)])
             .select_from(db.join(Attachment, AttachmentFolder, Attachment.folder_id == AttachmentFolder.id))
             .where(db.and_(
                 ~AttachmentFolder.is_deleted,
                 ~Attachment.is_deleted,
                 (getattr(AttachmentFolder, cls.ATTACHMENT_FOLDER_ID_COLUMN) == cls.id)
             ))
             .correlate_except(AttachmentFolder, Attachment))
    cls.attachment_count = db.column_property(query, deferred=True)
Esempio n. 9
0
 def _paper_last_revision(cls):
     # Incompatible with joinedload
     subquery = (db.select([db.func.max(PaperRevision.submitted_dt)])
                 .where(PaperRevision._contribution_id == cls.id)
                 .correlate_except(PaperRevision)
                 .as_scalar())
     return db.relationship(
         'PaperRevision',
         uselist=False,
         lazy=True,
         viewonly=True,
         primaryjoin=db.and_(PaperRevision._contribution_id == cls.id, PaperRevision.submitted_dt == subquery)
     )
Esempio n. 10
0
 def _paper_last_revision(cls):
     # Incompatible with joinedload
     subquery = (db.select([db.func.max(PaperRevision.submitted_dt)])
                 .where(PaperRevision._contribution_id == cls.id)
                 .correlate_except(PaperRevision)
                 .as_scalar())
     return db.relationship(
         'PaperRevision',
         uselist=False,
         lazy=True,
         viewonly=True,
         primaryjoin=db.and_(PaperRevision._contribution_id == cls.id, PaperRevision.submitted_dt == subquery)
     )
Esempio n. 11
0
 def _paper_revision_count(cls):
     query = (db.select([db.func.count(PaperRevision.id)])
              .where(PaperRevision._contribution_id == cls.id)
              .correlate_except(PaperRevision))
     return db.column_property(query, deferred=True)
Esempio n. 12
0
 def subcontribution_count(cls):
     from indico.modules.events.contributions.models.subcontributions import SubContribution
     query = (db.select([db.func.count(SubContribution.id)])
              .where((SubContribution.contribution_id == cls.id) & ~SubContribution.is_deleted)
              .correlate_except(SubContribution))
     return db.column_property(query, deferred=True)
Esempio n. 13
0
    def _filter_list_entries(self, query, filters):
        criteria = []
        field_filters = filters.get('fields')
        item_filters = filters.get('items')
        extra_filters = filters.get('extra')

        if not (field_filters or item_filters or extra_filters):
            return query

        if field_filters:
            for field_id, field_values in field_filters.items():
                field_values = set(field_values)

                # Support filtering by 'No selection' in single-choice abstract fields.
                field_criteria = []
                if None in field_values:
                    # Handle the case when there is no value in
                    # 'Abstract.field_values' matching the 'field_id'.
                    # This can happen when custom fields are added after the
                    # abstract had already been submitted or when submitting as a regular
                    # user who cannot see a field that is only editable by managers.
                    # In these cases, we still want to show the abstracts.
                    field_values.discard(None)
                    field_criteria += [
                        ~Abstract.field_values.any(
                            AbstractFieldValue.contribution_field_id ==
                            field_id),
                        Abstract.field_values.any(
                            db.and_(
                                AbstractFieldValue.contribution_field_id ==
                                field_id,
                                AbstractFieldValue.data.op('#>>')('{}').is_(
                                    None)))
                    ]
                if field_values:
                    field_criteria.append(
                        Abstract.field_values.any(
                            db.and_(
                                AbstractFieldValue.contribution_field_id ==
                                field_id,
                                AbstractFieldValue.data.op('#>>')('{}').in_(
                                    field_values))))

                criteria.append(db.or_(*field_criteria))

        if item_filters:
            static_filters = {
                'accepted_track': Abstract.accepted_track_id,
                'accepted_contrib_type': Abstract.accepted_contrib_type_id,
                'submitted_contrib_type': Abstract.submitted_contrib_type_id,
                'submitted_for_tracks': Abstract.submitted_for_tracks,
                'reviewed_for_tracks': Abstract.reviewed_for_tracks
            }
            for key, column in static_filters.items():
                ids = set(item_filters.get(key, ()))
                if not ids:
                    continue
                column_criteria = []
                if '_for_tracks' in key:
                    if None in ids:
                        column_criteria.append(~column.any())
                        ids.discard(None)
                    if ids:
                        column_criteria.append(column.any(Track.id.in_(ids)))
                else:
                    if None in ids:
                        column_criteria.append(column.is_(None))
                        ids.discard(None)
                    if ids:
                        column_criteria.append(column.in_(ids))
                criteria.append(db.or_(*column_criteria))
            if 'state' in item_filters:
                states = [
                    AbstractState(int(state))
                    for state in item_filters['state']
                ]
                criteria.append(Abstract.state.in_(states))
        if extra_filters:
            if extra_filters.get('multiple_tracks'):
                submitted_for_count = (db.select(
                    [db.func.count()]).scalar_subquery().where(
                        Abstract.submitted_for_tracks.prop.primaryjoin))
                criteria.append(submitted_for_count > 1)
            if extra_filters.get('comments'):
                criteria.append(Abstract.submission_comment != '')
        return query.filter(db.and_(*criteria))
Esempio n. 14
0
 def _paper_revision_count(cls):
     query = (db.select([db.func.count(PaperRevision.id)])
              .where(PaperRevision._contribution_id == cls.id)
              .correlate_except(PaperRevision))
     return db.column_property(query, deferred=True)