Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send email action email field #40

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions form_designer/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

import warnings
from functools import partial

Expand Down Expand Up @@ -51,6 +53,13 @@ def validate_comma_separated_emails(value):
for v in value.split(","):
validate_email(v.strip())

def email_field_choices(form: Optional[forms.ModelForm], required: bool=True) -> list[tuple[str, str]]:
if not form or not form.instance or not form.instance.pk:
return []
email_fields = form.instance.fields.filter(type='email')
choices = [] if required else [('', '--')]
choices.extend([(_.name, _.title) for _ in email_fields])
return choices

class Form(models.Model):
CONFIG_OPTIONS = [
Expand Down Expand Up @@ -86,13 +95,13 @@ class Form(models.Model):
),
(
"author_email_field",
forms.CharField(
forms.ChoiceField(
label=capfirst(_("author's email field")),
help_text=_(
"The author of the submission will be added to the Cc: if this is set to an existing form field below."
),
required=False,
widget=widgets.AdminTextInputWidget,
choices=email_field_choices(form, required=False),
),
),
],
Expand Down