-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* uat release okt
- Loading branch information
Showing
7 changed files
with
87 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,7 +217,7 @@ def get_urls(self) -> Any: | |
custom_urls = [ | ||
path("import-file/", self.admin_site.admin_view(self.import_file), name="import_file"), | ||
path("bulk-import/", self.admin_site.admin_view(self.bulk_import_view), name="bulk_import"), | ||
path("send-email/", self.admin_site.admin_view(self.send_email_to_observers), name="send-email"), | ||
path("send-email/", self.admin_site.admin_view(self.send_email_view), name="send-email"), # Correcte URL naam | ||
] | ||
return custom_urls + urls | ||
|
||
|
@@ -279,25 +279,19 @@ def bulk_import_view(self, request: HttpRequest) -> HttpResponse: | |
else: | ||
self.message_user(request, f"Failed to import observations: {response.data}", level="error") | ||
return redirect("admin:observations_observation_changelist") | ||
|
||
@admin.action(description="Verzend emails naar observatoren") | ||
def send_email_to_observers( | ||
self, request: HttpRequest, queryset: QuerySet[Observation] | ||
) -> TemplateResponse | HttpResponse: | ||
""" | ||
Send emails to the observers of the selected observations. | ||
:param request: HttpRequest object | ||
:param queryset: QuerySet of selected observations | ||
:return: TemplateResponse or HttpResponse object | ||
""" | ||
if "apply" in request.POST: | ||
|
||
def send_email_view(self, request: HttpRequest) -> HttpResponse: | ||
"""View to display the form and send emails.""" | ||
if request.method == 'POST': | ||
form = SendEmailForm(request.POST) | ||
if form.is_valid(): | ||
subject = form.cleaned_data["subject"] | ||
message = form.cleaned_data["message"] | ||
resend = form.cleaned_data["resend"] | ||
|
||
selected_observations = request.session.get('selected_observations', []) | ||
queryset = Observation.objects.filter(pk__in=selected_observations) | ||
|
||
success_list = [] | ||
fail_list = [] | ||
|
||
|
@@ -312,7 +306,7 @@ def send_email_to_observers( | |
continue | ||
try: | ||
send_mail(subject, message, "[email protected]", [observation.observer_email]) | ||
logger.info(f"Email sent to {observation.observer_email} for observation {observation.id}") | ||
logger.debug(f"Email sent to {observation.observer_email} for observation {observation.id}") | ||
observation.observer_received_email = True | ||
observation.save() | ||
success_list.append(observation.id) | ||
|
@@ -325,19 +319,22 @@ def send_email_to_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", | ||
{ | ||
"success_list": success_list, | ||
"fail_list": fail_list, | ||
}, | ||
) | ||
|
||
return redirect('admin:observations_observation_changelist') | ||
else: | ||
form = SendEmailForm() | ||
|
||
return render(request, "admin/send_email.html", {"observations": queryset, "form": form}) | ||
return render(request, 'admin/send_email.html', {'form': form}) | ||
|
||
@admin.action(description="Verzend emails naar observatoren") | ||
def send_email_to_observers(self, request: HttpRequest, queryset: QuerySet[Observation]) -> HttpResponse: | ||
""" | ||
Action to prepare sending emails. | ||
""" | ||
# Sla de geselecteerde observaties op in de sessie | ||
request.session['selected_observations'] = list(queryset.values_list('pk', flat=True)) | ||
|
||
# Redirect naar de juiste naam van de custom URL | ||
return redirect('admin:send-email') | ||
|
||
@admin.action(description="Markeer observatie(s) als bestreden") | ||
def mark_as_eradicated(self, request: HttpRequest, queryset: Any) -> None: | ||
|
18 changes: 18 additions & 0 deletions
18
vespadb/observations/migrations/0029_alter_observation_observer_phone_number.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.0.6 on 2024-10-22 11:11 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('observations', '0028_alter_observation_eradication_duration'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='observation', | ||
name='observer_phone_number', | ||
field=models.CharField(blank=True, help_text='Phone number of the observer', max_length=50, null=True), | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
vespadb/observations/migrations/0030_alter_observation_observer_phone_number.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.0.6 on 2024-10-22 11:51 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('observations', '0029_alter_observation_observer_phone_number'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='observation', | ||
name='observer_phone_number', | ||
field=models.CharField(blank=True, help_text='Phone number of the observer', max_length=200, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters