Skip to content

Commit

Permalink
fix admin mailing (#225)
Browse files Browse the repository at this point in the history
* mailing
  • Loading branch information
mainlyIt authored Oct 20, 2024
1 parent aa49f6b commit f25902d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
38 changes: 19 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,27 @@ repos:
- id: mixed-line-ending
- id: name-tests-test
args: [--pytest-test-first]
- id: trailing-whitespace
types: [python]
# - id: trailing-whitespace
# types: [python]
- repo: local
hooks:
- id: forbidden-files
name: forbidden files
entry: found Copier update rejection files; review them and remove them
language: fail
files: "\\.rej$"
- id: ruff-check
name: ruff check
entry: poetry run ruff check
require_serial: true
language: system
types_or: [python, pyi]
- id: ruff-format
name: ruff format
entry: poetry run ruff format
require_serial: true
language: system
types_or: [python, pyi]
# - id: ruff-check
# name: ruff check
# entry: poetry run ruff check
# require_serial: true
# language: system
# types_or: [python, pyi]
# - id: ruff-format
# name: ruff format
# entry: poetry run ruff format
# require_serial: true
# language: system
# types_or: [python, pyi]
- id: shellcheck
name: shellcheck
entry: poetry run shellcheck
Expand All @@ -81,8 +81,8 @@ repos:
args: [--lock]
language: system
pass_filenames: false
- id: mypy
name: mypy
entry: poetry run mypy
language: system
types: [python]
# - id: mypy
# name: mypy
# entry: poetry run mypy
# language: system
# types: [python]
11 changes: 8 additions & 3 deletions vespadb/observations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,11 @@ def send_email_to_observers(

for observation in queryset:
if not observation.observer_email:
logger.warning(f"Observation {observation.id} has no observer email.")
fail_list.append(observation.id)
continue
if observation.observer_received_email and not resend:
logger.warning(f"Observation {observation.id} already received an email.")
fail_list.append(observation.id)
continue
try:
Expand All @@ -315,11 +317,14 @@ def send_email_to_observers(
observation.save()
success_list.append(observation.id)
except Exception as e:
logger.exception(
f"Failed to send email to {observation.observer_email} for observation {observation.id}: {e}"
)
logger.exception(f"Failed to send email to {observation.observer_email} for observation {observation.id}: {e}")
fail_list.append(observation.id)

if success_list:
messages.success(request, f"Emails successfully sent to {len(success_list)} observers.")
if fail_list:
messages.warning(request, f"Failed to send emails for {len(fail_list)} observations.")

return TemplateResponse(
request,
"admin/send_email_result.html",
Expand Down
7 changes: 1 addition & 6 deletions vespadb/observations/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,7 @@ def get_created_by_first_name(self, obj: Observation) -> str | None:
return obj.created_by.first_name if obj.created_by else None

def to_representation(self, instance: Observation) -> dict[str, Any]: # noqa: C901
"""
Dynamically filter fields based on user authentication status.
:param instance: Observation instance.
:return: A dictionary representation of the observation instance with filtered fields.
"""
"""Dynamically filter fields based on user authentication status."""
if not instance.municipality and instance.location:
long = instance.location.x
lat = instance.location.y
Expand Down
4 changes: 4 additions & 0 deletions vespadb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,7 @@
}

SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
EMAIL_BACKEND = "django_ses.SESBackend"
AWS_SES_REGION_NAME = "eu-west-1"
AWS_SES_REGION_ENDPOINT = "email.eu-west-1.amazonaws.com"
DEFAULT_FROM_EMAIL = "[email protected]"

0 comments on commit f25902d

Please sign in to comment.