Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Video.priority #137

Merged
merged 3 commits into from
Jan 25, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Video.priority
  • Loading branch information
bhrutledge committed Jan 25, 2020
commit aa3bb7b742c00fa9983e4371fb68d7183cc36694
20 changes: 20 additions & 0 deletions hth/music/migrations/0013_video_priority.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.27 on 2020-01-25 11:27
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('music', '0012_auto_20160704_1559'),
]

operations = [
migrations.AddField(
model_name='video',
name='priority',
field=models.PositiveIntegerField(blank=True, help_text='Site-wide sort order (higher numbers first)', null=True),
),
]
5 changes: 4 additions & 1 deletion hth/music/models.py
Original file line number Diff line number Diff line change
@@ -102,9 +102,12 @@ class Video(PublishedModel, TitledModel):
description = models.TextField(blank=True)
credits = models.TextField(blank=True)
release = models.ForeignKey(Release, blank=True, null=True)
priority = models.PositiveIntegerField(
help_text='Site-wide sort order (higher numbers first)',
blank=True, null=True)

class Meta:
ordering = ['publish', '-publish_on']
ordering = ['-priority', 'publish', '-publish_on']

def save(self, *args, **kwargs):
if self.source_url and not (self.preview_url and self.embed_code):
41 changes: 41 additions & 0 deletions hth/music/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -112,6 +112,25 @@ def test_ordered_by_date(self):

self.assertEqual(list(Video.objects.all()), [draft, new, first, old])

def test_ordered_by_priority(self):
third = PublishedVideoFactory.create(
publish_on=datetime(2014, 8, 1, tzinfo=timezone.utc),
priority=1)

first = PublishedVideoFactory.create(
publish_on=datetime(2014, 7, 31, tzinfo=timezone.utc),
priority=10)

fourth = PublishedVideoFactory.create(
publish_on=datetime(2014, 7, 1, tzinfo=timezone.utc))

second = PublishedVideoFactory.create(
publish_on=datetime(2014, 8, 31, tzinfo=timezone.utc),
priority=1)

self.assertEqual(list(Video.objects.all()),
[first, second, third, fourth])

def test_can_be_added_to_release(self):
r = PublishedReleaseFactory.create()

@@ -138,6 +157,28 @@ def test_release_videos_ordered_by_date(self):

self.assertEqual(list(r.videos.all()), [new, first, old])

def test_release_videos_ordered_by_priority(self):
r = PublishedReleaseFactory.create()

third = PublishedVideoFactory.create(
publish_on=datetime(2014, 8, 1, tzinfo=timezone.utc),
priority=1, release=r)

first = PublishedVideoFactory.create(
publish_on=datetime(2014, 7, 31, tzinfo=timezone.utc),
priority=10, release=r)

fourth = PublishedVideoFactory.create(
publish_on=datetime(2014, 7, 1, tzinfo=timezone.utc),
release=r)

second = PublishedVideoFactory.create(
publish_on=datetime(2014, 8, 31, tzinfo=timezone.utc),
priority=1, release=r)

self.assertEqual(list(r.videos.all()),
[first, second, third, fourth])


class VideoAutofillTestCase(TestCase):