-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8f8032
commit 260109e
Showing
12 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from wagtail.api.v2.router import WagtailAPIRouter | ||
from wagtail.api.v2.views import PagesAPIViewSet | ||
|
||
from .models import InfoIndexPage, InfoPage | ||
|
||
api_router = WagtailAPIRouter("praktiskapi") | ||
|
||
|
||
class InfoPagesAPIViewSet(PagesAPIViewSet): | ||
# This combined with get_queryset is just an awkward way of only allowing | ||
# InfoIndexPage and InfoPage to be returned, and not any other page type. | ||
# Guessing there is a better pattern for this | ||
known_query_parameters = PagesAPIViewSet.known_query_parameters.difference(["type"]) | ||
|
||
meta_fields = PagesAPIViewSet.meta_fields + ["last_published_at"] | ||
|
||
def get_queryset(self): | ||
allowed_models = [InfoIndexPage, InfoPage] | ||
return super().get_queryset().type(tuple(allowed_models)) | ||
|
||
|
||
api_router.register_endpoint("info", InfoPagesAPIViewSet) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class PraktiskConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "praktisk" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Generated by Django 4.2.7 on 2023-12-03 10:09 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
initial = True | ||
|
||
dependencies = [ | ||
("aktuelt", "0009_remove_newspage_date_newspage_custom_published_at_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="InfoIndexPage", | ||
fields=[ | ||
( | ||
"newsindexpage_ptr", | ||
models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, | ||
primary_key=True, | ||
serialize=False, | ||
to="aktuelt.newsindexpage", | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
bases=("aktuelt.newsindexpage",), | ||
), | ||
migrations.CreateModel( | ||
name="InfoPage", | ||
fields=[ | ||
( | ||
"newspage_ptr", | ||
models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, | ||
primary_key=True, | ||
serialize=False, | ||
to="aktuelt.newspage", | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
bases=("aktuelt.newspage",), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from django.db import models | ||
from rest_framework.serializers import ModelSerializer | ||
from wagtail.api.v2.serializers import ( | ||
BaseSerializer, | ||
ChildRelationField, | ||
Field, | ||
get_serializer_class, | ||
) | ||
from wagtail.api.v2.views import APIField, PageSerializer | ||
|
||
from aktuelt.models import NewsIndexPage, NewsPage | ||
from praktisk.serializers import ChildInfoIndexPagesSerializer, ChildInfoPageSerializer | ||
|
||
# In info context we imagine structures like this | ||
# - Practical info (top index/intro) - InfoIndexPage | ||
# - Standalone info page 1 - InfoPage | ||
# - Safety info (topic intro) - InfoPageIndex | ||
# - Safety page 1 - InfoPage | ||
# - Safety page 2 - InfoPage | ||
# - ... | ||
# - Ticket info (topic intro) - InfoPageIndex | ||
# - Ticket page 1 - InfoPage | ||
# - ... | ||
# | ||
# This is a bit different from the news context, where we mostly organize based | ||
# on tags. This initial setup is an assumption, so feel free to adjust as needed. | ||
|
||
|
||
# Extending the NewsPage models since they have a lot of similarities, | ||
# feel free to split them up when/if conventient | ||
class InfoPage(NewsPage): | ||
page_description = "A regular info page" | ||
parent_page_types = ["praktisk.InfoIndexPage"] | ||
subpage_types = [] | ||
|
||
|
||
class InfoIndexPage(NewsIndexPage): | ||
page_description = "Page to list all published info items" | ||
parent_page_types = ["home.HomePage", "praktisk.InfoIndexPage"] | ||
subpage_types = ["praktisk.InfoPage", "praktisk.InfoIndexPage"] | ||
|
||
api_meta_fields = [ | ||
APIField("pages", ChildRelationField(serializer_class=ChildInfoPageSerializer)), | ||
APIField("topics", serializer=ChildInfoIndexPagesSerializer()), | ||
] | ||
|
||
def pages(self): | ||
return InfoPage.objects.live().descendant_of(self) | ||
|
||
def topics(self): | ||
return InfoIndexPage.objects.live().descendant_of(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from wagtail.api.v2.serializers import Field, PageSerializer | ||
|
||
|
||
# The more basic serializers as seen in aktuelt/serializers.py seem a lot | ||
# more appropriate for current usage here. But hoping we can find a pattern where | ||
# the Info(Index)Page is used to serialize. Ie. it uses and respects | ||
# `.api_fields` and `.api_meta_fields` from the model similar to how it is done | ||
# in PageAPIViewSet. | ||
# | ||
# Currently just left here for someone to play around with when/if they want | ||
class ChildInfoPageSerializer(Field): | ||
def __init__(self, *args, **kwargs): | ||
kwargs.pop("context") | ||
super().__init__(*args, **kwargs) | ||
|
||
def to_representation(self, info_page): | ||
return { | ||
"id": info_page.pk, | ||
"title": info_page.title, | ||
"intro": info_page.intro, | ||
} | ||
|
||
|
||
class ChildInfoIndexPagesSerializer(Field): | ||
def to_representation(self, pages): | ||
return [ | ||
{ | ||
"id": index_page.pk, | ||
"title": index_page.title, | ||
"intro": index_page.intro, | ||
} | ||
for index_page in pages.all() | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
|
||
INSTALLED_APPS = [ | ||
"aktuelt", | ||
"praktisk", | ||
"home", | ||
"search", | ||
"wagtail.contrib.forms", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters