Skip to content

Commit

Permalink
Add tags to public schedule and session view (#158)
Browse files Browse the repository at this point in the history
* add tag in talk view detail
* show tags on schedule and session view
* move tag to above track and room

---------

Co-authored-by: lcduong <[email protected]>
  • Loading branch information
lcduong and odkhang authored Jul 31, 2024
1 parent b2b3f01 commit 50cd392
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/pretalx/agenda/templates/agenda/talk.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ <h3 class="talk-title">
<section>
{% html_signal "pretalx.agenda.signals.html_below_session_pages" sender=request.event request=request submission=submission %}
</section>
{% if submission_tags %}
{% for tag_item in submission_tags %}
<span class="submission_tag" onclick="#" style="background-color: {{ tag_item.color }}; color: {{ tag_item.contrast_color }};">{{ tag_item.tag }}</span>
{% endfor %}
{% endif %}
</div>
</div>
{% if not hide_speaker_links %}
Expand Down
13 changes: 13 additions & 0 deletions src/pretalx/agenda/views/talk.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ def submission(self):
def get_permission_object(self):
return self.submission

def get_contrast_color(self, bg_color):
if not bg_color:
return ''
bg_color = bg_color.lstrip('#')
r = int(bg_color[0:2], 16)
g = int(bg_color[2:4], 16)
b = int(bg_color[4:6], 16)
brightness = (r * 299 + g * 587 + b * 114) / 1000
return 'black' if brightness > 128 else 'white'

@cached_property
def recording(self):
for __, response in register_recording_provider.send_robust(self.request.event):
Expand Down Expand Up @@ -93,6 +103,9 @@ def get_context_data(self, **kwargs):
.order_by("start")
.select_related("room")
)
ctx["submission_tags"] = self.submission.tags.all()
for tag_item in ctx['submission_tags']:
tag_item.contrast_color = self.get_contrast_color(tag_item.color)
result = []
other_slots = (
schedule.talks.exclude(submission_id=self.submission.pk).filter(
Expand Down
3 changes: 2 additions & 1 deletion src/pretalx/schedule/models/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,8 @@ def build_data(self, all_talks=False, filter_updated=None, all_rooms=False):
"updated": talk.updated.isoformat(),
"state": talk.submission.state if all_talks else None,
"fav_count": count_fav_talk(talk.submission.code) if talk.submission else 0,
"do_not_record": talk.submission.do_not_record
"do_not_record": talk.submission.do_not_record,
"tags": talk.submission.get_tag()
}
)
else:
Expand Down
3 changes: 3 additions & 0 deletions src/pretalx/static/agenda/scss/_speaker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
max-width: 100%;
}
}
.submission_tag {
padding: 0px 5px;
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/pretalx/submission/models/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,16 @@ def get_duration(self) -> int:
return self.submission_type.default_duration
return self.duration

def get_tag(self):
tags = []
for tag in self.tags.all():
tags.append({
'id': tag.id,
'tag': tag.tag,
'color': tag.color
})
return tags

def update_duration(self):
"""Apply the submission's duration to its currently scheduled.
Expand Down

0 comments on commit 50cd392

Please sign in to comment.