Skip to content

Commit b51a37b

Browse files
committed
Merge branch 'dev' into release/1
2 parents 7281c36 + 29fa2e1 commit b51a37b

17 files changed

Lines changed: 5128 additions & 31 deletions

File tree

coderedcms/blocks/html_blocks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ class Meta:
244244
label = _("Latest Pages")
245245

246246
def get_context(self, value, parent_context=None):
247-
248247
context = super().get_context(value, parent_context=parent_context)
249248

250249
indexer = value["indexed_by"].specific

coderedcms/blocks/stream_form_blocks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616

1717
class CoderedFormAdvSettings(CoderedAdvSettings):
18-
1918
condition_trigger_id = blocks.CharBlock(
2019
required=False,
2120
max_length=255,

coderedcms/models/page_models.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import os
88
import warnings
99
from datetime import date, datetime
10-
from typing import Dict, List, Optional, TYPE_CHECKING, Union
10+
from typing import Dict, List, Optional, TYPE_CHECKING, Union, Tuple
1111

1212
# This is a requirement for icalendar, even if django doesn't require it
1313
import pytz
@@ -798,7 +798,9 @@ def upcoming_occurrences(self):
798798
return self.query_occurrences(num_of_instances_to_return=10)
799799

800800
@property
801-
def most_recent_occurrence(self):
801+
def most_recent_occurrence(
802+
self,
803+
) -> Tuple[datetime, datetime, BaseOccurrence]:
802804
"""
803805
Gets the next upcoming, or last occurrence if the event has no more occurrences.
804806
"""
@@ -807,23 +809,32 @@ def most_recent_occurrence(self):
807809
noc = self.next_occurrence()
808810
if noc:
809811
return noc
810-
aoc = []
811-
for occurrence in self.occurrences.all():
812-
aoc += [instance for instance in occurrence.all_occurrences()]
813-
if len(aoc) > 0:
814-
return aoc[-1] # last one in the list
815812

816813
except AttributeError:
817814
# Triggers when a preview is initiated on an
818815
# EventPage because it uses a FakeQuerySet object.
819816
# Here we manually compute the next_occurrence
820817
occurrences = [e.next_occurrence() for e in self.occurrences.all()]
821-
if occurrences:
818+
# If there are no more occurrences, we find the last one instead
819+
if occurrences and None not in occurrences:
822820
return sorted(occurrences, key=lambda tup: tup[0])[0]
823821

822+
# If both of the above methods fail to find a future occurrence,
823+
# instead return the last occurrence.
824+
aoc = []
825+
for occurrence in self.occurrences.all():
826+
aoc += [instance for instance in occurrence.all_occurrences()]
827+
if len(aoc) > 0:
828+
return aoc[-1] # last one in the list
829+
824830
@property
825831
def seo_struct_event_dict(self) -> dict:
826832
next_occ = self.most_recent_occurrence
833+
if not next_occ:
834+
return {}
835+
# The method returns a tuple of the start, end, and object. We only care about
836+
# the object, so take it out of the tuple.
837+
next_occ = next_occ[2]
827838
sd_dict = {
828839
"@context": "https://schema.org/",
829840
"@type": "Event",
@@ -833,12 +844,18 @@ def seo_struct_event_dict(self) -> dict:
833844
"endDate": next_occ.end,
834845
"mainEntityOfPage": {
835846
"@type": "WebPage",
836-
"@id": self.get_full_url,
847+
"@id": self.get_full_url(),
837848
},
838849
}
839850

840851
if self.seo_image:
841-
sd_dict.update({"image": get_struct_data_images(self.seo_image)})
852+
sd_dict.update(
853+
{
854+
"image": get_struct_data_images(
855+
self.get_site(), self.seo_image
856+
)
857+
}
858+
)
842859

843860
if self.address:
844861
sd_dict.update(
@@ -879,7 +896,6 @@ def query_occurrences(self, num_of_instances_to_return=None, **kwargs):
879896

880897
# For each occurrence rule in all of the occurrence rules for this event.
881898
for occurrence in self.occurrences.all():
882-
883899
# Add the qualifying generated event instances to the list.
884900
event_instances += [
885901
instance
@@ -1280,7 +1296,6 @@ def process_data(self, form, request):
12801296
processed_data = {}
12811297
# Handle file uploads
12821298
for key, val in form.cleaned_data.items():
1283-
12841299
if (
12851300
type(val) == InMemoryUploadedFile
12861301
or type(val) == TemporaryUploadedFile
@@ -1318,7 +1333,6 @@ def get_storage(self):
13181333
def process_form_submission(
13191334
self, request, form, form_submission, processed_data
13201335
):
1321-
13221336
# Save to database
13231337
if self.save_to_database:
13241338
form_submission.save()
@@ -1332,7 +1346,6 @@ def process_form_submission(
13321346
context = Context(self.data_to_dict(processed_data, request))
13331347
# Render emails as if they are django templates.
13341348
for email in self.confirmation_emails.all():
1335-
13361349
# Build email message parameters.
13371350
message_args = {}
13381351
# From
@@ -1437,7 +1450,6 @@ def send_mail(
14371450
message.send()
14381451

14391452
def render_landing_page(self, request, form_submission=None):
1440-
14411453
"""
14421454
Renders the landing page.
14431455
@@ -1646,7 +1658,6 @@ class CoderedSubmissionRevision(SubmissionRevision, models.Model):
16461658

16471659

16481660
class CoderedSessionFormSubmission(SessionFormSubmission):
1649-
16501661
INCOMPLETE = "incomplete"
16511662
COMPLETE = "complete"
16521663
REVIEWED = "reviewed"

coderedcms/models/tests/test_page_models.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime, timedelta
12
from django.test import Client
23
from wagtail.test.utils import WagtailPageTests
34

@@ -20,6 +21,7 @@
2021
ArticlePage,
2122
EventIndexPage,
2223
EventPage,
24+
EventOccurrence,
2325
FormPage,
2426
IndexTestPage,
2527
LocationIndexPage,
@@ -200,6 +202,19 @@ class EventIndexPageTestCase(ConcreteBasicPageTestCase, WagtailPageTests):
200202
class EventPageTestCase(ConcreteBasicPageTestCase, WagtailPageTests):
201203
model = EventPage
202204

205+
def setUp(self):
206+
super().setUp()
207+
self.occurrence = EventOccurrence(
208+
start=datetime.now(),
209+
end=datetime.now() + timedelta(days=1),
210+
event=self.basic_page,
211+
)
212+
self.occurrence.save()
213+
214+
def tearDown(self) -> None:
215+
super().tearDown()
216+
self.occurrence.delete()
217+
203218

204219
class LocationIndexPageTestCase(ConcreteBasicPageTestCase, WagtailPageTests):
205220
model = LocationIndexPage

coderedcms/settings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class _DefaultSettings:
7-
87
CRX_PROTECTED_MEDIA_URL = "/protected/"
98
CRX_PROTECTED_MEDIA_ROOT = os.path.join(settings.BASE_DIR, "protected")
109
CRX_PROTECTED_MEDIA_UPLOAD_WHITELIST = []

coderedcms/templates/coderedcms/blocks/accordion_block.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{% with a_id=self.accordion.id accordion=self.accordion %}
55
<div class="accordion" id="accordion-{{a_id}}">
66
{% for panel in accordion.accordion_panels.all %}
7-
<div class="accordion-item">
7+
<div id="{{panel.custom_id}}" class="accordion-item {{panel.custom_css_class}}">
88
<h2 class="accordion-header" id="accordion-heading-{{forloop.counter}}">
99
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
1010
data-bs-target="#collapse-{{a_id}}-{{forloop.counter}}" aria-expanded="false"

coderedcms/templates/coderedcms/blocks/cardgrid_deck.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
{% load wagtailcore_tags %}
33
{% block grid_content %}
44
<div class="row {{self.settings.custom_css_class}}">
5-
<div class="col">
6-
{% for block in self.content %}
7-
{% include_block block %}
8-
{% endfor %}
9-
</div>
5+
{% for block in self.content %}
6+
<div class="col">{% include_block block %}</div>
7+
{% endfor %}
108
</div>
119
{% endblock %}

coderedcms/templates/coderedcms/includes/pagination.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
</a>
1010
</li>
1111
<li class="page-item disabled">
12-
<span class="page-link">{% trans 'Page' %} {{ items.number }} {% trans 'of' %} {{ items.paginator.num_pages
13-
}}</span>
12+
<span class="page-link">{% trans 'Page' %} {{ items.number }} {% trans 'of' %} {{ items.paginator.num_pages }}</span>
1413
</li>
1514
<li class="page-item {% if not items.has_next %}disabled{% endif %}">
1615
<a class="page-link" href="{% if items.has_next %}?{% query_update request.GET 'p' items.next_page_number as q %}{{q.urlencode}}{% else %}#{% endif %}" aria-label="Next">

coderedcms/templates/coderedcms/pages/base.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@
165165

166166
{% block custom_scripts %}{% endblock %}
167167

168-
{% include "wagtailseo/struct_data.html" %}
168+
{% block struct_seo %}
169+
{% include "wagtailseo/struct_data.html" %}
170+
{% block struct_seo_extra %}{% endblock %}
171+
{% endblock %}
169172

170173
{% block body_tracking_scripts %}
171174
{% if settings.coderedcms.AnalyticsSettings.gtm_id %}

coderedcms/tests/testapp/models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ class Meta:
6060

6161

6262
class FormConfirmEmail(CoderedEmail):
63-
6463
page = ParentalKey("FormPage", related_name="confirmation_emails")
6564

6665

0 commit comments

Comments
 (0)