Fix AddressDeleteView
This commit is contained in:
parent
216c4d9419
commit
d4b44d58c8
|
@ -4,9 +4,9 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<form method="post">
|
<form method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<p>{% blocktrans with address_name=object.full_address_name %}Are you sure that you want remove the address: "{{ address_name }}"?{% endblocktrans %}</p>
|
<p>{% blocktrans with address_name=object.email %}Are you sure that you want remove the address: "{{ address_name }}"?{% endblocktrans %}</p>
|
||||||
<p class="alert alert-warning"><strong>{% trans 'WARNING: This action cannot be undone.' %}</strong></p>
|
<p class="alert alert-warning"><strong>{% trans 'WARNING: This action cannot be undone.' %}</strong></p>
|
||||||
|
<a class="btn btn-light mr-2" href="{% url 'musician:address-update' object.pk %}">{% trans 'Cancel' %}</a>
|
||||||
<input class="btn btn-danger" type="submit" value="{% trans 'Delete' %}">
|
<input class="btn btn-danger" type="submit" value="{% trans 'Delete' %}">
|
||||||
<a class="btn btn-secondary" href="{% url 'musician:address-update' view.kwargs.pk %}">{% trans 'Cancel' %}</a>
|
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import logging
|
import logging
|
||||||
import smtplib
|
import smtplib
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.core.mail import mail_managers
|
from django.core.mail import mail_managers
|
||||||
|
from django.db.models.query import QuerySet
|
||||||
from django.http import (HttpResponse, HttpResponseNotFound,
|
from django.http import (HttpResponse, HttpResponseNotFound,
|
||||||
HttpResponseRedirect)
|
HttpResponseRedirect)
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
|
@ -290,6 +292,9 @@ class MailUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
|
||||||
success_url = reverse_lazy("musician:address-list")
|
success_url = reverse_lazy("musician:address-list")
|
||||||
extra_context = {'service': service_class}
|
extra_context = {'service': service_class}
|
||||||
|
|
||||||
|
def get_queryset(self) -> QuerySet[Any]:
|
||||||
|
return self.model.objects.filter(account=self.request.user)
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
kwargs = super().get_form_kwargs()
|
kwargs = super().get_form_kwargs()
|
||||||
kwargs["user"] = self.request.user
|
kwargs["user"] = self.request.user
|
||||||
|
@ -298,22 +303,11 @@ class MailUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
|
||||||
|
|
||||||
class AddressDeleteView(CustomContextMixin, UserTokenRequiredMixin, DeleteView):
|
class AddressDeleteView(CustomContextMixin, UserTokenRequiredMixin, DeleteView):
|
||||||
template_name = "musician/address_check_delete.html"
|
template_name = "musician/address_check_delete.html"
|
||||||
|
model = Address
|
||||||
success_url = reverse_lazy("musician:address-list")
|
success_url = reverse_lazy("musician:address-list")
|
||||||
|
|
||||||
def get_object(self, queryset=None):
|
def get_queryset(self) -> QuerySet[Any]:
|
||||||
obj = self.orchestra.retrieve_mail_address(self.kwargs['pk'])
|
return self.model.objects.filter(account=self.request.user)
|
||||||
return obj
|
|
||||||
|
|
||||||
def delete(self, request, *args, **kwargs):
|
|
||||||
self.object = self.get_object()
|
|
||||||
try:
|
|
||||||
self.orchestra.delete_mail_address(self.object.id)
|
|
||||||
messages.success(self.request, _('Address deleted!'))
|
|
||||||
except HTTPError as e:
|
|
||||||
messages.error(self.request, _('Cannot process your request, please try again later.'))
|
|
||||||
logger.error(e)
|
|
||||||
|
|
||||||
return HttpResponseRedirect(self.success_url)
|
|
||||||
|
|
||||||
|
|
||||||
class MailingListsView(ServiceListView):
|
class MailingListsView(ServiceListView):
|
||||||
|
|
Loading…
Reference in a new issue