From 21dab42524cd72c10c14fd5a67a52a118968b8a5 Mon Sep 17 00:00:00 2001 From: Sanjay B Date: Thu, 28 Oct 2021 15:42:34 +0530 Subject: [PATCH 1/2] add language field to text model, output en and zh texts separately, refs #30 --- app/templates/texts.html | 11 +++++++-- app/text/admin.py | 3 ++- .../migrations/0008_auto_20211028_1007.py | 23 +++++++++++++++++++ app/text/models.py | 9 ++++++-- app/text/views.py | 4 +++- 5 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 app/text/migrations/0008_auto_20211028_1007.py diff --git a/app/templates/texts.html b/app/templates/texts.html index 02897aa..4b9bd77 100644 --- a/app/templates/texts.html +++ b/app/templates/texts.html @@ -3,10 +3,17 @@ {% block main %}
- {% for text in texts %} -
+ {% for text in en_texts %} +

{{ text.title | safe }}

{{ text.byline|striptags }}

{% endfor %} + {% for text in zh_texts %} +
+

{{ text.title | safe }}

+

{{ text.byline|striptags }}

+
+ {% endfor %} +
{% endblock %} diff --git a/app/text/admin.py b/app/text/admin.py index 00a8b9f..aed4364 100644 --- a/app/text/admin.py +++ b/app/text/admin.py @@ -9,11 +9,12 @@ class TextAdmin(admin.ModelAdmin): '__str__', 'item', 'edit', + 'language', 'slug', 'public', 'position', ) - + list_editable = ['public', 'language'] def item(self, obj): return obj.data.get('item') def edit(self, obj): diff --git a/app/text/migrations/0008_auto_20211028_1007.py b/app/text/migrations/0008_auto_20211028_1007.py new file mode 100644 index 0000000..638b0c6 --- /dev/null +++ b/app/text/migrations/0008_auto_20211028_1007.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.7 on 2021-10-28 10:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('text', '0007_text_annotations'), + ] + + operations = [ + migrations.AddField( + model_name='text', + name='language', + field=models.CharField(choices=[('en', 'EN'), ('zh', 'ZH')], default='en', max_length=8), + ), + migrations.AlterField( + model_name='text', + name='annotations', + field=models.JSONField(blank=True, default=dict, editable=False), + ), + ] diff --git a/app/text/models.py b/app/text/models.py index f61238e..c28d7ea 100644 --- a/app/text/models.py +++ b/app/text/models.py @@ -32,14 +32,19 @@ class Page(models.Model): return '/' + settings.URL_PREFIX[:-1] +LANGUAGE_CHOICES = ( + ('en', 'EN'), + ('zh', 'ZH'), +) + class Text(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) - + language = models.CharField(choices=LANGUAGE_CHOICES, max_length=8, default='en') slug = models.SlugField() public = models.BooleanField(default=False) position = models.IntegerField(default=0) - + title = models.TextField() byline = models.TextField(default="", blank=True) body = models.TextField(default="", blank=True) diff --git a/app/text/views.py b/app/text/views.py index f6c14d8..23217de 100755 --- a/app/text/views.py +++ b/app/text/views.py @@ -36,7 +36,9 @@ def about(request): def texts(request): context = {} - context['texts'] = models.Text.objects.filter(public=True).order_by('position', 'created') + all_texts = models.Text.objects.filter(public=True).order_by('position', 'created') + context['en_texts'] = all_texts.filter(language='en') + context['zh_texts'] = all_texts.filter(language='zh') return render(request, 'texts.html', context) def text(request, slug): From 81d4df0b32213322a33ad2c6dc669dba53ab9c7b Mon Sep 17 00:00:00 2001 From: imohkay Date: Thu, 28 Oct 2021 16:00:36 +0530 Subject: [PATCH 2/2] split en and zh into 2 columns for assemblies --- app/static/css/partials/_film.scss | 1 + app/static/css/partials/_text.scss | 14 ++++++++++++++ app/templates/texts.html | 28 +++++++++++++++++----------- 3 files changed, 32 insertions(+), 11 deletions(-) mode change 100644 => 100755 app/templates/texts.html diff --git a/app/static/css/partials/_film.scss b/app/static/css/partials/_film.scss index 483c7e1..8b90eaf 100755 --- a/app/static/css/partials/_film.scss +++ b/app/static/css/partials/_film.scss @@ -67,6 +67,7 @@ main > .film { max-width: 250px; } + .texts { margin-top: var(--spacing-2); margin-bottom: var(--spacing-2); diff --git a/app/static/css/partials/_text.scss b/app/static/css/partials/_text.scss index e0e602a..119c1a7 100755 --- a/app/static/css/partials/_text.scss +++ b/app/static/css/partials/_text.scss @@ -102,3 +102,17 @@ main > .about { } } + +.assemblies { + &.row { + @media only screen and (max-width: 799px) { + flex-direction: column; + } + } + + .col { + @media only screen and (min-width: 800px) { + width: 50%; + } + } +} diff --git a/app/templates/texts.html b/app/templates/texts.html old mode 100644 new mode 100755 index 4b9bd77..9e5ef04 --- a/app/templates/texts.html +++ b/app/templates/texts.html @@ -3,17 +3,23 @@ {% block main %}
- {% for text in en_texts %} -
-

{{ text.title | safe }}

-

{{ text.byline|striptags }}

+
+
+ {% for text in en_texts %} +
+

{{ text.title | safe }}

+

{{ text.byline|striptags }}

+
+ {% endfor %} +
+
+ {% for text in zh_texts %} +
+

{{ text.title | safe }}

+

{{ text.byline|striptags }}

+
+ {% endfor %} +
- {% endfor %} - {% for text in zh_texts %} -
-

{{ text.title | safe }}

-

{{ text.byline|striptags }}

-
- {% endfor %}
{% endblock %}