2024-01-04 11:54:56 +11:00
|
|
|
"""group models"""
|
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
from .utils import Announcement, Category, GroupType
|
|
|
|
|
|
|
|
|
|
|
|
class Group(models.Model):
|
|
|
|
"""a group on email, discord, slack etc"""
|
|
|
|
|
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)
|
|
|
|
type = models.CharField(choices=GroupType.choices, max_length=4)
|
|
|
|
url = models.URLField(max_length=400, unique=True)
|
|
|
|
registration_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-07 16:58:56 +11:00
|
|
|
contact_email = models.EmailField(blank=True, null=True)
|
2024-01-04 11:54:56 +11:00
|
|
|
announced = models.BooleanField(default=False)
|
|
|
|
approved = models.BooleanField(default=False)
|
|
|
|
pub_date = models.DateTimeField(null=True, default=None)
|
|
|
|
|
|
|
|
def announce(self):
|
|
|
|
"""create a group announcement"""
|
|
|
|
|
|
|
|
category = Category(self.category).label
|
|
|
|
type = GroupType(self.type).label
|
|
|
|
status = f"{self.name} is a {type} about {category}!\n\nJoin them: {self.registration_url}"
|
|
|
|
|
|
|
|
Announcement.objects.create(status=status)
|
|
|
|
self.announced = True
|
|
|
|
super().save()
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
if not self.pub_date:
|
|
|
|
self.pub_date = timezone.now()
|
|
|
|
super().save(*args, **kwargs)
|