|
@@ -12,7 +12,7 @@ from django.contrib import messages
|
|
|
from django.core.files.uploadedfile import InMemoryUploadedFile, TemporaryUploadedFile
|
|
|
from django.core.files.storage import FileSystemStorage
|
|
|
from django.core.mail import EmailMessage
|
|
|
-from django.core.paginator import Paginator
|
|
|
+from django.core.paginator import Paginator, InvalidPage, EmptyPage, PageNotAnInteger
|
|
|
from django.core.serializers.json import DjangoJSONEncoder
|
|
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
|
|
from django.db import models
|
|
@@ -41,7 +41,8 @@ from wagtail.admin.edit_handlers import (
|
|
|
ObjectList,
|
|
|
PageChooserPanel,
|
|
|
StreamFieldPanel,
|
|
|
- TabbedInterface)
|
|
|
+ TabbedInterface
|
|
|
+)
|
|
|
from wagtail.core import hooks
|
|
|
from wagtail.core.fields import StreamField
|
|
|
from wagtail.core.models import Orderable, PageBase, Page, Site
|
|
@@ -60,13 +61,21 @@ from coderedcms.blocks import (
|
|
|
STREAMFORM_BLOCKS,
|
|
|
ContentWallBlock,
|
|
|
OpenHoursBlock,
|
|
|
- StructuredDataActionBlock)
|
|
|
+ StructuredDataActionBlock
|
|
|
+)
|
|
|
from coderedcms.fields import ColorField
|
|
|
from coderedcms.forms import CoderedFormBuilder, CoderedSubmissionsListView
|
|
|
from coderedcms.models.snippet_models import ClassifierTerm
|
|
|
-from coderedcms.models.wagtailsettings_models import GeneralSettings, LayoutSettings, SeoSettings, GoogleApiSettings
|
|
|
+from coderedcms.models.wagtailsettings_models import GeneralSettings, LayoutSettings, SeoSettings, GoogleApiSettings # noqa
|
|
|
from coderedcms.wagtail_flexible_forms.blocks import FormFieldBlock, FormStepBlock
|
|
|
-from coderedcms.wagtail_flexible_forms.models import Step, Steps, StreamFormMixin, StreamFormJSONEncoder, SessionFormSubmission, SubmissionRevision
|
|
|
+from coderedcms.wagtail_flexible_forms.models import (
|
|
|
+ Step,
|
|
|
+ Steps,
|
|
|
+ StreamFormMixin,
|
|
|
+ StreamFormJSONEncoder,
|
|
|
+ SessionFormSubmission,
|
|
|
+ SubmissionRevision
|
|
|
+)
|
|
|
from coderedcms.settings import cr_settings
|
|
|
from coderedcms.widgets import ClassifierSelectWidget
|
|
|
|
|
@@ -76,6 +85,7 @@ logger = logging.getLogger('coderedcms')
|
|
|
|
|
|
CODERED_PAGE_MODELS = []
|
|
|
|
|
|
+
|
|
|
def get_page_models():
|
|
|
return CODERED_PAGE_MODELS
|
|
|
|
|
@@ -100,11 +110,13 @@ class CoderedPageMeta(PageBase):
|
|
|
if not cls._meta.abstract:
|
|
|
CODERED_PAGE_MODELS.append(cls)
|
|
|
|
|
|
+
|
|
|
class CoderedTag(TaggedItemBase):
|
|
|
class Meta:
|
|
|
verbose_name = _('CodeRed Tag')
|
|
|
content_object = ParentalKey('coderedcms.CoderedPage', related_name='tagged_items')
|
|
|
|
|
|
+
|
|
|
class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
"""
|
|
|
General use page with caching, templating, and SEO functionality.
|
|
@@ -124,7 +136,6 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
# ajax_template = ''
|
|
|
# search_template = ''
|
|
|
|
|
|
-
|
|
|
###############
|
|
|
# Content fields
|
|
|
###############
|
|
@@ -138,7 +149,6 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
verbose_name=_('Cover image'),
|
|
|
)
|
|
|
|
|
|
-
|
|
|
###############
|
|
|
# Index fields
|
|
|
###############
|
|
@@ -184,7 +194,6 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
help_text=_('Enable filtering child pages by these classifiers.'),
|
|
|
)
|
|
|
|
|
|
-
|
|
|
###############
|
|
|
# Layout fields
|
|
|
###############
|
|
@@ -196,7 +205,6 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
verbose_name=_('Template')
|
|
|
)
|
|
|
|
|
|
-
|
|
|
###############
|
|
|
# SEO fields
|
|
|
###############
|
|
@@ -208,7 +216,9 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
on_delete=models.SET_NULL,
|
|
|
related_name='+',
|
|
|
verbose_name=_('Open Graph preview image'),
|
|
|
- help_text=_('The image shown when linking to this page on social media. If blank, defaults to article cover image, or logo in Settings > Layout > Logo')
|
|
|
+ help_text=_(
|
|
|
+ "The image shown when linking to this page on social media. If blank, defaults to article cover image, or logo in Settings > Layout > Logo" # noqa
|
|
|
+ )
|
|
|
)
|
|
|
struct_org_type = models.CharField(
|
|
|
default='',
|
|
@@ -241,7 +251,9 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
on_delete=models.SET_NULL,
|
|
|
related_name='+',
|
|
|
verbose_name=_('Photo of Organization'),
|
|
|
- help_text=_('A photo of the facility. This photo will be cropped to 1:1, 4:3, and 16:9 aspect ratios automatically.')
|
|
|
+ help_text=_(
|
|
|
+ "A photo of the facility. This photo will be cropped to 1:1, 4:3, and 16:9 aspect ratios automatically." # noqa
|
|
|
+ )
|
|
|
)
|
|
|
struct_org_phone = models.CharField(
|
|
|
blank=True,
|
|
@@ -277,7 +289,9 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
blank=True,
|
|
|
max_length=255,
|
|
|
verbose_name=_('Country'),
|
|
|
- help_text=_('For example, USA. Two-letter ISO 3166-1 alpha-2 country code is also acceptible https://en.wikipedia.org/wiki/ISO_3166-1')
|
|
|
+ help_text=_(
|
|
|
+ "For example, USA. Two-letter ISO 3166-1 alpha-2 country code is also acceptible https://en.wikipedia.org/wiki/ISO_3166-1" # noqa
|
|
|
+ )
|
|
|
)
|
|
|
struct_org_geo_lat = models.DecimalField(
|
|
|
blank=True,
|
|
@@ -310,10 +324,11 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
struct_org_extra_json = models.TextField(
|
|
|
blank=True,
|
|
|
verbose_name=_('Additional Organization markup'),
|
|
|
- help_text=_('Additional JSON-LD inserted into the Organization dictionary. Must be properties of https://schema.org/Organization or the selected organization type.')
|
|
|
+ help_text=_(
|
|
|
+ "Additional JSON-LD inserted into the Organization dictionary. Must be properties of https://schema.org/Organization or the selected organization type." # noqa
|
|
|
+ )
|
|
|
)
|
|
|
|
|
|
-
|
|
|
###############
|
|
|
# Classify
|
|
|
###############
|
|
@@ -322,7 +337,9 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
'coderedcms.ClassifierTerm',
|
|
|
blank=True,
|
|
|
verbose_name=_('Classifiers'),
|
|
|
- help_text=_('Categorize and group pages together with classifiers. Used to organize and filter pages across the site.'),
|
|
|
+ help_text=_(
|
|
|
+ "Categorize and group pages together with classifiers. Used to organize and filter pages across the site." # noqa
|
|
|
+ ),
|
|
|
)
|
|
|
tags = ClusterTaggableManager(
|
|
|
through=CoderedTag,
|
|
@@ -331,7 +348,6 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
help_text=_('Used to organize pages across the site.'),
|
|
|
)
|
|
|
|
|
|
-
|
|
|
###############
|
|
|
# Settings
|
|
|
###############
|
|
@@ -344,7 +360,6 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
verbose_name=_('Content Walls')
|
|
|
)
|
|
|
|
|
|
-
|
|
|
###############
|
|
|
# Search
|
|
|
###############
|
|
@@ -370,7 +385,6 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
index.FilterField('classifier_terms'),
|
|
|
]
|
|
|
|
|
|
-
|
|
|
###############
|
|
|
# Panels
|
|
|
###############
|
|
@@ -460,8 +474,7 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
super().__init__(*args, **kwargs)
|
|
|
klassname = self.__class__.__name__.lower()
|
|
|
template_choices = cr_settings['FRONTEND_TEMPLATES_PAGES'].get('*', ()) + \
|
|
|
- cr_settings['FRONTEND_TEMPLATES_PAGES'].get(klassname, ())
|
|
|
-
|
|
|
+ cr_settings['FRONTEND_TEMPLATES_PAGES'].get(klassname, ())
|
|
|
|
|
|
self._meta.get_field('index_order_by').choices = self.index_order_by_choices
|
|
|
self._meta.get_field('custom_template').choices = template_choices
|
|
@@ -469,14 +482,16 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
self.index_order_by = self.index_order_by_default
|
|
|
self.index_show_subpages = self.index_show_subpages_default
|
|
|
|
|
|
-
|
|
|
@classmethod
|
|
|
def get_edit_handler(cls):
|
|
|
"""
|
|
|
Override to "lazy load" the panels overriden by subclasses.
|
|
|
"""
|
|
|
panels = [
|
|
|
- ObjectList(cls.content_panels + cls.body_content_panels + cls.bottom_content_panels, heading=_('Content')),
|
|
|
+ ObjectList(
|
|
|
+ cls.content_panels + cls.body_content_panels + cls.bottom_content_panels,
|
|
|
+ heading=_('Content')
|
|
|
+ ),
|
|
|
ObjectList(cls.classify_panels, heading=_('Classify')),
|
|
|
ObjectList(cls.layout_panels, heading=_('Layout')),
|
|
|
ObjectList(cls.promote_panels, heading=_('SEO'), classname="seo"),
|
|
@@ -484,7 +499,11 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
]
|
|
|
|
|
|
if cls.integration_panels:
|
|
|
- panels.append(ObjectList(cls.integration_panels, heading='Integrations', classname='integrations'))
|
|
|
+ panels.append(ObjectList(
|
|
|
+ cls.integration_panels,
|
|
|
+ heading='Integrations',
|
|
|
+ classname='integrations'
|
|
|
+ ))
|
|
|
|
|
|
return TabbedInterface(panels).bind_to_model(cls)
|
|
|
|
|
@@ -580,13 +599,18 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
try:
|
|
|
for term in selected_terms:
|
|
|
all_children = all_children.filter(classifier_terms=term)
|
|
|
- except:
|
|
|
- logger.warning("Tried to filter by ClassifierTerm, but <%s.%s ('%s')>.get_index_children() did not return a queryset or is not a queryset of CoderedPage models.", self._meta.app_label, self.__class__.__name__, self.title)
|
|
|
+ except AttributeError:
|
|
|
+ logger.warning(
|
|
|
+ "Tried to filter by ClassifierTerm, but <%s.%s ('%s')>.get_index_children() did not return a queryset or is not a queryset of CoderedPage models.", # noqa
|
|
|
+ self._meta.app_label,
|
|
|
+ self.__class__.__name__,
|
|
|
+ self.title
|
|
|
+ )
|
|
|
paginator = Paginator(all_children, self.index_num_per_page)
|
|
|
pagenum = request.GET.get('p', 1)
|
|
|
try:
|
|
|
paged_children = paginator.page(pagenum)
|
|
|
- except:
|
|
|
+ except (PageNotAnInteger, EmptyPage, InvalidPage) as e: # noqa
|
|
|
paged_children = paginator.page(1)
|
|
|
|
|
|
context['index_paginated'] = paged_children
|
|
@@ -594,9 +618,6 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
|
|
|
context['content_walls'] = self.get_content_walls(check_child_setting=False)
|
|
|
return context
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
###############################################################################
|
|
|
# Abstract pages providing pre-built common website functionality, suitable for subclassing.
|
|
|
# These are abstract so subclasses can override fields if desired.
|
|
@@ -841,10 +862,11 @@ class CoderedEventPage(CoderedWebPage, BaseEvent):
|
|
|
for occurrence in self.occurrences.all():
|
|
|
aoc += [instance for instance in occurrence.all_occurrences()]
|
|
|
if len(aoc) > 0:
|
|
|
- return aoc[-1] # last one in the list
|
|
|
+ return aoc[-1] # last one in the list
|
|
|
|
|
|
except AttributeError:
|
|
|
- # Triggers when a preview is initiated on an EventPage because it uses a FakeQuerySet object.
|
|
|
+ # Triggers when a preview is initiated on an
|
|
|
+ # EventPage because it uses a FakeQuerySet object.
|
|
|
# Here we manually compute the next_occurrence
|
|
|
occurrences = [e.next_occurrence() for e in self.occurrences.all()]
|
|
|
if occurrences:
|
|
@@ -862,21 +884,23 @@ class CoderedEventPage(CoderedWebPage, BaseEvent):
|
|
|
}
|
|
|
|
|
|
if 'limit' in kwargs:
|
|
|
- if kwargs['limit'] != None:
|
|
|
- # Limit the number of event instances that will be generated per occurrence rule to 10, if not otherwise specified.
|
|
|
+ if kwargs['limit'] is not None:
|
|
|
+ # Limit the number of event instances that will be
|
|
|
+ # generated per occurrence rule to 10, if not otherwise specified.
|
|
|
occurrence_kwargs['limit'] = kwargs.get('limit', 10)
|
|
|
|
|
|
# For each occurrence rule in all of the occurrence rules for this event.
|
|
|
for occurrence in self.occurrences.all():
|
|
|
|
|
|
# Add the qualifying generated event instances to the list.
|
|
|
- event_instances += [instance for instance in occurrence.all_occurrences(**occurrence_kwargs)]
|
|
|
+ event_instances += [
|
|
|
+ instance for instance in occurrence.all_occurrences(**occurrence_kwargs)]
|
|
|
|
|
|
# Sort all the events by the date that they start
|
|
|
event_instances.sort(key=lambda d: d[0])
|
|
|
|
|
|
# Return the event instances, possibly spliced if num_instances_to_return is set.
|
|
|
- return event_instances[:num_of_instances_to_return] if num_of_instances_to_return else event_instances
|
|
|
+ return event_instances[:num_of_instances_to_return] if num_of_instances_to_return else event_instances # noqa
|
|
|
|
|
|
def convert_to_ical_format(self, dt_start=None, dt_end=None, occurrence=None):
|
|
|
ical_event = ICalEvent()
|
|
@@ -892,7 +916,8 @@ class CoderedEventPage(CoderedWebPage, BaseEvent):
|
|
|
|
|
|
if occurrence:
|
|
|
freq = occurrence.repeat.split(":")[1] if occurrence.repeat else None
|
|
|
- repeat_until = occurrence.repeat_until.strftime("%Y%m%dT000000Z") if occurrence.repeat_until else None
|
|
|
+ repeat_until = occurrence.repeat_until.strftime(
|
|
|
+ "%Y%m%dT000000Z") if occurrence.repeat_until else None
|
|
|
|
|
|
ical_event.add('dtstart', occurrence.start)
|
|
|
|
|
@@ -916,6 +941,7 @@ class CoderedEventPage(CoderedWebPage, BaseEvent):
|
|
|
events.append(self.convert_to_ical_format(occurrence=occurrence))
|
|
|
return events
|
|
|
|
|
|
+
|
|
|
class DefaultCalendarViewChoices():
|
|
|
MONTH = 'month'
|
|
|
AGENDA_WEEK = 'agendaWeek'
|
|
@@ -930,6 +956,7 @@ class DefaultCalendarViewChoices():
|
|
|
(LIST_MONTH, _('Calendar List View')),
|
|
|
)
|
|
|
|
|
|
+
|
|
|
class CoderedEventIndexPage(CoderedWebPage):
|
|
|
"""
|
|
|
Shows a list of event sub-pages.
|
|
@@ -984,7 +1011,7 @@ class CoderedEventIndexPage(CoderedWebPage):
|
|
|
event_data = {
|
|
|
'title': event.title,
|
|
|
'start': occurrence[0].strftime('%Y-%m-%dT%H:%M:%S'),
|
|
|
- 'end' : occurrence[1].strftime('%Y-%m-%dT%H:%M:%S') if occurrence[1] else "",
|
|
|
+ 'end': occurrence[1].strftime('%Y-%m-%dT%H:%M:%S') if occurrence[1] else "",
|
|
|
'description': "",
|
|
|
}
|
|
|
if event.url:
|
|
@@ -1002,25 +1029,28 @@ class CoderedEventOccurrence(Orderable, BaseOccurrence):
|
|
|
|
|
|
|
|
|
class CoderedFormMixin(models.Model):
|
|
|
-
|
|
|
class Meta:
|
|
|
abstract = True
|
|
|
|
|
|
submissions_list_view_class = CoderedSubmissionsListView
|
|
|
encoder = DjangoJSONEncoder
|
|
|
|
|
|
- ### Custom codered fields
|
|
|
+ # Custom codered fields
|
|
|
to_address = models.CharField(
|
|
|
max_length=255,
|
|
|
blank=True,
|
|
|
verbose_name=_('Email form submissions to'),
|
|
|
- help_text=_('Optional - email form submissions to this address. Separate multiple addresses by comma.')
|
|
|
+ help_text=_(
|
|
|
+ "Optional - email form submissions to this address. Separate multiple addresses by comma." # noqa
|
|
|
+ )
|
|
|
)
|
|
|
reply_address = models.CharField(
|
|
|
max_length=255,
|
|
|
blank=True,
|
|
|
verbose_name=_('Reply-to address'),
|
|
|
- help_text=_('Optional - to reply to the submitter, specify the email field here. For example, if a form field above is labeled "Your Email", enter: {{ your_email }}')
|
|
|
+ help_text=_(
|
|
|
+ "Optional - to reply to the submitter, specify the email field here. For example, if a form field above is labeled 'Your Email', enter: {{ your_email }}" # noqa
|
|
|
+ )
|
|
|
)
|
|
|
subject = models.CharField(
|
|
|
max_length=255,
|
|
@@ -1136,7 +1166,6 @@ class CoderedFormMixin(models.Model):
|
|
|
FieldPanel('spam_protection')
|
|
|
]
|
|
|
|
|
|
-
|
|
|
@property
|
|
|
def form_live(self):
|
|
|
"""
|
|
@@ -1174,9 +1203,9 @@ class CoderedFormMixin(models.Model):
|
|
|
|
|
|
def get_storage(self):
|
|
|
return FileSystemStorage(
|
|
|
- location=cr_settings['PROTECTED_MEDIA_ROOT'],
|
|
|
- base_url=cr_settings['PROTECTED_MEDIA_URL']
|
|
|
- )
|
|
|
+ location=cr_settings['PROTECTED_MEDIA_ROOT'],
|
|
|
+ base_url=cr_settings['PROTECTED_MEDIA_URL']
|
|
|
+ )
|
|
|
|
|
|
def process_form_submission(self, request, form, form_submission, processed_data):
|
|
|
|
|
@@ -1412,13 +1441,13 @@ class CoderedFormPage(CoderedFormMixin, CoderedWebPage):
|
|
|
form_builder = CoderedFormBuilder
|
|
|
|
|
|
body_content_panels = [
|
|
|
- InlinePanel('form_fields', label="Form fields"),
|
|
|
- ] + \
|
|
|
+ InlinePanel('form_fields', label="Form fields"),
|
|
|
+ ] + \
|
|
|
CoderedWebPage.body_content_panels + \
|
|
|
CoderedFormMixin.body_content_panels + [
|
|
|
FormSubmissionsPanel(),
|
|
|
InlinePanel('confirmation_emails', label=_('Confirmation Emails'))
|
|
|
- ]
|
|
|
+ ]
|
|
|
|
|
|
settings_panels = CoderedPage.settings_panels + CoderedFormMixin.settings_panels
|
|
|
|
|
@@ -1494,9 +1523,9 @@ class CoderedSessionFormSubmission(SessionFormSubmission):
|
|
|
if 'user' in submission_data:
|
|
|
submission_data['user'] = str(submission_data['user'])
|
|
|
submission = FormSubmission.objects.create(
|
|
|
- form_data=json.dumps(submission_data, cls=StreamFormJSONEncoder),
|
|
|
- page=self.page
|
|
|
- )
|
|
|
+ form_data=json.dumps(submission_data, cls=StreamFormJSONEncoder),
|
|
|
+ page=self.page
|
|
|
+ )
|
|
|
|
|
|
if delete_self:
|
|
|
CoderedSubmissionRevision.objects.filter(submission_id=self.id).delete()
|
|
@@ -1510,11 +1539,9 @@ class CoderedSessionFormSubmission(SessionFormSubmission):
|
|
|
def render_link(self, value):
|
|
|
return "{0}{1}".format(cr_settings['PROTECTED_MEDIA_URL'], value)
|
|
|
|
|
|
-
|
|
|
def render_image(self, value):
|
|
|
return "{0}{1}".format(cr_settings['PROTECTED_MEDIA_URL'], value)
|
|
|
|
|
|
-
|
|
|
def render_file(self, value):
|
|
|
return "{0}{1}".format(cr_settings['PROTECTED_MEDIA_URL'], value)
|
|
|
|
|
@@ -1526,8 +1553,7 @@ def create_submission_changed_revision(sender, **kwargs):
|
|
|
submission = kwargs['instance']
|
|
|
created = kwargs['created']
|
|
|
CoderedSubmissionRevision.create_from_submission(
|
|
|
- submission, (CoderedSubmissionRevision.CREATED if created
|
|
|
- else CoderedSubmissionRevision.CHANGED))
|
|
|
+ submission, (CoderedSubmissionRevision.CREATED if created else CoderedSubmissionRevision.CHANGED)) # noqa
|
|
|
|
|
|
|
|
|
@receiver(post_delete)
|
|
@@ -1535,8 +1561,7 @@ def create_submission_deleted_revision(sender, **kwargs):
|
|
|
if not issubclass(sender, CoderedSessionFormSubmission):
|
|
|
return
|
|
|
submission = kwargs['instance']
|
|
|
- CoderedSubmissionRevision.create_from_submission(submission,
|
|
|
- SubmissionRevision.DELETED)
|
|
|
+ CoderedSubmissionRevision.create_from_submission(submission, SubmissionRevision.DELETED) # noqa
|
|
|
|
|
|
|
|
|
class CoderedStep(Step):
|
|
@@ -1571,7 +1596,7 @@ class CoderedSteps(Steps):
|
|
|
|
|
|
class CoderedStreamFormMixin(StreamFormMixin):
|
|
|
class Meta:
|
|
|
- abstract=True
|
|
|
+ abstract = True
|
|
|
|
|
|
def get_steps(self, request=None):
|
|
|
if not hasattr(self, 'steps'):
|
|
@@ -1625,8 +1650,8 @@ class CoderedStreamFormPage(CoderedFormMixin, CoderedStreamFormMixin, CoderedWeb
|
|
|
body_content_panels = [
|
|
|
StreamFieldPanel('form_fields')
|
|
|
] + \
|
|
|
- CoderedFormMixin.body_content_panels + [
|
|
|
- InlinePanel('confirmation_emails', label=_('Confirmation Emails'))
|
|
|
+ CoderedFormMixin.body_content_panels + [
|
|
|
+ InlinePanel('confirmation_emails', label=_('Confirmation Emails'))
|
|
|
]
|
|
|
|
|
|
def process_form_post(self, form, request):
|
|
@@ -1653,9 +1678,10 @@ class CoderedStreamFormPage(CoderedFormMixin, CoderedStreamFormMixin, CoderedWeb
|
|
|
|
|
|
def get_storage(self):
|
|
|
return FileSystemStorage(
|
|
|
- location=cr_settings['PROTECTED_MEDIA_ROOT'],
|
|
|
- base_url=cr_settings['PROTECTED_MEDIA_URL']
|
|
|
- )
|
|
|
+ location=cr_settings['PROTECTED_MEDIA_ROOT'],
|
|
|
+ base_url=cr_settings['PROTECTED_MEDIA_URL']
|
|
|
+ )
|
|
|
+
|
|
|
|
|
|
class CoderedLocationPage(CoderedWebPage):
|
|
|
"""
|
|
@@ -1687,7 +1713,8 @@ class CoderedLocationPage(CoderedWebPage):
|
|
|
auto_update_latlng = models.BooleanField(
|
|
|
default=True,
|
|
|
verbose_name=_("Auto Update Latitude and Longitude"),
|
|
|
- help_text=_("If checked, automatically update the latitude and longitude when the address is updated.")
|
|
|
+ help_text=_(
|
|
|
+ "If checked, automatically update the latitude and longitude when the address is updated.") # noqa
|
|
|
)
|
|
|
map_title = models.CharField(
|
|
|
blank=True,
|
|
@@ -1767,20 +1794,24 @@ class CoderedLocationPage(CoderedWebPage):
|
|
|
def to_geojson(self):
|
|
|
return {
|
|
|
"type": "Feature",
|
|
|
- "geometry":{
|
|
|
+ "geometry": {
|
|
|
"type": "Point",
|
|
|
"coordinates": [self.longitude, self.latitude]
|
|
|
},
|
|
|
- "properties":{
|
|
|
+ "properties": {
|
|
|
"list_description": self.render_list_description,
|
|
|
"pin_description": self.render_pin_description
|
|
|
}
|
|
|
}
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
- if self.auto_update_latlng and GoogleApiSettings.for_site(Site.objects.get(is_default_site=True)).google_maps_api_key:
|
|
|
+ if self.auto_update_latlng and GoogleApiSettings.for_site(
|
|
|
+ Site.objects.get(is_default_site=True)
|
|
|
+ ).google_maps_api_key:
|
|
|
try:
|
|
|
- g = geocoder.google(self.address, key=GoogleApiSettings.for_site(Site.objects.get(is_default_site=True)).google_maps_api_key)
|
|
|
+ g = geocoder.google(self.address, key=GoogleApiSettings.for_site(
|
|
|
+ Site.objects.get(is_default_site=True)
|
|
|
+ ).google_maps_api_key)
|
|
|
self.latitude = g.latlng[0]
|
|
|
self.longitude = g.latlng[1]
|
|
|
except TypeError:
|
|
@@ -1789,10 +1820,11 @@ class CoderedLocationPage(CoderedWebPage):
|
|
|
|
|
|
return super(CoderedLocationPage, self).save(*args, **kwargs)
|
|
|
|
|
|
-
|
|
|
def get_context(self, request, *args, **kwargs):
|
|
|
context = super().get_context(request)
|
|
|
- context['google_api_key'] = GoogleApiSettings.for_site(Site.objects.get(is_default_site=True)).google_maps_api_key
|
|
|
+ context['google_api_key'] = GoogleApiSettings.for_site(
|
|
|
+ Site.objects.get(is_default_site=True)
|
|
|
+ ).google_maps_api_key
|
|
|
return context
|
|
|
|
|
|
|
|
@@ -1826,7 +1858,9 @@ class CoderedLocationIndexPage(CoderedWebPage):
|
|
|
MaxValueValidator(20),
|
|
|
MinValueValidator(1),
|
|
|
],
|
|
|
- help_text=_('Requires API key to use zoom. 1: World, 5: Landmass/continent, 10: City, 15: Streets, 20: Buildings')
|
|
|
+ help_text=_(
|
|
|
+ "Requires API key to use zoom. 1: World, 5: Landmass/continent, 10: City, 15: Streets, 20: Buildings" # noqa
|
|
|
+ )
|
|
|
)
|
|
|
|
|
|
layout_panels = CoderedWebPage.layout_panels + [
|
|
@@ -1858,7 +1892,12 @@ class CoderedLocationIndexPage(CoderedWebPage):
|
|
|
southwest = [float(x) for x in southwest.split(',')]
|
|
|
northeast = [float(x) for x in northeast.split(',')]
|
|
|
|
|
|
- qs = qs.filter(latitude__gte=southwest[0], latitude__lte=northeast[0], longitude__gte=southwest[1], longitude__lte=northeast[1])
|
|
|
+ qs = qs.filter(
|
|
|
+ latitude__gte=southwest[0],
|
|
|
+ latitude__lte=northeast[0],
|
|
|
+ longitude__gte=southwest[1],
|
|
|
+ longitude__lte=northeast[1]
|
|
|
+ )
|
|
|
|
|
|
return {
|
|
|
"type": "FeatureCollection",
|
|
@@ -1879,5 +1918,7 @@ class CoderedLocationIndexPage(CoderedWebPage):
|
|
|
|
|
|
def get_context(self, request, *args, **kwargs):
|
|
|
context = super().get_context(request)
|
|
|
- context['google_api_key'] = GoogleApiSettings.for_site(Site.objects.get(is_default_site=True)).google_maps_api_key
|
|
|
+ context['google_api_key'] = GoogleApiSettings.for_site(
|
|
|
+ Site.objects.get(is_default_site=True)
|
|
|
+ ).google_maps_api_key
|
|
|
return context
|