-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
258 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
from hknweb.events.admin.attendance import ( | ||
AttendanceFormAdmin, | ||
AttendanceResponseAdmin, | ||
) | ||
from django.contrib import admin | ||
|
||
from hknweb.events.admin.attendance import AttendanceFormAdmin, AttendanceResponseAdmin | ||
from hknweb.events.admin.event import EventAdmin | ||
from hknweb.events.admin.event_type import EventTypeAdmin | ||
from hknweb.events.admin.google_calendar import ( | ||
GCalAccessLevelMappingAdmin, | ||
GoogleCalendarCredentialsAdmin, | ||
) | ||
from hknweb.events.admin.event import EventAdmin | ||
from hknweb.events.admin.event_type import EventTypeAdmin | ||
from hknweb.events.admin.ical_view import ICalViewAdmin | ||
from hknweb.events.admin.rsvp import RsvpAdmin | ||
|
||
from django.contrib import admin | ||
from hknweb.events.models import EventPhoto | ||
|
||
admin.site.register(EventPhoto) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from django.contrib import admin | ||
|
||
from hknweb.events.models import ICalView | ||
|
||
|
||
@admin.register(ICalView) | ||
class ICalViewAdmin(admin.ModelAdmin): | ||
fields = ["user", "show_rsvpd", "show_not_rsvpd"] | ||
list_display = ["id", "user"] | ||
search_fields = [ | ||
"user__username", | ||
"user__first_name", | ||
"user__last_name", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Generated by Django 4.2.5 on 2023-10-05 05:03 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
("events", "0011_eventphoto"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="ICalView", | ||
fields=[ | ||
( | ||
"id", | ||
models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
primary_key=True, | ||
serialize=False, | ||
), | ||
), | ||
("show_rsvpd", models.BooleanField(default=True)), | ||
("show_not_rsvpd", models.BooleanField(default=False)), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import random | ||
import uuid | ||
from datetime import datetime, timedelta | ||
|
||
import icalendar | ||
from django.conf import settings | ||
from django.db import models | ||
from django.urls import reverse | ||
|
||
from hknweb.events.models import Event | ||
from hknweb.events.utils import get_events | ||
|
||
|
||
class ICalView(models.Model): | ||
class Meta: | ||
verbose_name = "iCal view" | ||
|
||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) | ||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) | ||
show_rsvpd = models.BooleanField(default=True) | ||
show_not_rsvpd = models.BooleanField(default=False) | ||
|
||
@property | ||
def url(self): | ||
return reverse("events:ical", args=[self.id]) | ||
|
||
def to_ical_obj(self): | ||
cal = icalendar.Calendar() | ||
cal.add("prodid", "-//Eta Kappa Nu, Mu Chapter//Calendar//EN") | ||
cal.add("version", "2.0") | ||
cal.add("summary", f"HKN Personal Calendar for {self.user}") | ||
|
||
events = get_events(self.user, self.show_rsvpd, self.show_not_rsvpd) | ||
for event in events: | ||
cal.add_component(event.to_ical_obj()) | ||
|
||
cal.add_component(self.dummy_event()) | ||
return cal | ||
|
||
def dummy_event(self): | ||
# Google Calendar doesn't let you configure how often to sync iCal feeds | ||
# like Apple's Calendar app does. They say this can take up to 24 hours. | ||
|
||
# According to https://webapps.stackexchange.com/a/66686, they probably | ||
# look at how often the iCal feed itself changes and syncs more or less | ||
# frequently based on that. | ||
|
||
# So we add a dummy event in the far future that's randomized every time | ||
# the feed is requested in hopes of making Google Calendar sync faster. | ||
|
||
dt = datetime(3000, 1, 1) + timedelta(days=random.randrange(365)) | ||
|
||
event = icalendar.Event() | ||
event.add("uid", "dummy") | ||
event.add("summary", "Dummy Event") | ||
event.add( | ||
"description", | ||
"Randomized dummy event to make Google Calendar sync faster", | ||
) | ||
event.add("dtstart", dt) | ||
event.add("dtend", dt) | ||
event.add("dtstamp", dt) | ||
return event |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from hknweb.events.views.aggregate_displays import ( | ||
index, | ||
ical, | ||
get_leaderboard, | ||
photos, | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from hknweb.events.views.aggregate_displays.calendar import index | ||
from hknweb.events.views.aggregate_displays.calendar import ical, index | ||
from hknweb.events.views.aggregate_displays.leaderboard import get_leaderboard | ||
from hknweb.events.views.aggregate_displays.photos import photos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.