-
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.
Merge branch 'main' into bugfix/DBC22-1157
- Loading branch information
Showing
54 changed files
with
1,290 additions
and
522 deletions.
There are no files selected for viewing
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
Empty file.
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,7 @@ | ||
from apps.cms.tasks import populate_all_ferry_data | ||
from django.core.management.base import BaseCommand | ||
|
||
|
||
class Command(BaseCommand): | ||
def handle(self, *args, **options): | ||
populate_all_ferry_data() |
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.3 on 2023-11-22 00:48 | ||
|
||
import django.contrib.gis.db.models.fields | ||
import django.db.models.deletion | ||
import wagtail.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('wagtailcore', '0089_log_entry_data_json_null_to_object'), | ||
('wagtailimages', '0025_alter_image_file_alter_rendition_file'), | ||
('cms', '0008_bulletin_image'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Ferry', | ||
fields=[ | ||
('page_ptr', models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, primary_key=True, serialize=False, | ||
to='wagtailcore.page' | ||
)), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('modified_at', models.DateTimeField(auto_now=True)), | ||
('location', django.contrib.gis.db.models.fields.GeometryField( | ||
srid=4326 | ||
)), | ||
('url', models.URLField(blank=True)), | ||
('description', wagtail.fields.RichTextField( | ||
blank=True, max_length=750 | ||
)), | ||
('seasonal_description', wagtail.fields.RichTextField( | ||
blank=True, max_length=100 | ||
)), | ||
('service_hours', wagtail.fields.RichTextField( | ||
blank=True, max_length=750 | ||
)), | ||
('feed_created_at', models.DateTimeField()), | ||
('feed_modified_at', models.DateTimeField()), | ||
('image', models.ForeignKey( | ||
blank=True, null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to='wagtailimages.image' | ||
)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
bases=('wagtailcore.page', models.Model), | ||
), | ||
] |
23 changes: 23 additions & 0 deletions
23
src/backend/apps/cms/migrations/0010_alter_ferry_feed_created_at_and_more.py
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,23 @@ | ||
# Generated by Django 4.2.3 on 2023-11-22 03:58 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('cms', '0009_ferry'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='ferry', | ||
name='feed_created_at', | ||
field=models.DateTimeField(auto_now_add=True), | ||
), | ||
migrations.AlterField( | ||
model_name='ferry', | ||
name='feed_modified_at', | ||
field=models.DateTimeField(auto_now=True), | ||
), | ||
] |
21 changes: 21 additions & 0 deletions
21
src/backend/apps/cms/migrations/0011_alter_ferry_location.py
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,21 @@ | ||
# Generated by Django 4.2.3 on 2023-11-24 01:05 | ||
|
||
import django.contrib.gis.db.models.fields | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('cms', '0010_alter_ferry_feed_created_at_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='ferry', | ||
name='location', | ||
field=django.contrib.gis.db.models.fields.GeometryField( | ||
blank=True, null=True, srid=4326 | ||
), | ||
), | ||
] |
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,19 @@ | ||
# Generated by Django 4.2.3 on 2023-11-25 00:48 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('cms', '0011_alter_ferry_location'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='ferry', | ||
name='feed_id', | ||
field=models.PositiveIntegerField(default=None, unique=True), | ||
preserve_default=False, | ||
), | ||
] |
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
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
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,52 @@ | ||
import logging | ||
|
||
from apps.cms.models import Ferry | ||
from apps.feed.client import FeedClient | ||
from apps.shared.enums import CacheKey | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.contrib.gis.geos import Point | ||
from django.core.cache import cache | ||
from django.core.exceptions import ObjectDoesNotExist | ||
from django.utils.text import slugify | ||
from wagtail.models import Page | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def populate_ferry_from_data(ferry_data): | ||
ferry_id = ferry_data.get('id') | ||
|
||
try: | ||
ferry = Ferry.objects.get(feed_id=ferry_id) | ||
|
||
except ObjectDoesNotExist: | ||
# Generate Page associated with ferry obj | ||
root_page = Page.get_root_nodes()[0] | ||
|
||
# New ferry obj | ||
ferry = Ferry( | ||
feed_id=ferry_data['id'], | ||
title=ferry_data['title'], | ||
slug=slugify(ferry_data['title']), | ||
content_type=ContentType.objects.get_for_model(Ferry), | ||
) | ||
|
||
root_page.add_child(instance=ferry) | ||
ferry.save_revision().publish() | ||
|
||
point = Point(ferry_data['location']['coordinates'], srid=4326) | ||
|
||
ferry.location = point | ||
ferry.url = ferry_data['url'] | ||
ferry.feed_created_at = ferry_data['feed_created_at'] | ||
ferry.feed_modified_at = ferry_data['feed_modified_at'] | ||
ferry.save() | ||
|
||
|
||
def populate_all_ferry_data(): | ||
feed_data = FeedClient().get_ferries_list()['features'] | ||
for ferry_data in feed_data: | ||
populate_ferry_from_data(ferry_data) | ||
|
||
# Reset | ||
cache.delete(CacheKey.FERRY_LIST) |
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 @@ | ||
{% load wagtailcore_tags %} | ||
|
||
{% block body_class %}template-blogindexpage{% endblock %} | ||
|
||
{% load static %} | ||
|
||
{% block styles %} | ||
<link rel="stylesheet" type="text/css" href="{% static '../cms/templates/styles.css' %}"> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<div class="title"> | ||
<h1>{{ page.title|safe }}</h1> | ||
<h2>Published at {{ page.created_at|safe }}</h2> | ||
<h2>Last updated at {{ page.modified_at|safe }}</h2> | ||
<div class="description"> | ||
{{ page.seasonal_description|safe }} | ||
{{ page.description|safe }} | ||
{{ page.service_hours|safe }} | ||
</div> | ||
</div> | ||
{% endblock %} |
Oops, something went wrong.