Skip to content

Commit c8bac74

Browse files
authored
Fix EventPage previews (#555)
While previewing an EventPage, if no future occurrences exist, instead return the latest event.
1 parent 765401a commit c8bac74

6 files changed

Lines changed: 10 additions & 17 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: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -807,20 +807,24 @@ def most_recent_occurrence(self):
807807
noc = self.next_occurrence()
808808
if noc:
809809
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
815810

816811
except AttributeError:
817812
# Triggers when a preview is initiated on an
818813
# EventPage because it uses a FakeQuerySet object.
819814
# Here we manually compute the next_occurrence
820815
occurrences = [e.next_occurrence() for e in self.occurrences.all()]
821-
if occurrences:
816+
# If there are no more occurrences, we find the last one instead
817+
if occurrences and None not in occurrences:
822818
return sorted(occurrences, key=lambda tup: tup[0])[0]
823819

820+
# If both of the above methods fail to find a future occurrence,
821+
# instead return the last occurrence.
822+
aoc = []
823+
for occurrence in self.occurrences.all():
824+
aoc += [instance for instance in occurrence.all_occurrences()]
825+
if len(aoc) > 0:
826+
return aoc[-1] # last one in the list
827+
824828
@property
825829
def seo_struct_event_dict(self) -> dict:
826830
next_occ = self.most_recent_occurrence
@@ -879,7 +883,6 @@ def query_occurrences(self, num_of_instances_to_return=None, **kwargs):
879883

880884
# For each occurrence rule in all of the occurrence rules for this event.
881885
for occurrence in self.occurrences.all():
882-
883886
# Add the qualifying generated event instances to the list.
884887
event_instances += [
885888
instance
@@ -1280,7 +1283,6 @@ def process_data(self, form, request):
12801283
processed_data = {}
12811284
# Handle file uploads
12821285
for key, val in form.cleaned_data.items():
1283-
12841286
if (
12851287
type(val) == InMemoryUploadedFile
12861288
or type(val) == TemporaryUploadedFile
@@ -1318,7 +1320,6 @@ def get_storage(self):
13181320
def process_form_submission(
13191321
self, request, form, form_submission, processed_data
13201322
):
1321-
13221323
# Save to database
13231324
if self.save_to_database:
13241325
form_submission.save()
@@ -1332,7 +1333,6 @@ def process_form_submission(
13321333
context = Context(self.data_to_dict(processed_data, request))
13331334
# Render emails as if they are django templates.
13341335
for email in self.confirmation_emails.all():
1335-
13361336
# Build email message parameters.
13371337
message_args = {}
13381338
# From
@@ -1437,7 +1437,6 @@ def send_mail(
14371437
message.send()
14381438

14391439
def render_landing_page(self, request, form_submission=None):
1440-
14411440
"""
14421441
Renders the landing page.
14431442
@@ -1646,7 +1645,6 @@ class CoderedSubmissionRevision(SubmissionRevision, models.Model):
16461645

16471646

16481647
class CoderedSessionFormSubmission(SessionFormSubmission):
1649-
16501648
INCOMPLETE = "incomplete"
16511649
COMPLETE = "complete"
16521650
REVIEWED = "reviewed"

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/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

coderedcms/wagtail_flexible_forms/models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ def update_data(self):
293293

294294

295295
class SessionFormSubmission(AbstractFormSubmission):
296-
297296
session_key = CharField(max_length=40, null=True, default=None)
298297
user = ForeignKey(
299298
settings.AUTH_USER_MODEL,

0 commit comments

Comments
 (0)