class LocationDefaultEnvironment(models.Model): location = models.ForeignKey(Location) privacy = models.CharField(max_length=40, choices=Event.PRIVACY_CHOICES, default=Event.PRIVACY_PUBLIC) template = models.ForeignKey(Template) template_environment = EnvironmentField( help_text='Specify the template variables in the format' '<code>variable1=value</code>, one per line.') class Meta: unique_together = ('location', 'privacy', 'template')
class Event(models.Model): """ Events - all the essential data and metadata for publishing. """ title = models.CharField(max_length=200) slug = models.SlugField(blank=True, max_length=215, unique=True, db_index=True) template = models.ForeignKey(Template, blank=True, null=True, on_delete=models.SET_NULL) template_environment = EnvironmentField( blank=True, help_text='Specify the template variables in the format' '<code>variable1=value</code>, one per line.') STATUS_INITIATED = 'initiated' STATUS_SUBMITTED = 'submitted' STATUS_SCHEDULED = 'scheduled' STATUS_PENDING = 'pending' STATUS_PROCESSING = 'processing' STATUS_REMOVED = 'removed' STATUS_CHOICES = ((STATUS_SUBMITTED, 'Submitted'), (STATUS_SCHEDULED, 'Scheduled'), (STATUS_PENDING, 'Pending'), (STATUS_PROCESSING, 'Processing'), (STATUS_REMOVED, 'Removed')) status = models.CharField(max_length=20, choices=STATUS_CHOICES, default=STATUS_INITIATED, db_index=True) placeholder_img = ImageField( upload_to=_upload_path('event-placeholder'), blank=True, null=True, ) picture = models.ForeignKey('Picture', blank=True, null=True, related_name='event_picture', on_delete=models.SET_NULL) upload = models.ForeignKey('uploads.Upload', null=True, related_name='event_upload', on_delete=models.SET_NULL) description = models.TextField() short_description = models.TextField( blank=True, help_text='If not provided, this will be filled in by the first ' 'words of the full description.') start_time = models.DateTimeField(db_index=True) archive_time = models.DateTimeField(blank=True, null=True, db_index=True) location = models.ForeignKey(Location, blank=True, null=True, on_delete=models.SET_NULL) tags = models.ManyToManyField(Tag, blank=True) channels = models.ManyToManyField(Channel) call_info = models.TextField(blank=True) additional_links = models.TextField(blank=True) remote_presenters = models.TextField(blank=True, null=True) popcorn_url = models.URLField(null=True, blank=True) PRIVACY_PUBLIC = 'public' PRIVACY_COMPANY = 'company' PRIVACY_CONTRIBUTORS = 'contributors' PRIVACY_CHOICES = ( (PRIVACY_PUBLIC, 'Public'), (PRIVACY_CONTRIBUTORS, 'Contributors'), (PRIVACY_COMPANY, 'Staff'), ) privacy = models.CharField(max_length=40, choices=PRIVACY_CHOICES, default=PRIVACY_PUBLIC, db_index=True) featured = models.BooleanField(default=False, db_index=True) pin = models.CharField(max_length=20, null=True, blank=True) transcript = models.TextField(null=True) recruitmentmessage = models.ForeignKey(RecruitmentMessage, null=True, on_delete=models.SET_NULL) topics = models.ManyToManyField(Topic) duration = models.PositiveIntegerField(null=True) # seconds # Choices for when you enter a suggested event and specify the estimated # duration time. # This gets used both for SuggestedEvent and Event models. ESTIMATED_DURATION_CHOICES = ( (60 * 30, '30 minutes'), (60 * 60, '1 hour'), (60 * (60 + 30), '1 hour 30 minutes'), (60 * 60 * 2, '2 hours'), (60 * (60 * 2 + 30), '2 hours 30 minutes'), (60 * 60 * 3, '3 hours'), (60 * (60 * 3 + 30), '3 hours 30 minutes'), (60 * 60 * 4, '4 hours'), ) estimated_duration = models.PositiveIntegerField( default=60 * 60, # seconds null=True, ) mozillian = models.CharField(max_length=200, null=True) creator = models.ForeignKey(User, related_name='creator', blank=True, null=True, on_delete=models.SET_NULL) created = models.DateTimeField(auto_now_add=True) modified_user = models.ForeignKey(User, related_name='modified_user', blank=True, null=True, on_delete=models.SET_NULL) modified = models.DateTimeField(auto_now=True) objects = EventManager() class Meta: permissions = (('change_event_others', 'Can edit events created by other users'), ('add_event_scheduled', 'Can create events with scheduled status')) def __unicode__(self): return self.title def is_upcoming(self): return (self.archive_time is None and self.start_time > _get_live_time()) def is_removed(self): return self.status == self.STATUS_REMOVED def is_public(self): return self.privacy == self.PRIVACY_PUBLIC def is_scheduled(self): return self.status == self.STATUS_SCHEDULED def is_pending(self): return self.status == self.STATUS_PENDING def is_processing(self): return self.status == self.STATUS_PROCESSING def is_live(self): return (not self.archive_time and self.start_time and self.start_time < _get_live_time()) def needs_approval(self): if self.is_scheduled(): for approval in Approval.objects.filter(event=self): if approval.processed: return False if not approval.approved: return True return False def is_prerecorded(self): return not self.location_id def has_vidly_template(self): return self.template and 'Vid.ly' in self.template.name @property def location_time(self): assert self.location tz = pytz.timezone(self.location.timezone) return tz.normalize(self.start_time)
class Event(models.Model): """ Events - all the essential data and metadata for publishing. """ title = models.CharField(max_length=200) slug = models.SlugField(blank=True, max_length=215, unique=True, db_index=True) template = models.ForeignKey(Template, blank=True, null=True, on_delete=models.SET_NULL) template_environment = EnvironmentField( blank=True, help_text='Specify the template variables in the format' '<code>variable1=value</code>, one per line.') STATUS_INITIATED = 'initiated' STATUS_SUBMITTED = 'submitted' STATUS_SCHEDULED = 'scheduled' STATUS_PENDING = 'pending' STATUS_PROCESSING = 'processing' STATUS_REMOVED = 'removed' STATUS_CHOICES = ((STATUS_SUBMITTED, 'Submitted'), (STATUS_SCHEDULED, 'Scheduled'), (STATUS_PENDING, 'Pending'), (STATUS_PROCESSING, 'Processing'), (STATUS_REMOVED, 'Removed')) status = models.CharField(max_length=20, choices=STATUS_CHOICES, default=STATUS_INITIATED, db_index=True) placeholder_img = ImageField( upload_to=_upload_path_event_placeholder, blank=True, null=True, ) picture = models.ForeignKey('Picture', blank=True, null=True, related_name='event_picture', on_delete=models.SET_NULL) upload = models.ForeignKey('uploads.Upload', null=True, related_name='event_upload', on_delete=models.SET_NULL) description = models.TextField() short_description = models.TextField( blank=True, help_text='If not provided, this will be filled in by the first ' 'words of the full description.') start_time = models.DateTimeField(db_index=True) archive_time = models.DateTimeField(blank=True, null=True, db_index=True) location = models.ForeignKey(Location, blank=True, null=True, on_delete=models.SET_NULL) tags = models.ManyToManyField(Tag, blank=True) channels = models.ManyToManyField(Channel) call_info = models.TextField(blank=True) additional_links = models.TextField(blank=True) remote_presenters = models.TextField(blank=True, null=True) popcorn_url = models.URLField(null=True, blank=True) PRIVACY_PUBLIC = 'public' PRIVACY_COMPANY = 'company' PRIVACY_CONTRIBUTORS = 'contributors' PRIVACY_CHOICES = ( (PRIVACY_PUBLIC, 'Public'), (PRIVACY_CONTRIBUTORS, 'Contributors'), (PRIVACY_COMPANY, 'Staff'), ) privacy = models.CharField(max_length=40, choices=PRIVACY_CHOICES, default=PRIVACY_PUBLIC, db_index=True) featured = models.BooleanField(default=False, db_index=True) pin = models.CharField(max_length=20, null=True, blank=True) transcript = models.TextField(null=True) topics = models.ManyToManyField(Topic) duration = models.PositiveIntegerField(null=True) # seconds # Choices for when you enter a suggested event and specify the estimated # duration time. # This gets used both for SuggestedEvent and Event models. ESTIMATED_DURATION_CHOICES = ( (60 * 30, '30 minutes'), (60 * 60, '1 hour'), (60 * (60 + 30), '1 hour 30 minutes'), (60 * 60 * 2, '2 hours'), (60 * (60 * 2 + 30), '2 hours 30 minutes'), (60 * 60 * 3, '3 hours'), (60 * (60 * 3 + 30), '3 hours 30 minutes'), (60 * 60 * 4, '4 hours'), ) estimated_duration = models.PositiveIntegerField( default=60 * 60, # seconds null=True, ) creator = models.ForeignKey(User, related_name='creator', blank=True, null=True, on_delete=models.SET_NULL) created = models.DateTimeField(auto_now_add=True) modified_user = models.ForeignKey(User, related_name='modified_user', blank=True, null=True, on_delete=models.SET_NULL) modified = models.DateTimeField(auto_now=True) objects = EventManager() class Meta: permissions = (('change_event_others', 'Can edit events created by other users'), ('add_event_scheduled', 'Can create events with scheduled status')) def __unicode__(self): return self.title def is_upcoming(self): return (self.archive_time is None and self.start_time > _get_live_time()) def is_removed(self): return self.status == self.STATUS_REMOVED def is_public(self): return self.privacy == self.PRIVACY_PUBLIC def is_scheduled(self): return self.status == self.STATUS_SCHEDULED def is_pending(self): return self.status == self.STATUS_PENDING def is_processing(self): return self.status == self.STATUS_PROCESSING def is_live(self): return (not self.archive_time and self.start_time and self.start_time < _get_live_time() and self.status != self.STATUS_PROCESSING) def needs_approval(self): if self.is_scheduled(): for approval in Approval.objects.filter(event=self): if approval.processed: return False if not approval.approved: return True return False def is_prerecorded(self): return not self.location_id def has_vidly_template(self): return self.template and 'Vid.ly' in self.template.name @property def location_time(self): assert self.location tz = pytz.timezone(self.location.timezone) return tz.normalize(self.start_time) def has_unique_title(self): return not (Event.objects.filter(title=self.title).exclude( id=self.id).exists()) def get_unique_title(self): cache_key = 'unique_title_{}'.format(self.id) value = cache.get(cache_key) if value is None: value = self._get_unique_title() cache.set(cache_key, value, roughly(60 * 60 * 5)) else: # When it comes out of memcache (not LocMemCache) it comes # out as a byte string. smart_text() always returns a # unicode string even if you pass in a unicode string. value = smart_text(value) return value def _get_unique_title(self): if self.has_unique_title(): return self.title else: start_time = self.start_time if self.location: start_time = self.location_time return u'{}, {}'.format(self.title, start_time.strftime('%d %b %Y')) @property def metadata(self): items = [] qs = EventMetadata.objects.filter(event=self) for each in qs.order_by('created'): items.append((each.key, each.value)) return items @property def seconds_till_live(self): assert self.is_upcoming() diff = (self.start_time - timezone.now()).total_seconds() # but the live status starts before it actually begins diff -= settings.LIVE_MARGIN * 60 # LIVE_MARGIN is minutes # Round up so avoid hitting exactly on when it goes live return int(math.ceil(diff))
class Event(models.Model): """ Events - all the essential data and metadata for publishing. """ title = models.CharField(max_length=200) slug = models.SlugField(blank=True, max_length=215, unique=True, db_index=True) template = models.ForeignKey(Template, blank=True, null=True, on_delete=models.SET_NULL) template_environment = EnvironmentField( blank=True, help_text='Specify the template variables in the format' '<code>variable1=value</code>, one per line.') STATUS_INITIATED = 'initiated' STATUS_SCHEDULED = 'scheduled' STATUS_REMOVED = 'removed' STATUS_CHOICES = ((STATUS_INITIATED, 'Initiated'), (STATUS_SCHEDULED, 'Scheduled'), (STATUS_REMOVED, 'Removed')) status = models.CharField(max_length=20, choices=STATUS_CHOICES, default=STATUS_INITIATED, db_index=True) placeholder_img = ImageField(upload_to=_upload_path('event-placeholder')) description = models.TextField() short_description = models.TextField( blank=True, help_text='If not provided, this will be filled in by the first ' 'words of the full description.') start_time = models.DateTimeField(db_index=True) archive_time = models.DateTimeField(blank=True, null=True, db_index=True) participants = models.ManyToManyField( Participant, help_text='Speakers or presenters for this event.') location = models.ForeignKey(Location, blank=True, null=True, on_delete=models.SET_NULL) category = models.ForeignKey(Category, blank=True, null=True, on_delete=models.SET_NULL) tags = models.ManyToManyField(Tag, blank=True) channels = models.ManyToManyField(Channel) call_info = models.TextField(blank=True) additional_links = models.TextField(blank=True) remote_presenters = models.TextField(blank=True, null=True) PRIVACY_PUBLIC = 'public' PRIVACY_COMPANY = 'company' PRIVACY_CONTRIBUTORS = 'contributors' PRIVACY_CHOICES = ( (PRIVACY_PUBLIC, 'Public'), (PRIVACY_CONTRIBUTORS, 'Employees and contributors only'), (PRIVACY_COMPANY, 'Employees only'), ) privacy = models.CharField(max_length=40, choices=PRIVACY_CHOICES, default=PRIVACY_PUBLIC, db_index=True) featured = models.BooleanField(default=False, db_index=True) creator = models.ForeignKey(User, related_name='creator', blank=True, null=True, on_delete=models.SET_NULL) created = models.DateTimeField(auto_now_add=True) modified_user = models.ForeignKey(User, related_name='modified_user', blank=True, null=True, on_delete=models.SET_NULL) modified = models.DateTimeField(auto_now=True) objects = EventManager() class Meta: permissions = (('change_event_others', 'Can edit events created by other users'), ('add_event_scheduled', 'Can create events with scheduled status')) def __unicode__(self): return self.title def is_upcoming(self): return (self.archive_time is None and self.start_time > _get_live_time()) def is_removed(self): return self.status == self.STATUS_REMOVED def is_public(self): return self.privacy == self.PRIVACY_PUBLIC def is_scheduled(self): return self.status == self.STATUS_SCHEDULED def needs_approval(self): if self.is_scheduled(): for approval in Approval.objects.filter(event=self): if approval.processed: return False if not approval.approved: return True return False
class Event(models.Model): """ Events - all the essential data and metadata for publishing. """ title = models.CharField(max_length=200) slug = models.SlugField(blank=True, max_length=215, unique=True, db_index=True) template = models.ForeignKey(Template, blank=True, null=True, on_delete=models.SET_NULL) template_environment = EnvironmentField( blank=True, help_text='Specify the template variables in the format' '<code>variable1=value</code>, one per line.') STATUS_INITIATED = 'initiated' STATUS_SCHEDULED = 'scheduled' STATUS_REMOVED = 'removed' STATUS_CHOICES = ((STATUS_INITIATED, 'Initiated'), (STATUS_SCHEDULED, 'Scheduled'), (STATUS_REMOVED, 'Removed')) status = models.CharField(max_length=20, choices=STATUS_CHOICES, default=STATUS_INITIATED, db_index=True) placeholder_img = ImageField(upload_to=_upload_path('event-placeholder')) description = models.TextField() short_description = models.TextField( blank=True, help_text='If not provided, this will be filled in by the first ' 'words of the full description.') start_time = models.DateTimeField(db_index=True) archive_time = models.DateTimeField(blank=True, null=True, db_index=True) participants = models.ManyToManyField( Participant, help_text='Speakers or presenters for this event.') location = models.ForeignKey(Location, blank=True, null=True, on_delete=models.SET_NULL) category = models.ForeignKey(Category, blank=True, null=True, on_delete=models.SET_NULL) tags = models.ManyToManyField(Tag, blank=True) call_info = models.TextField(blank=True) additional_links = models.TextField(blank=True) public = models.BooleanField( default=False, help_text='Available to everyone (else MoCo only.)', db_index=True) featured = models.BooleanField(default=False, db_index=True) creator = models.ForeignKey(User, related_name='creator', blank=True, null=True, on_delete=models.SET_NULL) created = models.DateTimeField(auto_now_add=True) modified_user = models.ForeignKey(User, related_name='modified_user', blank=True, null=True, on_delete=models.SET_NULL) modified = models.DateTimeField(auto_now=True) objects = EventManager() class Meta: permissions = (('change_event_others', 'Can edit events created by other users'), ('add_event_scheduled', 'Can create events with scheduled status')) def is_upcoming(self): return (self.archive_time is None and self.start_time > _get_live_time()) def is_removed(self): return self.status == self.STATUS_REMOVED