Skip to content

Commit

Permalink
Allow different audio formats (why didn't I do that before? laziness)…
Browse files Browse the repository at this point in the history
…. Slugify user inputed ids cause no one reads help text. Alter some help texts lmao. Highlight manually inputted events on events calendar to make admining easier.
  • Loading branch information
SamuelmdLow committed Oct 29, 2024
1 parent 7e41f21 commit 98d751a
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 21 deletions.
30 changes: 27 additions & 3 deletions article/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,40 @@

class AudioBlock(blocks.StructBlock):
caption = blocks.CharBlock(required=False)
audio = DocumentChooserBlock(required=True, help_text="Must be mp3 format")

audio = DocumentChooserBlock(required=True, help_text="File format: .m4a, .mp4, .mp, .wav, or .ogg")

def get_context(self, value, parent_context=None):
context = super().get_context(value, parent_context)
if value['audio'].url[-4:] == '.wav':
context['self'].format = 'wav'
if value['audio'].url[-4:] == '.mp3':
context['self'].format = 'mpeg'
if value['audio'].url[-4:] == '.ogg':
context['self'].format = 'ogg'
else:
context['self'].format = 'mp4'
return context

class Meta:
template = 'article/stream_blocks/audio.html',
icon = "media"

class PullQuoteBlock(blocks.StructBlock):
content = blocks.CharBlock(required=True)
source = blocks.CharBlock(required=False)
audio = DocumentChooserBlock(required=False, help_text="optional, must be mp3 format")
audio = DocumentChooserBlock(required=False, help_text="Optional, file format: .m4a, .mp4, .mp, .wav, or .ogg")

def get_context(self, value, parent_context=None):
context = super().get_context(value, parent_context)
if value['audio'].url[-4:] == '.wav':
context['self'].format = 'wav'
if value['audio'].url[-4:] == '.mp3':
context['self'].format = 'mpeg'
if value['audio'].url[-4:] == '.ogg':
context['self'].format = 'ogg'
else:
context['self'].format = 'mp4'
return context

class Meta:
template = 'article/stream_blocks/quote.html',
Expand Down
4 changes: 2 additions & 2 deletions article/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ class ArticlePage(RoutablePageMixin, SectionablePage, UbysseyMenuMixin):
('dropcap', blocks.TextBlock(
label = "Dropcap Block",
template = 'article/stream_blocks/dropcap.html',
help_text = "DO NOT USE - Legacy block. Create a block where special dropcap styling with be applied to the first letter and the first letter only.\n\nThe contents of this block will be enclosed in a <p class=\"drop-cap\">...</p> element, allowing its targetting for styling.\n\nNo RichText allowed."
help_text = "Create a block where special dropcap styling with be applied to the first letter and the first letter only.\n\nThe contents of this block will be enclosed in a <p class=\"drop-cap\">...</p> element, allowing its targetting for styling.\n\nNo RichText allowed."
)),
('video', video_blocks.OneOffVideoBlock(
label = "Credited/Captioned One-Off Video",
Expand Down Expand Up @@ -546,7 +546,7 @@ class ArticlePage(RoutablePageMixin, SectionablePage, UbysseyMenuMixin):
blank=True,
default='',
max_length=255,
help_text="Enter the slug of the tag to be used for linking at the end of the article. For example, the slug of the tag 'blue chip' is 'blue-chip'.",
help_text="IF USED, SHOULD ALSO BE IN TAGS FIELD. Enter the slug of the tag to be used for linking at the end of the article. For example, the slug of the tag 'blue chip' is 'blue-chip'.",
)
tag_page_link = models.BooleanField(
null=False,
Expand Down
2 changes: 1 addition & 1 deletion article/templates/article/stream_blocks/audio.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="audio">
<p class="caption">{{self.caption}}</p>
<audio controls>
<source src="{{self.audio.url}}" type="audio/mpeg">
<source src="{{self.audio.url}}" type="audio/{{self.format}}">
Your browser does not support the audio element.
</audio>
</div>
3 changes: 2 additions & 1 deletion article/templates/article/stream_blocks/header.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load wagtailcore_tags %}
<div class="header">
<h2 class="pageLink{{self.id}}" id="{{self.id}}">{{self.title}}</h2>
<h2 class="pageLink{{self.id|slugify}}" id="{{self.id|slugify}}">{{self.title}}</h2>
</div>
7 changes: 4 additions & 3 deletions article/templates/article/stream_blocks/pageLink.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{% load static %}
{% load wagtailcore_tags %}

<div class="header-menu">
<ul>
{% for item in self.list %}
<style>
.pageLink{{item.id}} {
.pageLink{{item.id|slugify}} {
--linkColour: #{{item.colour}};
}
</style>
<li class="menu-title pageLink{{item.id}}">
<a href="#{{item.id}}">{{item.title}}</a>
<li class="menu-title pageLink{{item.id|slugify}}">
<a href="#{{item.id|slugify}}">{{item.title}}</a>
</li>
{% endfor %}
</ul>
Expand Down
10 changes: 6 additions & 4 deletions article/templates/article/stream_blocks/quote.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{% load wagtailcore_tags %}

{% if self.audio %}
<audio id="{{id}}">
<source src="{{self.audio.url}}" type="audio/mpeg">
<audio id="{{id|slugify}}">
<source src="{{self.audio.url}}" type="audio/{{self.format}}">
</audio>
{% endif %}

<div class="pull-quote attachment">
<p class="quote">{{ self.content }}</p>
<p class="meta">
{% if self.audio %}
<a href="#" audio="{{id}}" class="playAudioQuote">
<ion-icon id="icon-{{id}}" class="volume" name="volume-off"></ion-icon>
<a href="#" audio="{{id|slugify}}" class="playAudioQuote">
<ion-icon id="icon-{{id|slugify}}" class="volume" name="volume-off"></ion-icon>
{% if self.source %}<span class="source">Listen to {{ self.source }}</span>{% endif %}
</a>
{% elif self.source %}
Expand Down
9 changes: 5 additions & 4 deletions events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,16 @@ def ubcevents_category(self, event):

categories = categories.to_ical().decode().lower()

# Check for entertainment keywords
for i in ['entertainment', 'concert', 'perform', 'film']:
if i in categories:
return 'entertainment'

# Check for community keywords
for i in ['orientations', 'festival']:
if i in categories:
return 'community'

# Check for entertainment keywords
for i in ['entertainment', 'concert', 'perform']:
if i in categories:
return 'entertainment'

if 'graduate students' in categories:
if not True in (term in categories for term in ['audience – community', 'audience – undergraduate students', 'audience – all students']):
Expand Down
2 changes: 1 addition & 1 deletion events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ def item_link(self, item):
class EventsSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Event
fields = ['id', 'title', 'description', 'start_time', 'end_time', 'location', 'address', 'host', 'email', 'event_url', 'hash', 'category']
fields = ['id', 'title', 'description', 'start_time', 'end_time', 'location', 'address', 'host', 'email', 'event_url', 'hash', 'category', 'update_mode']

class EventsViewSet(viewsets.ModelViewSet):
serializer_class = EventsSerializer
Expand Down
2 changes: 1 addition & 1 deletion ubyssey/static_src/src/js/components/Events/calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ function EventsCalendar({events}) {
<span className="events-calendar--number-dayOfWeek">{day.day_of_week} </span>{day.day}.
</button>
<ul>{day.events.map((event) =>
<li className={(eventHash==event.hash && "selected") + " " + eventsTags(event)}>
<li className={(eventHash==event.hash && "selected") + " " + eventsTags(event) + " " + (event.update_mode==0 && "manual")}>
<Link title={event.title.replace("<br>", ", ")} className="calendar-item" to={"?event=" + event.hash} event-url={event.event_url}
onClick={(e) => {
e.preventDefault();
Expand Down
4 changes: 3 additions & 1 deletion ubyssey/static_src/src/styles/components/events/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ main.events-page {
}
}
}

[authenticated=True] .manual {
border: 1px solid red;
}
.events-calendar {
width: 500px;
max-width: 1200px;
Expand Down

0 comments on commit 98d751a

Please sign in to comment.