Allow user to create a new record on a domain
This commit is contained in:
parent
7c85f219d8
commit
f26b2f0e87
|
@ -3,7 +3,7 @@ from django.contrib.auth.forms import AuthenticationForm
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from orchestra.contrib.domains.models import Domain
|
from orchestra.contrib.domains.models import Domain, Record
|
||||||
from orchestra.contrib.mailboxes.models import Address, Mailbox
|
from orchestra.contrib.mailboxes.models import Address, Mailbox
|
||||||
|
|
||||||
from . import api
|
from . import api
|
||||||
|
@ -131,6 +131,25 @@ class MailboxCreateForm(forms.ModelForm):
|
||||||
|
|
||||||
class MailboxUpdateForm(forms.ModelForm):
|
class MailboxUpdateForm(forms.ModelForm):
|
||||||
addresses = forms.MultipleChoiceField(required=False)
|
addresses = forms.MultipleChoiceField(required=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
fields = ('addresses',)
|
fields = ('addresses',)
|
||||||
model = Mailbox
|
model = Mailbox
|
||||||
|
|
||||||
|
|
||||||
|
class RecordCreateForm(forms.ModelForm):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Record
|
||||||
|
fields = ("ttl", "type", "value")
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.domain = kwargs.pop('domain')
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def save(self, commit=True):
|
||||||
|
instance = super().save(commit=False)
|
||||||
|
instance.domain = self.domain
|
||||||
|
if commit:
|
||||||
|
super().save(commit=True)
|
||||||
|
return instance
|
||||||
|
|
|
@ -27,4 +27,5 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<a class="btn btn-primary mt-4 mb-4" href="{% url 'musician:domain-add-record' object.pk %}">{% trans "Add new record" %}</a></td>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
{% extends "musician/base.html" %}
|
||||||
|
{% load bootstrap4 i18n %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<a class="btn-arrow-left" href="{% url 'musician:domain-detail' form.domain.pk %}">{% trans "Go back" %}</a>
|
||||||
|
|
||||||
|
<h1 class="service-name">{% trans "Add record for" %} <span class="font-weight-light">{{ form.domain.name }}</span></h1>
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{% bootstrap_form form %}
|
||||||
|
{% buttons %}
|
||||||
|
<a class="btn btn-light mr-2" href="{% url 'musician:domain-detail' form.domain.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>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endbuttons %}
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
|
@ -8,7 +8,6 @@ from django.urls import path
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
|
|
||||||
app_name = 'musician'
|
app_name = 'musician'
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
@ -16,6 +15,7 @@ urlpatterns = [
|
||||||
path('auth/logout/', views.LogoutView.as_view(), name='logout'),
|
path('auth/logout/', views.LogoutView.as_view(), name='logout'),
|
||||||
path('dashboard/', views.DashboardView.as_view(), name='dashboard'),
|
path('dashboard/', views.DashboardView.as_view(), name='dashboard'),
|
||||||
path('domains/<int:pk>/', views.DomainDetailView.as_view(), name='domain-detail'),
|
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('billing/', views.BillingView.as_view(), name='billing'),
|
path('billing/', views.BillingView.as_view(), name='billing'),
|
||||||
path('bills/<int:pk>/download/', views.BillDownloadView.as_view(), name='bill-download'),
|
path('bills/<int:pk>/download/', views.BillDownloadView.as_view(), name='bill-download'),
|
||||||
path('profile/', views.ProfileView.as_view(), name='profile'),
|
path('profile/', views.ProfileView.as_view(), name='profile'),
|
||||||
|
|
|
@ -24,7 +24,7 @@ from requests.exceptions import HTTPError
|
||||||
from orchestra import get_version
|
from orchestra import get_version
|
||||||
from orchestra.contrib.bills.models import Bill
|
from orchestra.contrib.bills.models import Bill
|
||||||
from orchestra.contrib.databases.models import Database
|
from orchestra.contrib.databases.models import Database
|
||||||
from orchestra.contrib.domains.models import Domain
|
from orchestra.contrib.domains.models import Domain, Record
|
||||||
from orchestra.contrib.lists.models import List
|
from orchestra.contrib.lists.models import List
|
||||||
from orchestra.contrib.mailboxes.models import Address, Mailbox
|
from orchestra.contrib.mailboxes.models import Address, Mailbox
|
||||||
from orchestra.contrib.saas.models import SaaS
|
from orchestra.contrib.saas.models import SaaS
|
||||||
|
@ -33,7 +33,7 @@ from orchestra.utils.html import html_to_pdf
|
||||||
# from .auth import login as auth_login
|
# from .auth import login as auth_login
|
||||||
from .auth import logout as auth_logout
|
from .auth import logout as auth_logout
|
||||||
from .forms import (LoginForm, MailboxChangePasswordForm, MailboxCreateForm,
|
from .forms import (LoginForm, MailboxChangePasswordForm, MailboxCreateForm,
|
||||||
MailboxUpdateForm, MailForm)
|
MailboxUpdateForm, MailForm, RecordCreateForm)
|
||||||
from .mixins import (CustomContextMixin, ExtendedPaginationMixin,
|
from .mixins import (CustomContextMixin, ExtendedPaginationMixin,
|
||||||
UserTokenRequiredMixin)
|
UserTokenRequiredMixin)
|
||||||
from .models import Address as AddressService
|
from .models import Address as AddressService
|
||||||
|
@ -468,6 +468,21 @@ class DomainDetailView(CustomContextMixin, UserTokenRequiredMixin, DetailView):
|
||||||
return Domain.objects.filter(account=self.request.user)
|
return Domain.objects.filter(account=self.request.user)
|
||||||
|
|
||||||
|
|
||||||
|
class DomainAddRecordView(CustomContextMixin, UserTokenRequiredMixin, CreateView):
|
||||||
|
model = Record
|
||||||
|
form_class = RecordCreateForm
|
||||||
|
template_name = "musician/record_form.html"
|
||||||
|
|
||||||
|
def get_form_kwargs(self):
|
||||||
|
kwargs = super().get_form_kwargs()
|
||||||
|
domain = get_object_or_404(Domain, account=self.request.user, pk=self.kwargs["pk"])
|
||||||
|
kwargs['domain'] = domain
|
||||||
|
return kwargs
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return reverse_lazy("musician:domain-detail", kwargs={"pk": self.kwargs["pk"]})
|
||||||
|
|
||||||
|
|
||||||
class LoginView(FormView):
|
class LoginView(FormView):
|
||||||
template_name = 'auth/login.html'
|
template_name = 'auth/login.html'
|
||||||
form_class = LoginForm
|
form_class = LoginForm
|
||||||
|
|
Loading…
Reference in New Issue