ausglamr/blogs/models/event.py

80 lines
2.7 KiB
Python
Raw Normal View History

2024-01-04 11:54:56 +11:00
"""event models"""
from django.db import models
from django.utils import timezone
from .utils import Announcement, Category
class Event(models.Model):
"""a event"""
2024-01-09 18:11:22 +11:00
name = models.CharField(max_length=100)
2024-01-04 11:54:56 +11:00
category = models.CharField(choices=Category.choices, max_length=4)
url = models.URLField(max_length=400, unique=True)
2024-01-09 18:11:22 +11:00
description = models.TextField(null=True, blank=True, max_length=250)
2024-01-26 11:00:26 +11:00
pubdate = models.DateTimeField() # for RSS feed
2024-01-04 11:54:56 +11:00
start_date = models.DateField()
announcements = models.IntegerField(null=True, blank=True, default=0)
activitypub_account_name = models.CharField(max_length=200, blank=True, null=True)
2024-01-07 16:58:56 +11:00
contact_email = models.EmailField(blank=True, null=True)
2024-01-04 11:54:56 +11:00
approved = models.BooleanField(default=False)
def save(self, *args, **kwargs):
2024-01-26 11:00:26 +11:00
if not self.pubdate:
self.pubdate = timezone.now()
2024-01-04 11:54:56 +11:00
super().save(*args, **kwargs)
def __str__(self):
"""display for admin dropdowns"""
return self.name
def get_absolute_url(self):
"""override for rss feed"""
return self.url
def announce(self):
"""announce a event"""
date = self.start_date.strftime("%a %d %b %Y")
category = Category(self.category).label
name = self.name
if self.activitypub_account_name:
name = f"{self.name} ({self.activitypub_account_name})"
status = (
f"{name} is a event about {category}, starting on {date}!\n\n{self.url}"
)
Announcement.objects.create(status=status)
self.announcements = self.announcements + 1
super().save()
class CallForPapers(models.Model):
"""a event call for papers/presentations"""
name = models.CharField(
2024-01-09 18:11:22 +11:00
max_length=100
2024-01-04 11:54:56 +11:00
) # "Call for papers", "call for participation" etc
2024-01-09 18:11:22 +11:00
details = models.TextField(null=True, blank=True, max_length=250)
2024-01-26 11:00:26 +11:00
pubdate = models.DateTimeField(null=True, default=timezone.now)
2024-01-04 11:54:56 +11:00
opening_date = models.DateField()
closing_date = models.DateField()
announcements = models.IntegerField(null=True, default=0)
event = models.ForeignKey(Event, on_delete=models.CASCADE, related_name="cfp")
approved = models.BooleanField(default=False)
def announce(self):
"""create a call for papers announcement"""
opening_date = self.opening_date.strftime("%a %d %b %Y")
closing_date = self.closing_date.strftime("%a %d %b %Y")
status = f"{self.event.name} {self.name } is open from {opening_date}, closing on {closing_date}!\n\nMore info at {self.event.url}"
if self.event.approved:
Announcement.objects.create(status=status)
self.announcements = self.announcements + 1
super().save()