Skip to content

Commit

Permalink
feat(tup-308): working form plugin (aka tup-230) (#498)
Browse files Browse the repository at this point in the history
* feat(tup-230): working form plugin

* docs(tup-230): clarify form submission failure

* feat(tup-230): use jquery version that has ajax

The django-forms(-maintained) plugin expects jquery with ajax features.

Our CMS was using a slim build of jQuery.

The size difference is 17KB, which I consider negligible.

* feat(tup-230): make spam protection available

* feat(tup-230): e-mail template (when e-mail works)

* docs(tup-230): tweak comment in settings

* fix(tup-230): comments & semantic html in template

* fix(tup-230): revert and make some html changes

- less changes form original
- sometimes the original html was better for styling

* feat(tup-230): style form (no design review yet)

Also, no button styling yet.

* chore(tup-230): rename css file, add pointer file

Pointer file mimics what I do for blog CSS, which is also in source.

* chore(settings): tup-308, how to set captcha keys

Ref: TACC/Core-Portal-Deployments@48e6e9c

* noop(settings): tup-308, add new line

* fix(settings): tup-308, use new form css from #500

* fix(settings): tup-308, new form templates by #500

Not a straight clone of #500.

I added a little CSS and a small document to avoid cloning one template.

See:
- default.html.md
- django.cms.forms.css

* noop(settings): tup-308, form settings from #501

* fix(settings): tup-308, css changes from #501

* fix(settings): tup-308, "*" to "(required)"

I use a different solution than #501.

In #501, markup was changed to "(require)":
https://github.com/TACC/Core-CMS/blob/5f63bdf/taccsite_cms/templates/djangocms_forms/form_template/default.html#L27

But here, I do not edit the markup, so no need to clone template:
https://github.com/TACC/Core-CMS/blob/8a46a21/taccsite_cms/templates/djangocms_forms/form_template/default.html.md

* fix(css): tup-308, small form style issues

- bigger gap between single checkbox and input
- add gap between multiple checkbox and input
- align multiple checkbox and input
- simpler, less specific checkbox label selector
- remove undesired label margin*

* This style was ineffectual—good—in 3.6, but "fixed"—bad—when ported.

* fix(css): tup-308, small form style issues

- limit which help text gets margin
- remove ineffectual, unnecessary margin removal
- bigger gap between single checkbox and input
- align single checkbox and input
- add gap between multiple checkbox and input
- align multiple checkbox and input
- remove label margin on last of multiple checkboxes/radios
- simpler, less specific checkbox label selector
- remove undesired label margin*

* This style was ineffectual—good—in 3.6, but "fixed"—bad—when ported.

* docs(styles): typo fix for KSS comment

* fix(form): tup-308 only working export formats

1. Only let users export with supported formats.
2. Update form version to rev. that supports this.

Source: avryhof/djangocms-forms#8

* fix(form): delete unnecessary cloned template

* fix(form): tup-308, clean up templates

- remove unedited cloned template
- update commit in a comment

* fix(form): tup-308, move form export settings

* fix(form): tup-308, remove unused file

I forgot to delete this file earlier.

* fix(form): tup-308, remove redundant script

The removal happens form a merged PR on the plugin:
avryhof/djangocms-forms#12

* chore(core-styles): v0.7.0-beta

* fix(taccsite_custom): get main relevant PRs merged

* docs(form): no commented settings
  • Loading branch information
wesleyboar authored Jul 15, 2022
1 parent 6f47848 commit f65d0c4
Show file tree
Hide file tree
Showing 17 changed files with 425 additions and 34 deletions.
33 changes: 25 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ djangocms-blog = "1.1.1"
djangocms-bootstrap4 = "2.0.0"
djangocms-column = "1.11.0"
djangocms-file = "3.0.0"
djangocms-forms = "0.2.5"
djangocms-forms-maintained = { git = "https://github.com/avryhof/djangocms-forms", rev = "eaa6415efeefc8a3018450d0ca7b864e0e4b9dd2" }
djangocms-googlemap = "2.0.0"
djangocms-icon = "2.0.0"
djangocms-link = "3.0.0"
Expand Down
116 changes: 116 additions & 0 deletions taccsite_cms/_settings/form_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
"""Configure djangocms_forms and related apps"""

from django.utils.translation import gettext_lazy as _

########################
# KNOWN ISSUES
########################

# Unable to export to Excel nor YAML
# (No success hiding those formats from editor)
# https://github.com/avryhof/djangocms-forms/issues/8

########################
# DJANGO_RECAPTCHA
# https://github.com/avryhof/django-recaptcha/
########################

# To properly avoid client error about using test keys,
# define RECAPTCHA_..._KEY settings on client-facing servers

########################
# DJANGOCMS_FORMS
# https://github.com/avryhof/djangocms-forms/
########################

DJANGOCMS_FORMS_USE_HTML5_REQUIRED = True

DJANGOCMS_FORMS_SPAM_PROTECTIONS = (
(0, _('None')),
# (1, _('Honeypot')), # if necessary, learn how to use
(2, _('ReCAPTCHA')),
)
DEFAULT_SPAM_PROTECTION = 0

# Improve form legibility and conceal unavailable features
# https://github.com/avryhof/djangocms-forms/blob/97d7c21/djangocms_forms/cms_plugins.py#L69-L121
DJANGOCMS_FORMS_FIELDSETS = (
(None, {'fields': ('name', 'form_template',),}),
(
_('Text'),
{
'description': _(
'The <strong>Title</strong> and <strong>Description</strong> '
'will display above the input fields and Submit button.'
),
'fields': ('title', 'description','submit_btn_txt',),
},
),
(
None,
{
'description': _(
'You can change the message that appears <em>after</em> someone submits your form. By default, this says "<strong>Thank you!</strong>"'
),
'fields': ('post_submit_msg',),
},
),
(
_('Redirect settings'),
{
'description': _(
'Whether and how to redirect the form <em>after</em> submission.'
),
'fields': ('success_redirect', ('page_redirect', 'external_redirect'), 'redirect_delay',),
}
),
(
_('Submission settings'),
{
'description': 'Whether to save form data.',
'fields': (
'save_data',
'spam_protection',
),
},
),
(
_('Submission e-mail (unavailable feature)'),
{
'classes': ('collapse',),
'description': 'Choose storage options to capture form data. You can enter an e-mail address to which to e-mail form submissions.',
'fields': (
# Submitting form with 'email_to' defined causes server error
# FAQ: We may need to setup some django e-mail server for these
'email_to',
'email_from',
'email_subject',
'email_uploaded_files',
),
},
),
)

DJANGOCMS_FORMS_FORMAT_CHOICES = (
("csv", _("CSV")),
("json", _("JSON")),
)

########################
# DJANGO
# https://docs.djangoproject.com/en/2.2/ref/settings/#form-renderer
########################

# Allow form template override
# https://github.com/torchbox/django-recaptcha/issues/211#issuecomment-675608391
FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'

########################
# DJANGO CMS
########################

_INSTALLED_APPS = [
'djangocms_forms', # form plugin for editors
'django.forms', # support form template override
'captcha', # support recaptcha for djangocms_forms
]
29 changes: 7 additions & 22 deletions taccsite_cms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

from django.utils.translation import gettext_lazy as _

from taccsite_cms._settings.form_plugin import *
from taccsite_cms._settings.form_plugin import (
_INSTALLED_APPS as form_plugin_INSTALLED_APPS
)

SECRET_KEY = 'CHANGE_ME'
def gettext(s): return s

Expand Down Expand Up @@ -93,16 +98,6 @@ def gettext(s): return s
GOOGLE_ANALYTICS_PROPERTY_ID = "UA-123ABC@%$&-#"
GOOGLE_ANALYTICS_PRELOAD = True

########################
# CMS FORMS
########################

# Create CMS Forms
# SEE: https://pypi.org/project/djangocms-forms/
# SEE: https://www.google.com/recaptcha/admin/create
DJANGOCMS_FORMS_RECAPTCHA_PUBLIC_KEY = ""
DJANGOCMS_FORMS_RECAPTCHA_SECRET_KEY = ""

########################
# ELASTICSEARCH
########################
Expand Down Expand Up @@ -352,6 +347,8 @@ def gettext(s): return s
'aldryn_apphooks_config', # search index & django CMS Blog
'test_without_migrations', # run tests faster

] + form_plugin_INSTALLED_APPS + [

# core TACC CMS
# HELP: If this were top of list, would TACC/Core-CMS/pull/169 fix break?
'taccsite_cms',
Expand Down Expand Up @@ -461,18 +458,6 @@ def get_subdirs_as_module_names(path):

DJANGOCMS_AUDIO_ALLOWED_EXTENSIONS = ['mp3', 'ogg', 'wav']

# Djangocms Forms Settings.
# SEE: https://github.com/mishbahr/djangocms-forms#configuration
DJANGOCMS_FORMS_PLUGIN_MODULE = ('Generic')
DJANGOCMS_FORMS_PLUGIN_NAME = ('Form')

DJANGOCMS_FORMS_TEMPLATES = (
('djangocms_forms/form_template/default.html', ('Default')),
)
DJANGOCMS_FORMS_USE_HTML5_REQUIRED = False

DJANGOCMS_FORMS_REDIRECT_DELAY = 1

# Elasticsearch Indexing
HAYSTACK_ROUTERS = ['aldryn_search.router.LanguageRouter', ]
HAYSTACK_SIGNAL_PROCESSOR = 'taccsite_cms.signal_processor.RealtimeSignalProcessor'
Expand Down
3 changes: 3 additions & 0 deletions taccsite_cms/static/djangocms_forms/css/djangocms_forms.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* SEE: ../../site_cms/css/src/app.djangocms_forms.css */
/* FAQ: We uses future syntax that must be processed to work in the present;
and the process does not support outputting files to this directory */
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@import url("@tacc/core-styles/src/lib/_imports/components/c-button.css");

.c-button {
--max-width: unset;

font-size: 1.6rem;
}
Loading

0 comments on commit f65d0c4

Please sign in to comment.