Skip to content

Commit

Permalink
Release to main (#1742)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood authored Nov 13, 2024
2 parents 813ba6d + 187ccd7 commit 58cb2f3
Show file tree
Hide file tree
Showing 76 changed files with 5,634 additions and 870 deletions.
13 changes: 13 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"etna.alerts",
"etna.analytics",
"etna.articles",
"etna.blog",
"etna.people",
"etna.cookies",
"etna.categories",
Expand Down Expand Up @@ -307,6 +308,18 @@
}

WAGTAILDOCS_DOCUMENT_MODEL = "core.CustomDocument"
WAGTAILDOCS_EXTENSIONS = [
"pdf",
"xls",
"xlsx",
"doc",
"docx",
"xls",
"xlsx",
"stl",
"txt",
"csv",
]

WAGTAILIMAGES_IMAGE_MODEL = "images.CustomImage"

Expand Down
9 changes: 5 additions & 4 deletions etna/alerts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

from wagtail.models import Site

from ..alerts.models import Alert
from ..alerts.templatetags import alert_tags
from ..collections.models import ExplorerIndexPage, TopicExplorerPage
from ..home.models import HomePage
from etna.collections.models import ExplorerIndexPage, TopicExplorerPage
from etna.home.models import HomePage

from .models import Alert
from .templatetags import alert_tags


def rich_text_msg(level):
Expand Down
67 changes: 67 additions & 0 deletions etna/api/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import datetime

from wagtail.api.v2.utils import BadRequestError

from rest_framework.filters import BaseFilterBackend


class PublishedDateFilter(BaseFilterBackend):
"""
Implements the ?year, ?month and ?day filters to filter the results to only
contain blog posts that were published in the specified year/month/day.
"""

def filter_queryset(self, request, queryset, view):
if "day" in request.GET and (
"year" not in request.GET or "month" not in request.GET
):
raise BadRequestError(
"cannot use day filter without a year and month filter"
)
if "month" in request.GET and "year" not in request.GET:
raise BadRequestError("cannot use month filter without a year filter")

if "year" in request.GET:
try:
year = int(request.GET["year"])
if year < 0:
raise ValueError()
except ValueError:
raise BadRequestError("year must be a positive integer")
queryset = queryset.filter(**{"published_date__year": year})

if "month" in request.GET:
try:
month = int(request.GET["month"])
if month < 0 or month > 12:
raise ValueError()
except ValueError:
raise BadRequestError(
"month must be a positive integer between 1-12"
)
queryset = queryset.filter(**{"published_date__month": month})

if "day" in request.GET:
try:
day = int(request.GET["day"])
datetime.datetime(year, month, day)
except ValueError:
raise BadRequestError(
f"{year}-{month}-{day} is not a valid date"
)
queryset = queryset.filter(**{"published_date__day": day})

return queryset


class AuthorFilter(BaseFilterBackend):
def filter_queryset(self, request, queryset, view):
if "author" in request.GET:
try:
author = request.GET["author"]
if not author:
raise ValueError()
except ValueError:
raise BadRequestError("you must provide an author name")
queryset = queryset.filter(**{"author_tags__author__slug": author})
return queryset
24 changes: 17 additions & 7 deletions etna/api/tests/expected_results/article.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"privacy": "public",
"last_published_at": "2000-01-01T00:00:00Z",
"url": "/article_index/article/",
"depth": 4,
"teaser_text": "Teaser text",
"teaser_image": {
"id": 12,
Expand Down Expand Up @@ -221,9 +222,14 @@
"date": null,
"description": "<p>Description</p>",
"transcript": "<p>Transcript</p>",
"chapters": [],
"width": 1920,
"height": 1080,
"duration": 10.0
"duration": 10.0,
"subtitles_file": null,
"subtitles_file_full_url": null,
"chapters_file": null,
"chapters_file_full_url": null
}
},
"id": "6e6816e0-6634-46cc-bf75-0c7d737a4cb2"
Expand Down Expand Up @@ -325,6 +331,7 @@
"height": 68
}
},
"last_published_at": "2000-01-02T00:00:00Z",
"is_newly_published": true
}
],
Expand All @@ -335,7 +342,7 @@
"title": "arts",
"url": "/arts/",
"full_url": "http://localhost/arts/",
"type_label": "Topic",
"type_label": "Explore the collection",
"teaser_text": "Teaser text",
"teaser_image": {
"id": 2,
Expand All @@ -352,7 +359,8 @@
"width": 100,
"height": 68
}
}
},
"last_published_at": "2000-01-01T00:00:00Z"
}
],
"time_periods": [
Expand All @@ -361,7 +369,7 @@
"title": "early_modern",
"url": "/early_modern/",
"full_url": "http://localhost/early_modern/",
"type_label": "Time period",
"type_label": "Explore the collection",
"teaser_text": "Teaser text",
"teaser_image": {
"id": 4,
Expand All @@ -378,14 +386,15 @@
"width": 100,
"height": 68
}
}
},
"last_published_at": "2000-01-01T00:00:00Z"
},
{
"id": POSTWAR_ID,
"title": "postwar",
"url": "/postwar/",
"full_url": "http://localhost/postwar/",
"type_label": "Time period",
"type_label": "Explore the collection",
"teaser_text": "Teaser text",
"teaser_image": {
"id": 6,
Expand All @@ -402,7 +411,8 @@
"width": 100,
"height": 68
}
}
},
"last_published_at": "2000-01-01T00:00:00Z"
}
]
}
6 changes: 5 additions & 1 deletion etna/api/tests/expected_results/article_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"privacy": "public",
"last_published_at": "2000-01-01T00:00:00Z",
"url": "/article_index/",
"depth": 3,
"teaser_text": "Teaser text",
"teaser_image": {
"id": 11,
Expand Down Expand Up @@ -62,7 +63,7 @@
},
"title": "article_index",
"global_alert": null,
"type_label": "Article index",
"type_label": null,
"mourning_notice": {
"title": "Test title",
"message": "<p>Test message</p>"
Expand Down Expand Up @@ -91,6 +92,7 @@
"height": 68
}
},
"last_published_at": "2000-01-01T00:00:00Z",
"is_newly_published": false
},
"featured_pages": [
Expand Down Expand Up @@ -123,6 +125,7 @@
"height": 68
}
},
"last_published_at": "2000-01-01T00:00:00Z",
"is_newly_published": false
},
{
Expand All @@ -148,6 +151,7 @@
"height": 68
}
},
"last_published_at": "2000-01-02T00:00:00Z",
"is_newly_published": true
}
]
Expand Down
6 changes: 5 additions & 1 deletion etna/api/tests/expected_results/arts.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"privacy": "public",
"last_published_at": "2000-01-01T00:00:00Z",
"url": "/arts/",
"depth": 3,
"teaser_text": "Teaser text",
"teaser_image": {
"id": 2,
Expand Down Expand Up @@ -105,7 +106,7 @@
"custom_sensitive_image": null
},
"global_alert": null,
"type_label": "Topic",
"type_label": "Explore the collection",
"mourning_notice": {
"title": "Test title",
"message": "<p>Test message</p>"
Expand Down Expand Up @@ -138,6 +139,7 @@
"height": 68
}
},
"last_published_at": "2000-01-02T00:00:00Z",
"is_newly_published": true
},
{
Expand All @@ -163,6 +165,7 @@
"height": 68
}
},
"last_published_at": "2000-01-01T00:00:00Z",
"is_newly_published": false
}
],
Expand Down Expand Up @@ -190,6 +193,7 @@
"height": 68
}
},
"last_published_at": "2000-01-03T00:00:00Z",
"highlight_image_count": 1
}
]
Expand Down
4 changes: 3 additions & 1 deletion etna/api/tests/expected_results/author.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"privacy": "public",
"last_published_at": "2000-01-01T00:00:00Z",
"url": "/people/author/",
"depth": 4,
"teaser_text": "Teaser text",
"teaser_image": {
"id": 10,
Expand Down Expand Up @@ -68,7 +69,7 @@
"cascade": true,
"uid": ALERT_UID
},
"type_label": "Person",
"type_label": null,
"mourning_notice": {
"title": "Test title",
"message": "<p>Test message</p>"
Expand Down Expand Up @@ -140,6 +141,7 @@
"height": 68
}
},
"last_published_at": "2000-01-02T00:00:00Z",
"is_newly_published": true
}
],
Expand Down
6 changes: 5 additions & 1 deletion etna/api/tests/expected_results/early_modern.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"privacy": "public",
"last_published_at": "2000-01-01T00:00:00Z",
"url": "/early_modern/",
"depth": 3,
"teaser_text": "Teaser text",
"teaser_image": {
"id": 4,
Expand Down Expand Up @@ -105,7 +106,7 @@
"custom_sensitive_image": null
},
"global_alert": null,
"type_label": "Time period",
"type_label": "Explore the collection",
"mourning_notice": {
"title": "Test title",
"message": "<p>Test message</p>"
Expand Down Expand Up @@ -137,6 +138,7 @@
"height": 68
}
},
"last_published_at": "2000-01-02T00:00:00Z",
"is_newly_published": true
},
{
Expand All @@ -162,6 +164,7 @@
"height": 68
}
},
"last_published_at": "2000-01-01T00:00:00Z",
"is_newly_published": false
}
],
Expand Down Expand Up @@ -189,6 +192,7 @@
"height": 68
}
},
"last_published_at": "2000-01-03T00:00:00Z",
"highlight_image_count": 1
}
],
Expand Down
Loading

0 comments on commit 58cb2f3

Please sign in to comment.