From b8f1c52613d6b9b6dafbf339f42e497308e08e2f Mon Sep 17 00:00:00 2001 From: j Date: Mon, 11 Oct 2021 13:55:45 +0100 Subject: [PATCH] cleanup, better admin --- .gitignore | 1 + app/static/css/partials/_film.scss | 9 -------- app/static/css/partials/_text.scss | 22 +++++++++++++++++-- app/templates/films.html | 2 +- app/templates/texts.html | 3 ++- app/text/admin.py | 7 +++++- .../0004_rename_teaser_text_byline.py | 18 +++++++++++++++ app/text/migrations/0005_alter_page_slug.py | 18 +++++++++++++++ app/text/migrations/0006_text_position.py | 18 +++++++++++++++ app/text/models.py | 7 +++--- app/text/views.py | 12 +++++++--- app/video/admin.py | 7 +++++- app/video/migrations/0003_film_position.py | 18 +++++++++++++++ app/video/models.py | 4 +++- app/video/views.py | 2 +- 15 files changed, 124 insertions(+), 24 deletions(-) create mode 100644 app/text/migrations/0004_rename_teaser_text_byline.py create mode 100644 app/text/migrations/0005_alter_page_slug.py create mode 100644 app/text/migrations/0006_text_position.py create mode 100644 app/video/migrations/0003_film_position.py diff --git a/.gitignore b/.gitignore index 467e24f..474786d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ db.sqlite3 www/ *.swp venv +*.swo diff --git a/app/static/css/partials/_film.scss b/app/static/css/partials/_film.scss index e37f536..cc8cc8f 100644 --- a/app/static/css/partials/_film.scss +++ b/app/static/css/partials/_film.scss @@ -10,14 +10,6 @@ } .film { margin-bottom: 16px; - display: flex; - flex-direction: row; - .left, .right { - width: 50%; - img { - max-width: 100%; - } - } h1 { font-weight: bold; font-size: 20px; @@ -26,7 +18,6 @@ @media screen and (max-width: 799px) { .film { margin-bottom: 16px; - flex-direction: column; h2 { margin-bottom: 8px; } diff --git a/app/static/css/partials/_text.scss b/app/static/css/partials/_text.scss index 369ce44..6d97f58 100644 --- a/app/static/css/partials/_text.scss +++ b/app/static/css/partials/_text.scss @@ -1,8 +1,26 @@ .texts { - .text { - margin: 8px; + box-sizing: border-box; + + a { + color: #e00; + text-decoration: none; } + .text { + margin: 8px; + h1 { + font-weight: bold; + font-size: 20px; + } + } + @media screen and (max-width: 799px) { + .text { + margin-bottom: 16px; + h2 { + margin-bottom: 8px; + } + } + } } diff --git a/app/templates/films.html b/app/templates/films.html index 0be24ab..64eb72d 100644 --- a/app/templates/films.html +++ b/app/templates/films.html @@ -3,7 +3,7 @@
{% for film in films %}
-

{{ film.data.title | safe }}

+

{{ film.data.title | safe }}

{{ film.data.director|join:", "|safe }}

{% endfor %} diff --git a/app/templates/texts.html b/app/templates/texts.html index 9c7d616..2efe256 100644 --- a/app/templates/texts.html +++ b/app/templates/texts.html @@ -4,7 +4,8 @@
{% for text in texts %}
- {{ text.title }} +

{{ text.title | safe }}

+

{{ text.byline|safe }}

{% endfor %} {% endblock %} diff --git a/app/text/admin.py b/app/text/admin.py index f9f28e5..389a8ce 100644 --- a/app/text/admin.py +++ b/app/text/admin.py @@ -5,7 +5,12 @@ from . import models @admin.decorators.register(models.Text) class TextAdmin(admin.ModelAdmin): - pass + list_display = ( + '__str__', + 'position', + 'slug', + 'public', + ) @admin.decorators.register(models.Page) class PageAdmin(admin.ModelAdmin): diff --git a/app/text/migrations/0004_rename_teaser_text_byline.py b/app/text/migrations/0004_rename_teaser_text_byline.py new file mode 100644 index 0000000..e8fc2be --- /dev/null +++ b/app/text/migrations/0004_rename_teaser_text_byline.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.7 on 2021-10-11 12:35 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('text', '0003_auto_20211011_1222'), + ] + + operations = [ + migrations.RenameField( + model_name='text', + old_name='teaser', + new_name='byline', + ), + ] diff --git a/app/text/migrations/0005_alter_page_slug.py b/app/text/migrations/0005_alter_page_slug.py new file mode 100644 index 0000000..a4e21cc --- /dev/null +++ b/app/text/migrations/0005_alter_page_slug.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.7 on 2021-10-11 12:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('text', '0004_rename_teaser_text_byline'), + ] + + operations = [ + migrations.AlterField( + model_name='page', + name='slug', + field=models.SlugField(blank=True, unique=True), + ), + ] diff --git a/app/text/migrations/0006_text_position.py b/app/text/migrations/0006_text_position.py new file mode 100644 index 0000000..7e91575 --- /dev/null +++ b/app/text/migrations/0006_text_position.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.7 on 2021-10-11 12:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('text', '0005_alter_page_slug'), + ] + + operations = [ + migrations.AddField( + model_name='text', + name='position', + field=models.IntegerField(default=0), + ), + ] diff --git a/app/text/models.py b/app/text/models.py index 897d92b..9f67998 100644 --- a/app/text/models.py +++ b/app/text/models.py @@ -12,12 +12,10 @@ class Page(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) - slug = models.SlugField(blank=True) + slug = models.SlugField(blank=True, unique=True) public = models.BooleanField(default=False) - title = models.TextField(blank=True) - #teaser = models.TextField(blank=True) body = models.TextField(blank=True) data = models.JSONField(default=dict, blank=True) @@ -37,9 +35,10 @@ class Text(models.Model): slug = models.SlugField() public = models.BooleanField(default=False) + position = models.IntegerField(default=0) title = models.TextField() - teaser = models.TextField(default="", blank=True) + byline = models.TextField(default="", blank=True) body = models.TextField(default="", blank=True) data = models.JSONField(default=dict) diff --git a/app/text/views.py b/app/text/views.py index e5d1b19..49fd11a 100644 --- a/app/text/views.py +++ b/app/text/views.py @@ -12,7 +12,10 @@ def index(request): def page(request, slug=''): context = {} - page = models.Page.objects.filter(slug=slug, public=True).first() + if request.user.is_staff: + page = models.Page.objects.filter(slug=slug).first() + else: + page = models.Page.objects.filter(slug=slug, public=True).first() if page: context['page'] = page return render(request, 'page.html', context) @@ -24,10 +27,13 @@ def about(request): def texts(request): context = {} - context['texts'] = models.Text.objects.filter(public=True).order_by('created') + context['texts'] = models.Text.objects.filter(public=True).order_by('position', 'created') return render(request, 'texts.html', context) def text(request, slug): context = {} - context['text'] = get_object_or_404(models.Text, slug=slug) + if request.user.is_staff: + context['text'] = get_object_or_404(models.Text, slug=slug) + else: + context['text'] = get_object_or_404(models.Text, slug=slug, public=True) return render(request, 'text.html', context) diff --git a/app/video/admin.py b/app/video/admin.py index c0d501f..9f9a0b2 100644 --- a/app/video/admin.py +++ b/app/video/admin.py @@ -5,7 +5,12 @@ from . import models @admin.decorators.register(models.Film) class FilmAdmin(admin.ModelAdmin): - pass + list_display = ( + '__str__', + 'position', + 'slug', + 'public', + ) @admin.decorators.register(models.Edit) class EditAdmin(admin.ModelAdmin): diff --git a/app/video/migrations/0003_film_position.py b/app/video/migrations/0003_film_position.py new file mode 100644 index 0000000..80c888e --- /dev/null +++ b/app/video/migrations/0003_film_position.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.7 on 2021-10-11 12:47 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('video', '0002_auto_20210930_1527'), + ] + + operations = [ + migrations.AddField( + model_name='film', + name='position', + field=models.IntegerField(default=0), + ), + ] diff --git a/app/video/models.py b/app/video/models.py index c42c323..c310c49 100644 --- a/app/video/models.py +++ b/app/video/models.py @@ -1,5 +1,6 @@ import logging +from django.conf import settings from django.contrib.auth import get_user_model from django.db import models @@ -13,9 +14,10 @@ class Film(models.Model): slug = models.SlugField() public = models.BooleanField(default=False) + position = models.IntegerField(default=0) padma_id = models.CharField(max_length=255) - vimeo_id = models.CharField(max_length=255, default=None, null=True) + vimeo_id = models.CharField(max_length=255, default=None, blank=True) data = models.JSONField(default=dict, blank=True) diff --git a/app/video/views.py b/app/video/views.py index cd745b9..ce0068e 100644 --- a/app/video/views.py +++ b/app/video/views.py @@ -6,7 +6,7 @@ from . import models def films(request): context = {} - context['films'] = models.Film.objects.filter(public=True).order_by('data__title') + context['films'] = models.Film.objects.filter(public=True).order_by('position', 'data__title') context['settings'] = settings return render(request, 'films.html', context)