2010-09-26 21:32:53 +00:00
from datetime import datetime , timedelta
2023-10-19 22:44:24 +00:00
from django . db import models
from . . staff . models import Person
from . . worldmap . models import EarthLocation
2010-09-26 21:32:53 +00:00
class EventTag ( models . Model ) :
""" Tagging for events
( currently unused )
"""
label = models . CharField ( max_length = 100 )
date_created = models . DateField ( auto_now_add = True )
2022-01-10 22:13:46 +00:00
def __str__ ( self ) :
2010-09-26 21:32:53 +00:00
return self . label
class PastEventManager ( models . Manager ) :
""" Returns all past events """
2015-03-03 18:40:18 +00:00
def get_queryset ( self ) :
2023-09-07 13:15:48 +00:00
return super ( ) . get_queryset ( ) . filter ( date__lt = datetime . today ( ) )
2010-09-26 21:32:53 +00:00
class FutureEventManager ( models . Manager ) :
""" Returns all future events """
2015-03-03 18:40:18 +00:00
def get_queryset ( self ) :
2023-09-07 13:15:48 +00:00
return super ( ) . get_queryset ( ) . filter ( date__gte = datetime . today ( ) )
2010-09-26 21:32:53 +00:00
class Event ( models . Model ) :
2010-09-26 21:54:29 +00:00
""" Model for Conservancy staff member events (presentations, etc) """
2010-09-26 21:32:53 +00:00
title = models . CharField ( max_length = 400 )
date = models . DateField ( )
2015-03-09 01:00:50 +00:00
date_tentative = models . BooleanField ( default = False )
2010-09-26 21:32:53 +00:00
datetime = models . CharField ( " Date and Time " , max_length = 300 , blank = True )
slug = models . SlugField ( unique_for_year = ' date ' )
description = models . TextField ( blank = True )
2021-12-17 06:25:38 +00:00
people = models . ManyToManyField ( Person , blank = True )
2010-09-26 21:32:53 +00:00
location = models . CharField ( max_length = 1000 )
2023-09-12 00:55:30 +00:00
earth_location = models . ForeignKey (
EarthLocation , null = True , blank = True , help_text = " Label will not be displayed " ,
on_delete = models . CASCADE
)
2021-12-17 06:25:38 +00:00
tags = models . ManyToManyField ( EventTag , blank = True )
2010-09-26 21:32:53 +00:00
date_created = models . DateTimeField ( auto_now_add = True )
date_last_modified = models . DateTimeField ( auto_now = True )
2023-09-07 13:15:48 +00:00
class Meta :
2010-09-26 21:32:53 +00:00
ordering = ( " -date " , )
2022-01-10 22:13:46 +00:00
def __str__ ( self ) :
2023-09-07 13:15:48 +00:00
return " {} ( {} ) " . format ( self . title , self . date )
2010-09-26 21:32:53 +00:00
def get_absolute_url ( self ) :
2023-09-07 13:15:48 +00:00
return " /events/ {} / {} / " . format ( self . date . strftime ( " % Y " ) , self . slug )
2010-09-26 21:32:53 +00:00
def day_after ( self ) :
return self . date + timedelta ( days = 1 )
# for aggregate feed
pub_date = property ( lambda self : self . date_created )
objects = models . Manager ( )
past = PastEventManager ( )
future = FutureEventManager ( )
class EventMedia ( models . Model ) :
""" Media from an event
includes transcripts , audio , and video pieces
"""
2023-09-12 00:55:30 +00:00
event = models . ForeignKey ( Event , on_delete = models . CASCADE )
2010-09-26 21:32:53 +00:00
format = models . CharField ( max_length = 1 ,
choices = ( ( ' T ' , ' Transcript ' ) ,
( ' A ' , ' Audio ' ) ,
( ' V ' , ' Video ' ) ) )
local = models . CharField ( max_length = 300 , blank = True ,
help_text = " Local filename of the resource. File should be uploaded into the static directory that corresponds to the event. " )
2015-03-03 18:40:18 +00:00
# verify_exists removed https://docs.djangoproject.com/en/1.7/releases/1.4/
remote = models . URLField ( blank = True ,
2010-09-26 21:32:53 +00:00
help_text = " Remote URL of the resource. Required if ' local ' is not given. " )
2015-03-09 01:00:50 +00:00
novel = models . BooleanField ( help_text = " Is it a new piece of media or another form of an old one? If it is new it will be included in the event-media RSS feed and shown on the front page for a bit. " , default = False )
2010-09-26 21:32:53 +00:00
date_created = models . DateTimeField ( auto_now_add = True )
date_last_modified = models . DateTimeField ( auto_now = True )
2023-09-07 13:15:48 +00:00
class Meta :
2010-09-26 21:32:53 +00:00
verbose_name_plural = ' event media '
2022-01-10 22:13:46 +00:00
def __str__ ( self ) :
2023-09-07 13:15:48 +00:00
return " {} media: {} " . format ( self . event , self . format )
2010-09-26 21:32:53 +00:00