Skip to content

Commit

Permalink
Events calendar update: Don't request location every wp api event lik…
Browse files Browse the repository at this point in the history
…e an idiot, update character set for more text fields, update styling for better readability
  • Loading branch information
SamuelmdLow committed Sep 12, 2024
1 parent 7f3394c commit b791ec8
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2 on 2024-09-12 06:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('events', '0004_event_hash'),
]

operations = [
migrations.AlterField(
model_name='event',
name='address',
field=models.CharField(blank=True, db_collation='utf8mb4_general_ci', max_length=255, null=True),
),
migrations.AlterField(
model_name='event',
name='host',
field=models.CharField(blank=True, db_collation='utf8mb4_general_ci', max_length=255, null=True),
),
migrations.AlterField(
model_name='event',
name='location',
field=models.CharField(blank=True, db_collation='utf8mb4_general_ci', max_length=255, null=True),
),
]
31 changes: 24 additions & 7 deletions events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ async def ical_create_event(self, ical_component, name, instructions):
async def read_wp_events_api(self, name, api, categorize):
try:
#print("Requesting " + name)
locations = {}
async with aiohttp.ClientSession(headers={'User-Agent': "The Ubyssey https://ubyssey.ca/"}) as session:
async with session.get(api + 'event-venues/?per_page=100') as response:
result = json.loads(await response.text())
for l in result:
locations[l['id']] = {
'name': l['name'],
'address': l['address'],
'city': l['city'],
'state': l['state'],
}
async with aiohttp.ClientSession(headers={'User-Agent': "The Ubyssey https://ubyssey.ca/"}) as session:
async with session.get(api + "events/?event_end_after=" + (timezone.now()-timedelta(days=7)).strftime("%Y-%m-%d") + "T00:00:00&page=1&per_page=20") as response:

Expand All @@ -123,15 +134,15 @@ async def read_wp_events_api(self, name, api, categorize):

tasks = []
for i in result:
tasks.append(asyncio.create_task(self.wp_events_api_create_event(i, api, name, categorize)))
tasks.append(asyncio.create_task(self.wp_events_api_create_event(i, api, name, categorize, locations)))

await asyncio.gather(*tasks)

print(name + " finished " + str(len(tasks)) + " tasks")
except:
print("Failed requesting to " + name)

async def wp_events_api_create_event(self, event_json, api, host, categorize):
async def wp_events_api_create_event(self, event_json, api, host, categorize, locations):
if not await self.filter(event_url=event_json['link'], start_time=datetime.fromisoformat(event_json['start']).astimezone(timezone.get_current_timezone())).aexists():
event = await self.acreate(
title=event_json['title'],
Expand All @@ -154,11 +165,14 @@ async def wp_events_api_create_event(self, event_json, api, host, categorize):
event.end_time = datetime.fromisoformat(event_json['end']).astimezone(timezone.get_current_timezone())

if len(event_json['event-venues']) > 0:
async with aiohttp.ClientSession(headers={'User-Agent': "The Ubyssey https://ubyssey.ca/"}) as session:
async with session.get(api + 'event-venues/' + str(event_json['event-venues'][0])) as response:
venue = json.loads(await response.text())
event.location=str(venue['name'].encode('utf-8'), 'UTF-8')
event.address=str((venue['address'] + ", " + venue['city'] + ", " + venue['state']).encode('utf-8'), 'UTF-8')
if event_json['event-venues'][0] in locations:
venue = locations[event_json['event-venues'][0]]
else:
async with aiohttp.ClientSession(headers={'User-Agent': "The Ubyssey https://ubyssey.ca/"}) as session:
async with session.get(api + 'event-venues/' + str(event_json['event-venues'][0])) as response:
venue = json.loads(await response.text())
event.location=str(venue['name'].encode('utf-8'), 'UTF-8')
event.address=str((venue['address'] + ", " + venue['city'] + ", " + venue['state']).encode('utf-8'), 'UTF-8')
else:
event.location=''
event.address=''
Expand Down Expand Up @@ -767,16 +781,19 @@ class Event(models.Model):
max_length=255,
blank=True,
null=True,
db_collation = "utf8mb4_general_ci",
)
address = models.CharField(
max_length=255,
blank=True,
null=True,
db_collation = "utf8mb4_general_ci",
)
host = models.CharField(
max_length=255,
blank=True,
null=True,
db_collation = "utf8mb4_general_ci",
)
email = models.CharField(
max_length=255,
Expand Down
1 change: 1 addition & 0 deletions ubyssey/static_src/src/js/components/Events/calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ function EventsCalendar({events}) {
hosts.push(event.host);
}
}
hosts.sort();
return hosts;
}

Expand Down
35 changes: 29 additions & 6 deletions ubyssey/static_src/src/styles/components/events/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,17 @@ h2.events-calendar--month {

div.day{
min-height: 4em;
padding: 1em;
padding: 1em 0.5em;
font-size: 12px;

&:first-child {
padding-left: 1em;
}

&:last-child {
padding-right: 1em;
}

li {
border: 2px solid transparent;
font-family: noto-sans;
Expand Down Expand Up @@ -203,14 +211,9 @@ div.day{
margin: 0.3em 0;
padding-inline: 0.25em;
border-radius: 0.5em;
height: 1.5em;
max-width: 400px;

background-color: var(--highlight);

white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
line-height: 1.5em;
b {
text-transform: lowercase;
Expand All @@ -220,6 +223,14 @@ div.day{
}

@media($bp-larger-than-phablet) {

div.day li {
height: 1.5em;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

.events-calendar--row:first-child div.day:first-of-type {
border-radius: 0.5em 0 0 0;
}
Expand Down Expand Up @@ -265,6 +276,14 @@ button.events-calendar--number {
white-space: initial !important;
overflow: unset !important;
height: auto !important;
a {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
line-clamp: 5;
-webkit-line-clamp: 5;
-webkit-box-orient: vertical;
}
}
}

Expand Down Expand Up @@ -386,6 +405,7 @@ header.events{
width: 100%;
height: 0;
position: fixed;
font-size: 0.9em;
dialog {
padding: 1em;
display: block;
Expand Down Expand Up @@ -429,6 +449,9 @@ header.events{
padding: 1.5em;
li {
margin-right: 2em;
b {
display: block;
}
}
}
.events-calendar--rows .events-calendar--row:first-child .events-calendar--month {
Expand Down

0 comments on commit b791ec8

Please sign in to comment.