Esempio n. 1
0
    def _build_event_api_data(self, event):
        can_manage = self.user is not None and event.can_manage(self.user)
        data = self._build_event_api_data_base(event)
        data.update({
            '_fossil': self.fossils_mapping['event'].get(self._detail_level),
            'categoryId': event.category_id,
            'category': event.category.title,
            'note': build_note_api_data(event.note),
            'roomFullname': event.room_name,
            'url': url_for('event.conferenceDisplay', confId=event.id, _external=True),
            'modificationDate': self._serialize_date(event.as_legacy.getModificationDate()),
            'creationDate': self._serialize_date(event.created_dt),
            'creator': self._serialize_person(event.creator, person_type='Avatar', can_manage=can_manage),
            'hasAnyProtection': event.effective_protection_mode != ProtectionMode.public,
            'roomMapURL': event.room.map_url if event.room else None,
            'folders': build_folders_api_data(event),
            'chairs': self._serialize_persons(event.person_links, person_type='ConferenceChair', can_manage=can_manage),
            'material': build_material_legacy_api_data(event) + filter(None, [build_note_legacy_api_data(event.note)])
        })

        event_category_path = event.category.chain
        visibility = {'id': '', 'name': 'Everywhere'}
        if event.visibility is None:
            pass  # keep default
        elif event.visibility == 0:
            visibility['name'] = 'Nowhere'
        elif event.visibility:
            try:
                path_segment = event_category_path[-event.visibility]
            except IndexError:
                pass
            else:
                visibility['id'] = path_segment['id']
                visibility['name'] = path_segment['title']
        data['visibility'] = visibility

        if can_manage:
            data['allowed'] = self._serialize_access_list(event)
        if self._detail_level in {'contributions', 'subcontributions'}:
            data['contributions'] = []
            for contribution in event.contributions:
                include_subcontribs = self._detail_level == 'subcontributions'
                serialized_contrib = self._serialize_contribution(contribution, include_subcontribs)
                data['contributions'].append(serialized_contrib)
        elif self._detail_level == 'sessions':
            # Contributions without a session
            data['contributions'] = []
            for contribution in event.contributions:
                if not contribution.session:
                    serialized_contrib = self._serialize_contribution(contribution)
                    data['contributions'].append(serialized_contrib)

            data['sessions'] = []
            for session_ in event.sessions:
                data['sessions'].extend(self._build_session_api_data(session_))
        if self._occurrences:
            data['occurrences'] = fossilize(self._calculate_occurrences(event, self._fromDT, self._toDT,
                                            pytz.timezone(self._serverTZ)),
                                            {Period: IPeriodFossil}, tz=self._tz, naiveTZ=self._serverTZ)
        return data
Esempio n. 2
0
    def _build_event_api_data(self, event):
        can_manage = self.user is not None and event.can_manage(self.user)
        data = self._build_event_api_data_base(event)
        data.update({
            '_fossil': self.fossils_mapping['event'].get(self._detail_level),
            'categoryId': event.category_id,
            'category': event.category.title,
            'note': build_note_api_data(event.note),
            'roomFullname': event.room_name,
            'url': url_for('event.conferenceDisplay', confId=event.id, _external=True),
            'modificationDate': self._serialize_date(event.as_legacy.getModificationDate()),
            'creationDate': self._serialize_date(event.created_dt),
            'creator': self._serialize_person(event.creator, person_type='Avatar', can_manage=can_manage),
            'hasAnyProtection': event.effective_protection_mode != ProtectionMode.public,
            'roomMapURL': event.room.map_url if event.room else None,
            'folders': build_folders_api_data(event),
            'chairs': self._serialize_persons(event.person_links, person_type='ConferenceChair', can_manage=can_manage),
            'material': build_material_legacy_api_data(event) + filter(None, [build_note_legacy_api_data(event.note)])
        })

        event_category_path = event.category.chain
        visibility = {'id': '', 'name': 'Everywhere'}
        if event.visibility is None:
            pass  # keep default
        elif event.visibility == 0:
            visibility['name'] = 'Nowhere'
        elif event.visibility:
            try:
                path_segment = event_category_path[-event.visibility]
            except IndexError:
                pass
            else:
                visibility['id'] = path_segment['id']
                visibility['name'] = path_segment['title']
        data['visibility'] = visibility

        if can_manage:
            data['allowed'] = self._serialize_access_list(event)
        if self._detail_level in {'contributions', 'subcontributions'}:
            data['contributions'] = []
            for contribution in event.contributions:
                include_subcontribs = self._detail_level == 'subcontributions'
                serialized_contrib = self._serialize_contribution(contribution, include_subcontribs)
                data['contributions'].append(serialized_contrib)
        elif self._detail_level == 'sessions':
            # Contributions without a session
            data['contributions'] = []
            for contribution in event.contributions:
                if not contribution.session:
                    serialized_contrib = self._serialize_contribution(contribution)
                    data['contributions'].append(serialized_contrib)

            data['sessions'] = []
            for session_ in event.sessions:
                data['sessions'].extend(self._build_session_api_data(session_))
        if self._occurrences:
            data['occurrences'] = fossilize(self._calculate_occurrences(event, self._fromDT, self._toDT,
                                            pytz.timezone(self._serverTZ)),
                                            {Period: IPeriodFossil}, tz=self._tz, naiveTZ=self._serverTZ)
        return data
Esempio n. 3
0
    def _build_event_api_data(self, event):
        can_manage = self.user is not None and event.can_manage(self.user)
        data = self._build_event_api_data_base(event)
        data.update({
            '_fossil': self.fossils_mapping['event'].get(self._detail_level),
            'categoryId': unicode(event.category_id),
            'category': event.category.getTitle(),
            'note': build_note_api_data(event.note),
            'roomFullname': event.room_name,
            'url': url_for('event.conferenceDisplay', confId=event.id, _external=True),
            'modificationDate': self._serialize_date(event.as_legacy.getModificationDate()),
            'creationDate': self._serialize_date(event.as_legacy.getCreationDate()),
            'creator': self._serialize_person(event.creator, person_type='Avatar', can_manage=can_manage),
            'hasAnyProtection': event.as_legacy.hasAnyProtection(),
            'roomMapURL': event.room.map_url if event.room else None,
            'visibility': Conversion.visibility(event.as_legacy),
            'folders': build_folders_api_data(event),
            'chairs': self._serialize_persons(event.person_links, person_type='ConferenceChair', can_manage=can_manage),
            'material': build_material_legacy_api_data(event) + [build_note_legacy_api_data(event.note)]
        })
        if can_manage:
            data['allowed'] = self._serialize_access_list(event)
        if self._detail_level in {'contributions', 'subcontributions'}:
            data['contributions'] = []
            for contribution in event.contributions:
                include_subcontribs = self._detail_level == 'subcontributions'
                serialized_contrib = self._serialize_contribution(contribution, include_subcontribs)
                data['contributions'].append(serialized_contrib)
        elif self._detail_level == 'sessions':
            # Contributions without a session
            data['contributions'] = []
            for contribution in event.contributions:
                if not contribution.session:
                    serialized_contrib = self._serialize_contribution(contribution)
                    data['contributions'].append(serialized_contrib)

            data['sessions'] = []
            for session_ in event.sessions:
                data['sessions'].extend(self._build_session_api_data(session_))
        if self._occurrences:
            data['occurrences'] = fossilize(self._calculate_occurrences(event, self._fromDT, self._toDT,
                                            pytz.timezone(self._serverTZ)),
                                            {Period: IPeriodFossil}, tz=self._tz, naiveTZ=self._serverTZ)
        return data
Esempio n. 4
0
    def _build_event_api_data(self, event):
        can_manage = self.user is not None and event.can_manage(self.user)
        data = self._build_event_api_data_base(event)
        data.update({
            '_fossil':
            self.fossils_mapping['event'].get(self._detail_level),
            'categoryId':
            unicode(event.category_id),
            'category':
            event.category.getTitle(),
            'note':
            build_note_api_data(event.note),
            'roomFullname':
            event.room_name,
            'url':
            url_for('event.conferenceDisplay', confId=event.id,
                    _external=True),
            'modificationDate':
            self._serialize_date(event.as_legacy.getModificationDate()),
            'creationDate':
            self._serialize_date(event.as_legacy.getCreationDate()),
            'creator':
            self._serialize_person(event.creator,
                                   person_type='Avatar',
                                   can_manage=can_manage),
            'hasAnyProtection':
            event.as_legacy.hasAnyProtection(),
            'roomMapURL':
            event.room.map_url if event.room else None,
            'visibility':
            Conversion.visibility(event.as_legacy),
            'folders':
            build_folders_api_data(event),
            'chairs':
            self._serialize_persons(event.person_links,
                                    person_type='ConferenceChair',
                                    can_manage=can_manage),
            'material':
            build_material_legacy_api_data(event) +
            [build_note_legacy_api_data(event.note)]
        })
        if can_manage:
            data['allowed'] = self._serialize_access_list(event)
        if self._detail_level in {'contributions', 'subcontributions'}:
            data['contributions'] = []
            for contribution in event.contributions:
                include_subcontribs = self._detail_level == 'subcontributions'
                serialized_contrib = self._serialize_contribution(
                    contribution, include_subcontribs)
                data['contributions'].append(serialized_contrib)
        elif self._detail_level == 'sessions':
            # Contributions without a session
            data['contributions'] = []
            for contribution in event.contributions:
                if not contribution.session:
                    serialized_contrib = self._serialize_contribution(
                        contribution)
                    data['contributions'].append(serialized_contrib)

            data['sessions'] = []
            for session_ in event.sessions:
                data['sessions'].extend(self._build_session_api_data(session_))
        if self._occurrences:
            data['occurrences'] = fossilize(self._calculate_occurrences(
                event, self._fromDT, self._toDT,
                pytz.timezone(self._serverTZ)), {Period: IPeriodFossil},
                                            tz=self._tz,
                                            naiveTZ=self._serverTZ)
        return data
Esempio n. 5
0
File: api.py Progetto: vintas/indico
    def _build_event_api_data(self, event):
        can_manage = self.user is not None and event.can_manage(self.user)
        data = self._build_event_api_data_base(event)
        data.update({
            '_fossil':
            self.fossils_mapping['event'].get(self._detail_level),
            'categoryId':
            event.category_id,
            'category':
            event.category.title,
            'note':
            build_note_api_data(event.note),
            'roomFullname':
            event.room_name,
            'url':
            event.external_url,
            'creationDate':
            self._serialize_date(event.created_dt),
            'creator':
            self._serialize_person(event.creator,
                                   person_type='Avatar',
                                   can_manage=can_manage),
            'hasAnyProtection':
            event.effective_protection_mode != ProtectionMode.public,
            'roomMapURL':
            event.room.map_url if event.room else None,
            'folders':
            build_folders_api_data(event),
            'chairs':
            self._serialize_persons(event.person_links,
                                    person_type='ConferenceChair',
                                    can_manage=can_manage),
            'material':
            build_material_legacy_api_data(event) +
            filter(None, [build_note_legacy_api_data(event.note)]),
            'keywords':
            event.keywords,
        })

        event_category_path = event.category.chain
        visibility = {'id': '', 'name': 'Everywhere'}
        if event.visibility is None:
            pass  # keep default
        elif event.visibility == 0:
            visibility['name'] = 'Nowhere'
        elif event.visibility:
            try:
                path_segment = event_category_path[-event.visibility]
            except IndexError:
                pass
            else:
                visibility['id'] = path_segment['id']
                visibility['name'] = path_segment['title']
        data['visibility'] = visibility

        if can_manage:
            data['allowed'] = self._serialize_access_list(event)

        allow_details = contribution_settings.get(event,
                                                  'published') or can_manage
        if self._detail_level in {'contributions', 'subcontributions'
                                  } and allow_details:
            data['contributions'] = []
            for contribution in event.contributions:
                include_subcontribs = self._detail_level == 'subcontributions'
                serialized_contrib = self._serialize_contribution(
                    contribution, include_subcontribs)
                data['contributions'].append(serialized_contrib)
        elif self._detail_level == 'sessions' and allow_details:
            # Contributions without a session
            data['contributions'] = []
            for contribution in event.contributions:
                if not contribution.session:
                    serialized_contrib = self._serialize_contribution(
                        contribution)
                    data['contributions'].append(serialized_contrib)

            data['sessions'] = []
            for session_ in event.sessions:
                data['sessions'].extend(self._build_session_api_data(session_))
        if self._occurrences:
            data['occurrences'] = fossilize(self._calculate_occurrences(
                event, self._fromDT, self._toDT,
                pytz.timezone(config.DEFAULT_TIMEZONE)),
                                            {Period: IPeriodFossil},
                                            tz=self._tz,
                                            naiveTZ=config.DEFAULT_TIMEZONE)
        # check whether the plugins want to add/override any data
        for update in values_from_signal(
                signals.event.metadata_postprocess.send('http-api',
                                                        event=event,
                                                        data=data),
                as_list=True):
            data.update(update)
        return data
Esempio n. 6
0
 def _build_event_api_data(self, event):
     can_manage = self.user is not None and event.can_manage(self.user)
     data = self._build_event_api_data_base(event)
     material_data = build_material_legacy_api_data(event)
     if legacy_note_material := build_note_legacy_api_data(event.note):
         material_data.append(legacy_note_material)
Esempio n. 7
0
 def addLegacyMinutes(cls, result, _obj=None):
     from indico.modules.events.notes.util import build_note_legacy_api_data
     data = build_note_legacy_api_data(_obj.note)
     if data:
         result.append(data)
     return result
Esempio n. 8
0
File: api.py Progetto: OmeGak/indico
    def _build_event_api_data(self, event):
        can_manage = self.user is not None and event.can_manage(self.user)
        data = self._build_event_api_data_base(event)
        data.update(
            {
                "_fossil": self.fossils_mapping["event"].get(self._detail_level),
                "categoryId": event.category_id,
                "category": event.category.title,
                "note": build_note_api_data(event.note),
                "roomFullname": event.room_name,
                "url": url_for("event.conferenceDisplay", confId=event.id, _external=True),
                "modificationDate": self._serialize_date(event.as_legacy.getModificationDate()),
                "creationDate": self._serialize_date(event.created_dt),
                "creator": self._serialize_person(event.creator, person_type="Avatar", can_manage=can_manage),
                "hasAnyProtection": event.effective_protection_mode != ProtectionMode.public,
                "roomMapURL": event.room.map_url if event.room else None,
                "folders": build_folders_api_data(event),
                "chairs": self._serialize_persons(
                    event.person_links, person_type="ConferenceChair", can_manage=can_manage
                ),
                "material": build_material_legacy_api_data(event)
                + filter(None, [build_note_legacy_api_data(event.note)]),
            }
        )

        event_category_path = event.category.chain
        visibility = {"id": "", "name": "Everywhere"}
        if event.visibility is None:
            pass  # keep default
        elif event.visibility == 0:
            visibility["name"] = "Nowhere"
        elif event.visibility:
            try:
                path_segment = event_category_path[-event.visibility]
            except IndexError:
                pass
            else:
                visibility["id"] = path_segment["id"]
                visibility["name"] = path_segment["title"]
        data["visibility"] = visibility

        if can_manage:
            data["allowed"] = self._serialize_access_list(event)
        if self._detail_level in {"contributions", "subcontributions"}:
            data["contributions"] = []
            for contribution in event.contributions:
                include_subcontribs = self._detail_level == "subcontributions"
                serialized_contrib = self._serialize_contribution(contribution, include_subcontribs)
                data["contributions"].append(serialized_contrib)
        elif self._detail_level == "sessions":
            # Contributions without a session
            data["contributions"] = []
            for contribution in event.contributions:
                if not contribution.session:
                    serialized_contrib = self._serialize_contribution(contribution)
                    data["contributions"].append(serialized_contrib)

            data["sessions"] = []
            for session_ in event.sessions:
                data["sessions"].extend(self._build_session_api_data(session_))
        if self._occurrences:
            data["occurrences"] = fossilize(
                self._calculate_occurrences(event, self._fromDT, self._toDT, pytz.timezone(self._serverTZ)),
                {Period: IPeriodFossil},
                tz=self._tz,
                naiveTZ=self._serverTZ,
            )
        return data