From ccd41e3de50460769aeeaf283e844b68e11db520 Mon Sep 17 00:00:00 2001 From: Nordstrand Date: Wed, 3 Aug 2022 15:29:08 +0200 Subject: [PATCH] Rework frontpage (#368) * Point frontpage to LAN, add news to navbar, fix navbar overflow * Add alternative LAN schedule link --- CHANGELOG.md | 3 + apps/competition/views.py | 11 ++- apps/lan/migrations/0025_lan_schedule_link.py | 20 ++++ apps/lan/models.py | 1 + apps/lan/views.py | 9 +- apps/news/views.py | 9 +- locale/nb/LC_MESSAGES/django.po | 10 +- studlan/urls.py | 4 +- templates/lan/details.html | 4 +- templates/lan/stream.html | 21 ++++ templates/navigation.html | 29 +++--- templates/news/archive.html | 5 +- templates/news/article_tags.html | 6 +- templates/news/frontpage.html | 95 +++++++++++++++++++ templates/news/news.html | 60 +----------- 15 files changed, 193 insertions(+), 94 deletions(-) create mode 100644 apps/lan/migrations/0025_lan_schedule_link.py create mode 100644 templates/lan/stream.html create mode 100644 templates/news/frontpage.html diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d332e76..f70ddf8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added marketing email opt-in for users on sign-up and profile pages. - Added payment logging. - Added optional colored borders for ticket on the ticket page. +- Added optional alternative schedule link for LANs. ### Changed @@ -20,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Made the site domain in emails use the site framework domain, so make sure it's set properly. - Updated default logging settings. - Made age check fail for people over 150 years. +- Made frontpage redirect to LAN instead of showing news, and replace LAN button on navbar with news button. ### Deprecated @@ -28,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed graceful shutdown for production mode. +- Fixed navbar overflow for medium screen sizes. ### Security diff --git a/apps/competition/views.py b/apps/competition/views.py index d4444443..566188a7 100644 --- a/apps/competition/views.py +++ b/apps/competition/views.py @@ -347,12 +347,15 @@ def translate_competitions(competitions): def schedule(request): lans = LAN.objects.filter(end_date__gt=datetime.now()).order_by('-start_date') - if lans.count() == 1: - next_lan = lans[0] - return redirect('schedule_details', lan_id=next_lan.id) - else: + if lans.count() != 1: return redirect('schedule_lan_list') + lan = lans[0] + if lan.schedule_link: + return redirect(lan.schedule_link) + + return redirect('schedule_details', lan_id=lan.id) + @require_safe def schedule_lan_list(request): diff --git a/apps/lan/migrations/0025_lan_schedule_link.py b/apps/lan/migrations/0025_lan_schedule_link.py new file mode 100644 index 00000000..35601280 --- /dev/null +++ b/apps/lan/migrations/0025_lan_schedule_link.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.29 on 2022-08-03 15:18 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lan', '0024_auto_20220803_1317'), + ] + + operations = [ + migrations.AddField( + model_name='lan', + name='schedule_link', + field=models.CharField(blank=True, help_text='URL to an alternative schedule page.', max_length=300, verbose_name='schedule link'), + ), + ] diff --git a/apps/lan/models.py b/apps/lan/models.py index c3f49d2b..c27549ed 100644 --- a/apps/lan/models.py +++ b/apps/lan/models.py @@ -40,6 +40,7 @@ class LAN(TranslatableModel): frontpage_media_link = models.CharField(_(u'frontpage media link'), max_length=300, help_text=_(u'URL for embedded media on front page.'), blank=True) frontpage_media_type = models.CharField(_(u'frontpage media type'), max_length=10, choices=MEDIA_TYPES, default=MEDIA_TYPE_IMAGE, help_text=_(u'Type of the optional embedded media on front page.')) rules_link = models.CharField(_(u'rules link'), max_length=300, help_text=_(u'URL to rules which users have to accept to buy tickets.'), blank=True) + schedule_link = models.CharField(_(u'schedule link'), max_length=300, help_text=_(u'URL to an alternative schedule page.'), blank=True) @property def attendees(self): diff --git a/apps/lan/views.py b/apps/lan/views.py index d76a2e8d..7526c20e 100644 --- a/apps/lan/views.py +++ b/apps/lan/views.py @@ -9,7 +9,7 @@ from django.utils.translation import pgettext, ugettext as _ from django.views.decorators.http import require_POST, require_safe -from apps.lan.models import Attendee, Directions, LAN, Ticket +from apps.lan.models import Attendee, Directions, LAN, Stream, Ticket @require_safe @@ -53,7 +53,12 @@ def details(request, lan): directions = Directions.objects.filter(lan=lan) - return render(request, 'lan/details.html', {'lan': lan, 'active': active, 'directions': directions}) + stream = None + streams = Stream.objects.filter(active=True).order_by('-pk')[:1] + if len(streams) > 0: + stream = streams[0] + + return render(request, 'lan/details.html', {'lan': lan, 'active': active, 'directions': directions, 'stream': stream}) @require_safe diff --git a/apps/news/views.py b/apps/news/views.py index a418937a..e1421e32 100644 --- a/apps/news/views.py +++ b/apps/news/views.py @@ -5,7 +5,7 @@ from django.shortcuts import get_object_or_404, redirect, render from django.utils.datetime_safe import datetime -from apps.lan.models import LAN, Stream +from apps.lan.models import LAN from apps.news.models import Article @@ -17,7 +17,6 @@ def main(request, page): return redirect('archive_main') paginator = Paginator(articles, 10) # Articles per page - streams = Stream.objects.filter(active=True).order_by('-pk')[:1] try: articles = paginator.page(page) @@ -28,11 +27,7 @@ def main(request, page): # If page is out of range (e.g. 9999), deliver last page of results. articles = paginator.page(paginator.num_pages) - if len(streams) > 0: - return render(request, 'news/news.html', {'lans': active_lans, 'articles': articles, 'page': page, 'stream': streams[0], - 'languages': settings.LANGUAGES}) - else: - return render(request, 'news/news.html', {'lans': active_lans, 'articles': articles, 'page': page, 'languages': settings.LANGUAGES}) + return render(request, 'news/news.html', {'lans': active_lans, 'articles': articles, 'page': page, 'languages': settings.LANGUAGES}) def single(request, article_id): diff --git a/locale/nb/LC_MESSAGES/django.po b/locale/nb/LC_MESSAGES/django.po index 09ed088b..f192f4e4 100644 --- a/locale/nb/LC_MESSAGES/django.po +++ b/locale/nb/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-08-03 13:17+0200\n" +"POT-Creation-Date: 2022-08-03 15:18+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -525,6 +525,12 @@ msgstr "regellenke" msgid "URL to rules which users have to accept to buy tickets." msgstr "URL til regler som brukere må akseptere for å kjøpe billetter." +msgid "schedule link" +msgstr "tidsplanslenke" + +msgid "URL to an alternative schedule page." +msgstr "URL til en alternativ tidsplanslenke." + msgid "upcoming" msgstr "kommende" @@ -1655,7 +1661,7 @@ msgid "No raffles for this LAN." msgstr "Ingen trekninger for dette LAN-et." msgid "No schedule for this LAN." -msgstr "Ingen timetabell for dette LAN-et." +msgstr "Ingen tidsplan for dette LAN-et." msgid "Support" msgstr "Brukerstøtte" diff --git a/studlan/urls.py b/studlan/urls.py index 48a74b87..3d77bc05 100644 --- a/studlan/urls.py +++ b/studlan/urls.py @@ -3,11 +3,11 @@ from django.conf import settings from django.conf.urls import include, url from django.contrib import admin +from django.views.generic.base import RedirectView from apps.lan import views as lan_view from apps.lan.models import LAN from apps.misc import views as misc_view -from apps.news import views as news_view from apps.sponsor import views as sponsor_view urlpatterns = [ @@ -33,7 +33,7 @@ url(r'^messages/', include('postman.urls', namespace='postman')), # Views - url(r'^$', news_view.main, name='root', kwargs={'page': 1}), + url(r'^$', RedirectView.as_view(url='/lan', permanent=False), name='root'), url(r'^misc/remove_alert.html$', misc_view.remove_alert), url(r'^misc/change_language$', misc_view.change_language), url(r'^sponsors/', sponsor_view.index, name='sponsors'), diff --git a/templates/lan/details.html b/templates/lan/details.html index dcbb8985..43bf24dd 100644 --- a/templates/lan/details.html +++ b/templates/lan/details.html @@ -24,7 +24,9 @@

{{ lan }}

{% endif %} -{% if lan.media_link %} +{% if stream %} +{% include "lan/stream.html" %} +{% elif lan.media_link %} {% include "lan/media.html" with media_type=lan.media_type media_link=lan.media_link frontpage=0 %} {% endif %} diff --git a/templates/lan/stream.html b/templates/lan/stream.html new file mode 100644 index 00000000..3960de1b --- /dev/null +++ b/templates/lan/stream.html @@ -0,0 +1,21 @@ +{% load markdown_deux_tags %} + +{% if stream %} +
+
+
+ {% if stream.visible_title %} +

{{ stream.visible_title }}

+ {% endif %} +
+ +
+ {% if stream.description %} +
+ {{ stream.description | markdown }} +
+ {% endif %} +
+
+
+{% endif %} diff --git a/templates/navigation.html b/templates/navigation.html index 7bae76c2..b1632dc7 100644 --- a/templates/navigation.html +++ b/templates/navigation.html @@ -1,17 +1,22 @@ {% load i18n %} {% block navigation %} {% endblock navigation %} diff --git a/templates/news/archive.html b/templates/news/archive.html index c5a5808d..3ab03d11 100644 --- a/templates/news/archive.html +++ b/templates/news/archive.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load i18n %} -{% load markdown_deux_tags %} +{% load markdown_deux_tags %} {% block title %} {% trans "News Archive" %} @@ -12,9 +12,8 @@

{% trans "News Archive" %}

- {% for article in articles.object_list %} - {% if not forloop.first %} + {% if not forloop.first %}
{% endif %} {% include "news/article_card.html" %} diff --git a/templates/news/article_tags.html b/templates/news/article_tags.html index fa5ab3e5..e6a7a527 100644 --- a/templates/news/article_tags.html +++ b/templates/news/article_tags.html @@ -2,15 +2,13 @@ {% load markdown_deux_tags %} diff --git a/templates/news/frontpage.html b/templates/news/frontpage.html new file mode 100644 index 00000000..1b4e50ec --- /dev/null +++ b/templates/news/frontpage.html @@ -0,0 +1,95 @@ +{% extends "base.html" %} + +{% load i18n %} +{% load markdown_deux_tags %} + +{% block title %} +{% trans "Home" %} +{% endblock title %} + +{% block content %} +{% if stream %} +
+
+
+ {% if stream.visible_title %} +

{{ stream.visible_title }}

+ {% endif %} +
+ +
+ {% if stream.description %} +
+ {{ stream.description | markdown }} +
+ {% endif %} +
+
+
+{% endif %} + +
+
+ {% if lans.count == 1 %} +

{{ lans.0 }}

+ {% else %} +

{% trans "LANs" %}

+ {% endif %} +
+
+ +{% if lans.count == 1 %} +{% if lans.0.frontpage_media_link %} +{% with lan=lans.0 %} +{% include "lan/media.html" with media_type=lan.frontpage_media_type media_link=lan.frontpage_media_link frontpage=1 %} +{% endwith %} +{% endif %} + +
+
+

{{ lans.0.start_date|date }} – {{ lans.0.end_date|date }}

+
+ +
+{% else %} +
+
+ + + {% for lan in lans %} + + + + + {% endfor %} + +
{{ lan }}{{ lan.start_date|date }} – {{ lan.end_date|date }}
+
+
+{% endif %} + +
+
+ {% for article in articles.object_list %} +
+ {% include "news/article_card.html" %} + {% empty %} +
{% trans "No news." %}
+ {% endfor %} +
+
+ +
+
+ {% include "news/pagination.html" with news_area='news' %} +
+ +
+{% endblock content %} diff --git a/templates/news/news.html b/templates/news/news.html index 1b4e50ec..7d4f0620 100644 --- a/templates/news/news.html +++ b/templates/news/news.html @@ -8,72 +8,18 @@ {% endblock title %} {% block content %} -{% if stream %}
-
- {% if stream.visible_title %} -

{{ stream.visible_title }}

- {% endif %} -
- -
- {% if stream.description %} -
- {{ stream.description | markdown }} -
- {% endif %} -
+

{% trans "News" %}

-{% endif %} - -
-
- {% if lans.count == 1 %} -

{{ lans.0 }}

- {% else %} -

{% trans "LANs" %}

- {% endif %} -
-
- -{% if lans.count == 1 %} -{% if lans.0.frontpage_media_link %} -{% with lan=lans.0 %} -{% include "lan/media.html" with media_type=lan.frontpage_media_type media_link=lan.frontpage_media_link frontpage=1 %} -{% endwith %} -{% endif %} - -
-
-

{{ lans.0.start_date|date }} – {{ lans.0.end_date|date }}

-
- -
-{% else %} -
-
- - - {% for lan in lans %} - - - - - {% endfor %} - -
{{ lan }}{{ lan.start_date|date }} – {{ lan.end_date|date }}
-
-
-{% endif %}
{% for article in articles.object_list %} + {% if not forloop.first %}
+ {% endif %} {% include "news/article_card.html" %} {% empty %}
{% trans "No news." %}