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
def _serialize_session(self, session_, can_manage=False): return { 'folders': build_folders_api_data(session_), 'startDate': self._serialize_date(session_.start_dt) if session_.blocks else None, 'endDate': self._serialize_date(session_.end_dt) if session_.blocks else None, '_type': 'Session', 'sessionConveners': [self._serialize_convener(c, can_manage) for c in session_.conveners], 'title': session_.title, 'color': '#{}'.format(session_.colors.background), 'textColor': '#{}'.format(session_.colors.text), 'description': session_.description, 'material': build_material_legacy_api_data(session_), 'isPoster': session_.is_poster, 'url': url_for('sessions.display_session', session_, _external=True), 'roomFullname': session_.room_name, 'location': session_.venue_name, 'address': session_.address, '_fossil': 'sessionMinimal', 'numSlots': len(session_.blocks), 'id': (session_.legacy_mapping.legacy_session_id if session_.legacy_mapping else unicode(session_.friendly_id)), 'db_id': session_.id, 'friendly_id': session_.friendly_id, 'room': session_.get_room_name(full=False) }
def _serialize_subcontribution(self, subcontrib): can_manage = self.user is not None and subcontrib.contribution.can_manage( self.user) data = { '_type': 'SubContribution', '_fossil': 'subContributionMetadata', 'id': (subcontrib.legacy_mapping.legacy_subcontribution_id if subcontrib.legacy_mapping else unicode(subcontrib.friendly_id)), 'db_id': subcontrib.id, 'friendly_id': subcontrib.friendly_id, 'title': subcontrib.title, 'duration': subcontrib.duration.seconds // 60, 'note': build_note_api_data(subcontrib.note), 'material': build_material_legacy_api_data(subcontrib), 'folders': build_folders_api_data(subcontrib), 'speakers': self._serialize_persons(subcontrib.speakers, person_type='SubContribParticipation', can_manage=can_manage), 'references': map(self.serialize_reference, subcontrib.references) } return data
def _serialize_session(self, session_, can_manage=False): return { "folders": build_folders_api_data(session_), "startDate": self._serialize_date(session_.start_dt) if session_.blocks else None, "endDate": self._serialize_date(session_.end_dt) if session_.blocks else None, "_type": "Session", "sessionConveners": [self._serialize_convener(c, can_manage) for c in session_.conveners], "title": session_.title, "color": "#{}".format(session_.colors.background), "textColor": "#{}".format(session_.colors.text), "description": session_.description, "material": build_material_legacy_api_data(session_), "isPoster": session_.is_poster, "url": url_for("sessions.display_session", session_, _external=True), "roomFullname": session_.room_name, "location": session_.venue_name, "address": session_.address, "_fossil": "sessionMinimal", "numSlots": len(session_.blocks), "id": ( session_.legacy_mapping.legacy_session_id if session_.legacy_mapping else unicode(session_.friendly_id) ), "db_id": session_.id, "friendly_id": session_.friendly_id, "room": session_.get_room_name(full=False), }
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
def _serialize_contribution(self, contrib, include_subcontribs=True): can_manage = self.user is not None and contrib.can_manage(self.user) data = { "_type": "Contribution", "_fossil": self.fossils_mapping["contribution"].get(self._detail_level), "id": ( contrib.legacy_mapping.legacy_contribution_id if contrib.legacy_mapping else unicode(contrib.friendly_id) ), "db_id": contrib.id, "friendly_id": contrib.friendly_id, "title": contrib.title, "startDate": self._serialize_date(contrib.start_dt) if contrib.start_dt else None, "endDate": self._serialize_date(contrib.start_dt + contrib.duration) if contrib.start_dt else None, "duration": contrib.duration.seconds // 60, "roomFullname": contrib.room_name, "room": contrib.get_room_name(full=False), "note": build_note_api_data(contrib.note), "location": contrib.venue_name, "type": contrib.type.name if contrib.type else None, "description": contrib.description, "folders": build_folders_api_data(contrib), "url": url_for("contributions.display_contribution", contrib, _external=True), "material": build_material_legacy_api_data(contrib), "speakers": self._serialize_persons( contrib.speakers, person_type="ContributionParticipation", can_manage=can_manage ), "primaryauthors": self._serialize_persons( contrib.primary_authors, person_type="ContributionParticipation", can_manage=can_manage ), "coauthors": self._serialize_persons( contrib.secondary_authors, person_type="ContributionParticipation", can_manage=can_manage ), "keywords": contrib.keywords, "track": contrib.track.title if contrib.track else None, "session": contrib.session.title if contrib.session else None, "references": map(self.serialize_reference, contrib.references), } if include_subcontribs: data["subContributions"] = map(self._serialize_subcontribution, contrib.subcontributions) if can_manage: data["allowed"] = self._serialize_access_list(contrib) return data
def _serialize_subcontribution(self, subcontrib): can_manage = self.user is not None and subcontrib.contribution.can_manage(self.user) data = { '_type': 'SubContribution', '_fossil': 'subContributionMetadata', 'id': (subcontrib.legacy_mapping.legacy_subcontribution_id if subcontrib.legacy_mapping else unicode(subcontrib.friendly_id)), 'db_id': subcontrib.id, 'friendly_id': subcontrib.friendly_id, 'title': subcontrib.title, 'duration': subcontrib.duration.seconds // 60, 'note': build_note_api_data(subcontrib.note), 'material': build_material_legacy_api_data(subcontrib), 'folders': build_folders_api_data(subcontrib), 'speakers': self._serialize_persons(subcontrib.speakers, person_type='SubContribParticipation', can_manage=can_manage), 'references': map(self.serialize_reference, subcontrib.references) } return data
def _serialize_contribution(self, contrib, include_subcontribs=True): can_manage = self.user is not None and contrib.can_manage(self.user) data = { '_type': 'Contribution', '_fossil': self.fossils_mapping['contribution'].get(self._detail_level), 'id': (contrib.legacy_mapping.legacy_contribution_id if contrib.legacy_mapping else unicode(contrib.friendly_id)), 'db_id': contrib.id, 'friendly_id': contrib.friendly_id, 'title': contrib.title, 'startDate': self._serialize_date(contrib.start_dt) if contrib.start_dt else None, 'endDate': self._serialize_date(contrib.start_dt + contrib.duration) if contrib.start_dt else None, 'duration': contrib.duration.seconds // 60, 'roomFullname': contrib.room_name, 'room': contrib.get_room_name(full=False), 'note': build_note_api_data(contrib.note), 'location': contrib.venue_name, 'type': contrib.type.name if contrib.type else None, 'description': contrib.description, 'folders': build_folders_api_data(contrib), 'url': url_for('contributions.display_contribution', contrib, _external=True), 'material': build_material_legacy_api_data(contrib), 'speakers': self._serialize_persons(contrib.speakers, person_type='ContributionParticipation', can_manage=can_manage), 'primaryauthors': self._serialize_persons(contrib.primary_authors, person_type='ContributionParticipation', can_manage=can_manage), 'coauthors': self._serialize_persons(contrib.secondary_authors, person_type='ContributionParticipation', can_manage=can_manage), 'keywords': contrib.keywords, 'track': contrib.track.title if contrib.track else None, 'session': contrib.session.title if contrib.session else None, 'references': map(self.serialize_reference, contrib.references), 'board_number': contrib.board_number } if include_subcontribs: data['subContributions'] = map(self._serialize_subcontribution, contrib.subcontributions) if can_manage: data['allowed'] = self._serialize_access_list(contrib) return data
def _serialize_subcontribution(self, subcontrib): can_manage = self.user is not None and subcontrib.contribution.can_manage(self.user) data = { "_type": "SubContribution", "_fossil": "subContributionMetadata", "id": ( subcontrib.legacy_mapping.legacy_subcontribution_id if subcontrib.legacy_mapping else unicode(subcontrib.friendly_id) ), "db_id": subcontrib.id, "friendly_id": subcontrib.friendly_id, "title": subcontrib.title, "duration": subcontrib.duration.seconds // 60, "note": build_note_api_data(subcontrib.note), "material": build_material_legacy_api_data(subcontrib), "folders": build_folders_api_data(subcontrib), "speakers": self._serialize_persons( subcontrib.speakers, person_type="SubContribParticipation", can_manage=can_manage ), "references": map(self.serialize_reference, subcontrib.references), } return data
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
def export_attachments(self, user): return {'folders': build_folders_api_data(self._obj)}
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
class CategoryEventFetcher(IteratedDataFetcher, SerializerBase): def __init__(self, user, hook): super().__init__(user, hook) self._eventType = hook._eventType self._occurrences = hook._occurrences self._location = hook._location self._room = hook._room self.user = user self._detail_level = get_query_parameter(request.args.to_dict(), ['d', 'detail'], 'events') if self._detail_level not in ('events', 'contributions', 'subcontributions', 'sessions'): raise HTTPAPIError(f'Invalid detail level: {self._detail_level}', 400) def _calculate_occurrences(self, event, from_dt, to_dt, tz): start_dt = max(from_dt, event.start_dt) if from_dt else event.start_dt end_dt = min(to_dt, event.end_dt) if to_dt else event.end_dt for day in iterdays(start_dt, end_dt): first_start, last_end = find_event_day_bounds(event, day.date()) if first_start is not None: yield Period(first_start, last_end) def _get_query_options(self, detail_level): acl_user_strategy = joinedload('acl_entries').joinedload('user') # remote group membership checks will trigger a load on _all_emails # but not all events use this so there's no need to eager-load them # acl_user_strategy.noload('_primary_email') # acl_user_strategy.noload('_affiliation') creator_strategy = joinedload('creator') contributions_strategy = subqueryload('contributions') contributions_strategy.subqueryload('references') if detail_level in {'subcontributions', 'sessions'}: contributions_strategy.subqueryload('subcontributions').subqueryload('references') sessions_strategy = subqueryload('sessions') options = [acl_user_strategy, creator_strategy] if detail_level in {'contributions', 'subcontributions', 'sessions'}: options.append(contributions_strategy) if detail_level == 'sessions': options.append(sessions_strategy) options.append(undefer('effective_protection_mode')) return options def category(self, idlist, format): try: idlist = list(map(int, idlist)) except ValueError: raise HTTPAPIError('Category IDs must be numeric', 400) if format == 'ics': buf = serialize_categories_ical(idlist, self.user, event_filter=Event.happens_between(self._fromDT, self._toDT), event_filter_fn=self._filter_event, update_query=self._update_query) return send_file('events.ics', buf, 'text/calendar') else: query = (Event.query .filter(~Event.is_deleted, Event.category_chain_overlaps(idlist), Event.happens_between(self._fromDT, self._toDT)) .options(*self._get_query_options(self._detail_level))) query = self._update_query(query) return self.serialize_events(x for x in query if self._filter_event(x) and x.can_access(self.user)) def category_extra(self, ids): if self._toDT is None: has_future_events = False else: query = Event.find(Event.category_id.in_(ids), ~Event.is_deleted, Event.start_dt > self._toDT) has_future_events = query.has_rows() return { 'eventCategories': self._build_category_path_data(ids), 'moreFutureEvents': has_future_events } def event(self, idlist): query = (Event.find(Event.id.in_(idlist), ~Event.is_deleted, Event.happens_between(self._fromDT, self._toDT)) .options(*self._get_query_options(self._detail_level))) query = self._update_query(query) return self.serialize_events(x for x in query if self._filter_event(x) and x.can_access(self.user)) def _filter_event(self, event): if self._room or self._location or self._eventType: if self._eventType and event.type_.name != self._eventType: return False if self._location: name = event.venue_name if not name or not fnmatch.fnmatch(name.lower(), self._location.lower()): return False if self._room: name = event.room_name if not name or not fnmatch.fnmatch(name.lower(), self._room.lower()): return False return True def _update_query(self, query): order = get_query_parameter(request.args.to_dict(), ['o', 'order']) desc = get_query_parameter(request.args.to_dict(), ['c', 'descending']) == 'yes' limit = get_query_parameter(request.args.to_dict(), ['n', 'limit']) offset = get_query_parameter(request.args.to_dict(), ['O', 'offset']) col = { 'start': Event.start_dt, 'end': Event.end_dt, 'id': Event.id, 'title': Event.title }.get(order) if col: query = query.order_by(col.desc() if desc else col) if limit: query = query.limit(limit) if offset: query = query.offset(offset) return query def serialize_events(self, events): return list(map(self._build_event_api_data, events)) def _serialize_category_path(self, category): visibility = {'id': None, 'name': 'Everywhere'} path = [self._serialize_path_entry(category_data) for category_data in category.chain] if category.visibility is not None: try: path_segment = path[-category.visibility] except IndexError: pass else: visibility['id'] = path_segment['id'] visibility['name'] = path_segment['name'] path.append({'visibility': visibility}) return path def _serialize_path_entry(self, category_data): return { '_fossil': 'categoryMetadata', 'type': 'Category', 'name': category_data['title'], 'id': category_data['id'], 'url': url_for('categories.display', category_id=category_data['id'], _external=True) } def _build_category_path_data(self, ids): return [{'_type': 'CategoryPath', 'categoryId': category.id, 'path': self._serialize_category_path(category)} for category in Category.query.filter(Category.id.in_(ids)).options(undefer('chain'))] 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) 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': material_data, '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'}: data['contributions'] = [] if allow_details: 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': data['contributions'] = [] data['sessions'] = [] if allow_details: # Contributions without a session for contribution in event.contributions: if not contribution.session: serialized_contrib = self._serialize_contribution(contribution) data['contributions'].append(serialized_contrib) 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
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