Skip to content
Snippets Groups Projects
Unverified Commit 2d1f6043 authored by Andreas Hubel's avatar Andreas Hubel
Browse files

refactor / try to expose desciption of PlatformUser/ConferenceMember

parent 2cec4091
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ from django.conf import settings ...@@ -14,7 +14,7 @@ from django.conf import settings
from django.db.models import Prefetch from django.db.models import Prefetch
from core.models.assemblies import Assembly from core.models.assemblies import Assembly
from core.models.conference import Conference from core.models.conference import Conference, ConferenceMember
from core.models.events import Event, EventParticipant from core.models.events import Event, EventParticipant
from core.models.rooms import Room from core.models.rooms import Room
from core.models.users import PlatformUser from core.models.users import PlatformUser
...@@ -41,6 +41,7 @@ event_template = { ...@@ -41,6 +41,7 @@ event_template = {
'type': 'other', 'type': 'other',
'abstract': None, 'abstract': None,
'description': None, 'description': None,
'logo': None,
'persons': [], 'persons': [],
'links': [], 'links': [],
} }
...@@ -103,59 +104,60 @@ class ScheduleEncoder(json.JSONEncoder): ...@@ -103,59 +104,60 @@ class ScheduleEncoder(json.JSONEncoder):
return f'{days}:{hours:02d}:{minutes:02d}' return f'{days}:{hours:02d}:{minutes:02d}'
return f'{hours:02d}:{minutes:02d}' return f'{hours:02d}:{minutes:02d}'
def encode_person(self, person: PlatformUser | str | dict): def encode_person(self, p: EventParticipant | PlatformUser | str | dict):
if isinstance(person, str): if isinstance(p, str):
return {'id': None, 'name': person, 'public_name': person} return {'id': None, 'name': p, 'public_name': p}
if isinstance(person, PlatformUser): if isinstance(p, PlatformUser):
name = person.get_display_name() name = p.get_display_name()
return { return {
'guid': person.uuid, 'guid': p.uuid,
'name': name, 'name': name,
'public_name': name, 'public_name': name,
'avatar': (settings.PLAINUI_BASE_URL + person.avatar.url) if person.avatar else None, 'avatar': (settings.PLAINUI_BASE_URL + p.avatar.url) if p.avatar else None,
'biography': person.description, 'biography': p.description,
# 'links': person.links, # TODO # 'links': person.links, # TODO
'url': person.get_absolute_url(), 'url': p.get_absolute_url(),
} }
if isinstance(person, EventParticipant): if isinstance(p, EventParticipant):
member = person.event.conference.users.filter(uuid=person.participant.uuid).first() member: ConferenceMember = p.event.conference.users.filter(uuid=p.participant.uuid).first()
name = person.participant.get_display_name() name = p.participant.get_display_name()
return { return {
'guid': person.participant.uuid, 'guid': p.participant.uuid,
'name': name, 'name': name,
'public_name': name, 'public_name': name,
'avatar': (settings.PLAINUI_BASE_URL + person.participant.avatar.url) if person.participant.avatar else None, 'avatar': (settings.PLAINUI_BASE_URL + p.participant.avatar.url) if p.participant.avatar else None,
'biography': member.description if member else '', 'biography': member.description if member else '',
# 'links': person.participant.links, # TODO # 'links': person.participant.links, # TODO
'url': person.participant.get_absolute_url(), 'url': p.participant.get_absolute_url(),
} }
# we assume it is a dict, but we normally should never get here # we assume it is a dict, but we normally should never get here
return { return {
'guid': person.get('guid', None), 'guid': p.get('guid', None),
'id': person.get('id', None), 'id': p.get('id', None),
'name': person.get('name', person.get('public_name')), 'name': p.get('name', p.get('public_name')),
'avatar': person.get('avatar', None), 'avatar': p.get('avatar', None),
'biography': person.get('biography') or person.get('description', ''), 'biography': p.get('biography') or p.get('description', ''),
'links': person.get('links', []), 'links': p.get('links', []),
} }
def collect_persons(self, event): def collect_persons(self, event):
persons = [] persons = []
# TODO remove this workaround once imported speakers are stored as participants
# and have links and biography=description
if event.additional_data and 'persons' in event.additional_data and len(event.additional_data['persons']) > 0:
persons = event.additional_data['persons']
else:
if hasattr(event, 'speakers'): if hasattr(event, 'speakers'):
# event is a QuerySet and already fetched speakers # event is a QuerySet and already fetched speakers
persons = event.speakers persons = list(event.speakers)
else: else:
# direct event lookup -> fetch persons via public_speakers # direct event lookup -> fetch persons via public_speakers
persons = event.public_speakers persons = list(event.public_speakers)
# TODO remove this workaround once imported speakers are stored as participants
if event.additional_data and 'persons' in event.additional_data and len(event.additional_data['persons']) > 0:
persons += event.additional_data['persons']
return [self.encode_person(person) for person in persons] return [self.encode_person(person) for person in persons]
...@@ -315,6 +317,7 @@ class Schedule: ...@@ -315,6 +317,7 @@ class Schedule:
def add_events(self, events: 'QuerySet[Event]'): def add_events(self, events: 'QuerySet[Event]'):
events = events.select_related('track', 'room', 'assembly', 'conference').prefetch_related( events = events.select_related('track', 'room', 'assembly', 'conference').prefetch_related(
Prefetch( Prefetch(
# TODO: we have to prefetch the conference members here, as we need the description for the speakers
'participants', 'participants',
queryset=EventParticipant.objects.filter(is_public=True, role=EventParticipant.Role.SPEAKER).select_related('participant'), queryset=EventParticipant.objects.filter(is_public=True, role=EventParticipant.Role.SPEAKER).select_related('participant'),
to_attr='speakers', to_attr='speakers',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment