Skip to content

Commit

Permalink
change the MediaItem.published_it field to always require a date to b…
Browse files Browse the repository at this point in the history
…e set
  • Loading branch information
msb committed Sep 10, 2018
1 parent 2b7d55a commit 809931c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
19 changes: 19 additions & 0 deletions mediaplatform/migrations/0015_auto_20180910_1010.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.1.1 on 2018-09-10 10:10

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('mediaplatform', '0014_auto_20180905_1031'),
]

operations = [
migrations.AlterField(
model_name='mediaitem',
name='published_at',
field=models.DateTimeField(default=django.utils.timezone.now, help_text='Date from which video is visible'),
),
]
8 changes: 4 additions & 4 deletions mediaplatform/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from django.utils import timezone

import dataclasses
import itertools
Expand Down Expand Up @@ -84,7 +84,7 @@ class MediaItemQuerySet(PermissionQuerySetMixin, models.QuerySet):
def _viewable_condition(self, user):
# The item can be viewed if the user has view permission and the item is published.
# Overriding this, the item can be viewed if the user has edit permission.
published = models.Q(published_at__isnull=True) | models.Q(published_at__lt=datetime.now())
published = models.Q(published_at__isnull=True) | models.Q(published_at__lt=timezone.now())
return (
(self._permission_condition('view_permission', user) & published) |
Q(self._permission_condition('channel__edit_permission', user))
Expand Down Expand Up @@ -214,7 +214,7 @@ class Source:
TYPE_CHOICES = ((VIDEO, 'Video'), (AUDIO, 'Audio'))

LANGUAGE_CHOICES = tuple(itertools.chain([('', 'None')], sorted(
((language.part3, language.name) for language in languages if language.part3),
((language.part3, language.name) for language in languages if language.part3 != ''),
key=lambda choice: choice[1]
)))

Expand Down Expand Up @@ -251,7 +251,7 @@ class Source:

#: Publication date (we take null to mean it is published)
published_at = models.DateTimeField(
null=True, blank=True, help_text='Date from which video is visible')
default=timezone.now, help_text='Date from which video is visible')

#: Downloadable flag
downloadable = models.BooleanField(
Expand Down
2 changes: 0 additions & 2 deletions mediaplatform_jwp/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ def update_related_models_from_cache(update_all_videos=False):
if published_timestamp is not None:
item.published_at = datetime.datetime.fromtimestamp(
published_timestamp, pytz.utc)
else:
item.published_at = None

item.duration = _default_if_none(video.get('duration'), 0.)

Expand Down
11 changes: 0 additions & 11 deletions mediaplatform_jwp/tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,6 @@ def test_update_deleted_item(self):
i1_v2.updated_at,
mpmodels.MediaItem.objects_including_deleted.get(id=i1.id).updated_at)

def test_assigns_publication_date(self):
"""If the JWP video has no published timestamp, it defaults to None to avoid accidental
publication.
"""
v1 = make_video()
del v1['date']
set_resources_and_sync([v1])
i1 = mpmodels.MediaItem.objects.get(jwp__key=v1.key)
self.assertIsNone(i1.published_at)

def test_basic_acl(self):
"""A video with no ACL maps to a Permission which denies everything."""
v1, = set_resources_and_sync([make_video(acl=[])])
Expand Down

0 comments on commit 809931c

Please sign in to comment.