Skip to content

Commit

Permalink
add email list field
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin-Sun-tts committed Jul 1, 2024
1 parent c40cecd commit d16ff72
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ HARVEST_SOURCE_PORT=80
HARVEST_SOURCE_URL=http://localhost:${HARVEST_SOURCE_PORT}
CF_API_URL=https://api.fr.cloud.gov
HARVEST_RUNNER_APP_GUID=e6a8bba8-ed6d-4200-8280-67b46cebdc63
CLIENT_ID=urn:gov:gsa:openidconnect.profiles:sp:sso:gsa:datagov-dev-harvest-admin
CLIENT_ID=urn:gov:gsa:openidconnect.profiles:sp:sso:gsa:datagov-local-harvest-admin
ISSUER=https://idp.int.identitysandbox.gov
REDIRECT_URI=http://localhost:8080/callback
FLASK_APP_SECRET_KEY=Px4o0MPEsCzHJRRSUDyt1VRi-lYF2W5VEzR13lylAgI
Expand Down
12 changes: 9 additions & 3 deletions app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@
from wtforms import SelectField, StringField, TextAreaField
from wtforms.validators import URL, DataRequired, ValidationError


def validate_email_list(form, field):
emails = field.data.split(",")
emails = field.data
for email in emails:
if not re.match(r"[^@]+@[^@]+\.[^@]+", email.strip()):
raise ValidationError("Invalid email address: {}".format(email))

class EmailListField(TextAreaField):
def process_formdata(self, valuelist):
if valuelist:
raw_data = valuelist[0].replace("\r\n", ", ")
self.data = [email.strip() for email in raw_data .split(',')]
else:
self.data = []

class HarvestSourceForm(FlaskForm):
organization_id = SelectField(
"Organization", choices=[], validators=[DataRequired()]
)
name = StringField("Name", validators=[DataRequired()])
url = StringField("URL", validators=[DataRequired(), URL()])
notification_emails = TextAreaField(
notification_emails = EmailListField(
"Notification_emails", validators=[DataRequired(), validate_email_list]
)
frequency = SelectField(
Expand Down
2 changes: 1 addition & 1 deletion app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def remove_user(email):
def make_new_source_contract(form):
return {
"name": form.name.data,
"notification_emails": form.notification_emails.data.replace("\r\n", ", "),
"notification_emails": form.notification_emails.data,
"frequency": form.frequency.data,
"user_requested_frequency": form.frequency.data,
"url": form.url.data,
Expand Down

1 comment on commit d16ff72

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests Skipped Failures Errors Time
2 0 💤 0 ❌ 0 🔥 8.227s ⏱️

Please sign in to comment.