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_block(self, block, serialized_session, session_access_list, can_manage): block_data = { "_type": "SessionSlot", "_fossil": self.fossils_mapping["block"].get(self._detail_level), "id": block.id, # TODO: Need to check if breaking the `session_id-block_id` format is OK "conference": self._build_session_event_api_data(block.event_new), "startDate": self._serialize_date(block.timetable_entry.start_dt) if block.timetable_entry else None, "endDate": self._serialize_date(block.timetable_entry.end_dt) if block.timetable_entry else None, "description": "", # Session blocks don't have a description "title": block.full_title, "url": url_for("sessions.display_session", block.session, _external=True), "contributions": map(self._serialize_contribution, block.contributions), "note": build_note_api_data(block.note), "session": serialized_session, "room": block.get_room_name(full=False), "roomFullname": block.room_name, "location": block.venue_name, "inheritLoc": block.inherit_location, "inheritRoom": block.own_room is None, "slotTitle": block.title, "address": block.address, "conveners": [self._serialize_convener(c, can_manage) for c in block.person_links], } if session_access_list: block_data["allowed"] = session_access_list return block_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
class ISessionMetadataBaseFossil(ISessionSlotFossil, _IncludeACLFossil): def getSession(self): pass getSession.result = ISessionMinimalFossil def getId(self): pass getId.produce = lambda ss: "{0}-{1}".format(ss.getSession().getId(), ss.getId()) def getLocator(self): pass getLocator.convert = Conversion.url(urlHandlers.UHSessionDisplay) getLocator.name = 'url' def getFullTitle(self): pass getFullTitle.name = 'title' def getDescription(self): pass def getNote(self): pass getNote.produce = lambda x: build_note_api_data(x.note)
def _serialize_session_block(self, block, serialized_session, session_access_list, can_manage): block_data = { '_type': 'SessionSlot', '_fossil': self.fossils_mapping['block'].get(self._detail_level), 'id': block.id, # TODO: Need to check if breaking the `session_id-block_id` format is OK 'conference': self._build_session_event_api_data(block.event_new), 'startDate': self._serialize_date(block.timetable_entry.start_dt) if block.timetable_entry else None, 'endDate': self._serialize_date(block.timetable_entry.end_dt) if block.timetable_entry else None, 'description': '', # Session blocks don't have a description 'title': block.full_title, 'url': url_for('sessions.display_session', block.session, _external=True), 'contributions': map(self._serialize_contribution, block.contributions), 'note': build_note_api_data(block.note), 'session': serialized_session, 'room': block.get_room_name(full=False), 'roomFullname': block.room_name, 'location': block.venue_name, 'inheritLoc': block.inherit_location, 'inheritRoom': block.own_room is None, 'slotTitle': block.title, 'address': block.address, 'conveners': [self._serialize_convener(c, can_manage) for c in block.person_links] } if session_access_list: block_data['allowed'] = session_access_list return block_data
def _serialize_session_block(self, block, serialized_session, session_access_list, can_manage): block_data = { '_type': 'SessionSlot', '_fossil': self.fossils_mapping['block'].get(self._detail_level), 'id': block.id, # TODO: Need to check if breaking the `session_id-block_id` format is OK 'conference': self._build_session_event_api_data(block.event), 'startDate': self._serialize_date(block.timetable_entry.start_dt) if block.timetable_entry else None, 'endDate': self._serialize_date(block.timetable_entry.end_dt) if block.timetable_entry else None, 'description': '', # Session blocks don't have a description 'title': block.full_title, 'url': url_for('sessions.display_session', block.session, _external=True), 'contributions': map(self._serialize_contribution, block.contributions), 'note': build_note_api_data(block.note), 'session': serialized_session, 'room': block.get_room_name(full=False), 'roomFullname': block.room_name, 'location': block.venue_name, 'inheritLoc': block.inherit_location, 'inheritRoom': block.own_room is None, 'slotTitle': block.title, 'address': block.address, 'conveners': [self._serialize_convener(c, can_manage) for c in block.person_links] } if session_access_list: block_data['allowed'] = session_access_list return block_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 _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_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
class ISubContributionMetadataFossil(IFossil, _IncludeACLFossil, _IncludeMaterialFossil): def getId(self): pass def getTitle(self): pass def getDuration(self): pass getDuration.convert = Conversion.duration def getSpeakerList(self): pass getSpeakerList.name = 'speakers' getSpeakerList.result = IContributionParticipationMetadataFossil def getNote(self): pass getNote.produce = lambda x: build_note_api_data(x.note)
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
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
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_note(self, aw): return build_note_api_data(self._note)
def export_note(self, user): return build_note_api_data(self._note)
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 IConferenceMetadataFossil(_IncludeMaterialFossil, _IncludeACLFossil, IFossil): def getId(self): pass def getStartDate(self): pass getStartDate.convert = Conversion.datetime def getEndDate(self): pass getEndDate.convert = Conversion.datetime def getTitle(self): pass def getDescription(self): pass def getType(self): pass def getOwner(self): pass getOwner.convert = lambda x: x.getTitle() getOwner.name = 'category' def getCategoryId(self): pass getCategoryId.produce = lambda x: x.getOwner().getId() def getTimezone(self): pass def getNote(self): pass getNote.produce = lambda x: build_note_api_data(x.note) def getChairList(self): pass getChairList.name = 'chairs' getChairList.result = IConferenceChairMetadataFossil def getLocation(self): """ Location (CERN/...) """ getLocation.convert = lambda l: l and l.getName() def getLocator(self): pass getLocator.convert = Conversion.url(urlHandlers.UHConferenceDisplay) getLocator.name = 'url' def getRoom(self): """ Room (inside location) """ getRoom.convert = lambda r: r and r.getName() def getRoomFullName(self): """ Conference Room """ getRoomFullName.produce = lambda c: c.getRoom() getRoomFullName.convert = Conversion.roomFullName getRoomFullName.name = 'roomFullname' def getVisibility(self): pass getVisibility.name = 'visibility' getVisibility.produce = lambda x: Conversion.visibility(x) def hasAnyProtection(self): pass def getAddress(self): pass def getCreator(self): pass getCreator.produce = lambda x: x.as_event.creator.as_avatar getCreator.result = IConferenceChairMetadataFossil def getCreationDate(self): pass def getModificationDate(self): pass def getRoomMapURL(self): pass getRoomMapURL.produce = lambda x: RoomLinker().getURL(x.getRoom(), x.getLocation())
class IContributionMetadataFossil(_IncludeMaterialFossil, _IncludeACLFossil, IFossil): def getId(self): pass def getTitle(self): pass def getLocation(self): pass getLocation.convert = lambda l: l and l.getName() def getRoom(self): pass getRoom.convert = lambda r: r and r.getName() def getRoomFullName(self): """ Contribution Room """ getRoomFullName.produce = lambda c: c.getRoom() getRoomFullName.convert = Conversion.roomFullName getRoomFullName.name = 'roomFullname' def getStartDate(self): pass getStartDate.convert = Conversion.datetime def getEndDate(self): pass getEndDate.convert = Conversion.datetime def getDuration(self): pass getDuration.convert = Conversion.duration def getDescription(self): pass def getSpeakerList(self): pass getSpeakerList.name = 'speakers' getSpeakerList.result = IContributionParticipationMetadataFossil def getPrimaryAuthorList(self): pass getPrimaryAuthorList.name = 'primaryauthors' getPrimaryAuthorList.result = IContributionParticipationMetadataFossil def getCoAuthorList(self): pass getCoAuthorList.name = 'coauthors' getCoAuthorList.result = IContributionParticipationMetadataFossil def getTrack( self ): pass getTrack.convert = lambda t: t and t.getTitle() def getSession( self ): pass getSession.convert = lambda s: s and s.getTitle() def getType(self): pass getType.convert = lambda t: t and t.getName() def getLocator(self): pass getLocator.convert = Conversion.url(urlHandlers.UHContributionDisplay) getLocator.name = 'url' def getKeywords(self): pass getKeywords.produce = lambda x: x.getKeywords().splitlines() if x.getKeywords().strip() else [] def getNote(self): pass getNote.produce = lambda x: build_note_api_data(x.note)