Allow add and update domain's record

This commit is contained in:
Santiago L 2023-11-29 12:42:54 +01:00
parent f26b2f0e87
commit a6be3e5b00
6 changed files with 63 additions and 5 deletions

View file

@ -153,3 +153,10 @@ class RecordCreateForm(forms.ModelForm):
if commit:
super().save(commit=True)
return instance
class RecordUpdateForm(forms.ModelForm):
class Meta:
model = Record
fields = ("ttl", "type", "value")

View file

@ -22,7 +22,13 @@
{% for record in object.records.all %}
<tr>
<td>{{ record.type }}</td>
<td>{{ record.value }}</td>
<td>
<a href="{% url 'musician:domain-update-record' object.pk record.pk %}">
{{ record.value }}
<i class="ml-3 fas fa-edit"></i></a>
<a href="{% url 'musician:domain-delete-record' object.pk record.pk %}">
<i class="ml-3 text-danger fas fa-trash"></i></a>
</td>
</tr>
{% endfor %}
</tbody>

View file

@ -0,0 +1,13 @@
{% extends "musician/base.html" %}
{% load i18n %}
{% block content %}
<form method="post">
{% csrf_token %}
<p>{% blocktrans %}Are you sure that you want remove the following record"?{% endblocktrans %}</p>
<pre>{{ object.type}} {{ object.value}}</pre>
<p class="alert alert-warning"><strong>{% trans 'WARNING: This action cannot be undone.' %}</strong></p>
<input class="btn btn-danger" type="submit" value="{% trans 'Delete' %}">
<a class="btn btn-secondary" href="{% url 'musician:domain-detail' view.kwargs.pk %}">{% trans 'Cancel' %}</a>
</form>
{% endblock %}

View file

@ -2,7 +2,7 @@
{% load bootstrap4 i18n %}
{% block content %}
<a class="btn-arrow-left" href="{% url 'musician:domain-detail' form.domain.pk %}">{% trans "Go back" %}</a>
<a class="btn-arrow-left" href="{% url 'musician:domain-detail' view.kwargs.pk %}">{% trans "Go back" %}</a>
<h1 class="service-name">{% trans "Add record for" %} <span class="font-weight-light">{{ form.domain.name }}</span></h1>
@ -10,11 +10,11 @@
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<a class="btn btn-light mr-2" href="{% url 'musician:domain-detail' form.domain.pk %}"">{% trans "Cancel" %}</a>
<a class="btn btn-light mr-2" href="{% url 'musician:domain-detail' view.kwargs.pk %}"">{% trans "Cancel" %}</a>
<button type="submit" class="btn btn-secondary">{% trans "Save" %}</button>
{% if form.instance.pk %}
<div class="float-right">
<a class="btn btn-danger" href="{% url 'musician:domain-record-delete' form.instance.pk %}">{% trans "Delete" %}</a>
<a class="btn btn-danger" href="{% url 'musician:domain-delete-record' view.kwargs.pk form.instance.pk %}">{% trans "Delete" %}</a>
</div>
{% endif %}
{% endbuttons %}

View file

@ -14,8 +14,12 @@ urlpatterns = [
path('auth/login/', views.LoginView.as_view(), name='login'),
path('auth/logout/', views.LogoutView.as_view(), name='logout'),
path('dashboard/', views.DashboardView.as_view(), name='dashboard'),
path('domains/<int:pk>/', views.DomainDetailView.as_view(), name='domain-detail'),
path('domains/<int:pk>/add-record/', views.DomainAddRecordView.as_view(), name='domain-add-record'),
path('domains/<int:pk>/records/<int:record_pk>/update/', views.DomainUpdateRecordView.as_view(), name='domain-update-record'),
path('domains/<int:pk>/records/<int:record_pk>/delete/', views.DomainDeleteRecordView.as_view(), name='domain-delete-record'),
path('billing/', views.BillingView.as_view(), name='billing'),
path('bills/<int:pk>/download/', views.BillDownloadView.as_view(), name='bill-download'),
path('profile/', views.ProfileView.as_view(), name='profile'),

View file

@ -33,7 +33,8 @@ from orchestra.utils.html import html_to_pdf
# from .auth import login as auth_login
from .auth import logout as auth_logout
from .forms import (LoginForm, MailboxChangePasswordForm, MailboxCreateForm,
MailboxUpdateForm, MailForm, RecordCreateForm)
MailboxUpdateForm, MailForm, RecordCreateForm,
RecordUpdateForm)
from .mixins import (CustomContextMixin, ExtendedPaginationMixin,
UserTokenRequiredMixin)
from .models import Address as AddressService
@ -483,6 +484,33 @@ class DomainAddRecordView(CustomContextMixin, UserTokenRequiredMixin, CreateView
return reverse_lazy("musician:domain-detail", kwargs={"pk": self.kwargs["pk"]})
class DomainUpdateRecordView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
model = Record
form_class = RecordUpdateForm
template_name = "musician/record_form.html"
pk_url_kwarg = "record_pk"
def get_queryset(self):
qs = Record.objects.filter(domain__account=self.request.user, domain=self.kwargs["pk"])
return qs
def get_success_url(self):
return reverse_lazy("musician:domain-detail", kwargs={"pk": self.kwargs["pk"]})
class DomainDeleteRecordView(CustomContextMixin, UserTokenRequiredMixin, DeleteView):
model = Record
template_name = "musician/record_confirm_delete.html"
pk_url_kwarg = "record_pk"
def get_queryset(self):
qs = Record.objects.filter(domain__account=self.request.user, domain=self.kwargs["pk"])
return qs
def get_success_url(self):
return reverse_lazy("musician:domain-detail", kwargs={"pk": self.kwargs["pk"]})
class LoginView(FormView):
template_name = 'auth/login.html'
form_class = LoginForm