|
|
|
@ -10,13 +10,14 @@ from .models import Maintainer, Contact, InetNum, ASBlock, ASNumber
|
|
|
|
|
from .forms import MntForm, MntInitialForm, ContactForm, ContactInitialForm, InetNumForm
|
|
|
|
|
from .generic import DeleteCheckView
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
def dbDashboard(request):
|
|
|
|
|
mnts = request.user.maintainer_set.all()
|
|
|
|
|
contacts = Contact.objects.filter(mnt_by__in=mnts)
|
|
|
|
|
netblocks = InetNum.objects.filter(Q(mnt_by__in=mnts)|Q(mnt_lower__in=mnts))
|
|
|
|
|
asblocks = ASBlock.objects.filter(Q(mnt_by__in=mnts)|Q(mnt_lower__in=mnts))
|
|
|
|
|
asnumbers = ASNumber.objects.filter(Q(mnt_by__in=mnts)|Q(mnt_lower__in=mnts))
|
|
|
|
|
netblocks = InetNum.objects.filter(Q(mnt_by__in=mnts) | Q(mnt_lower__in=mnts)).distinct()
|
|
|
|
|
asblocks = ASBlock.objects.filter(Q(mnt_by__in=mnts) | Q(mnt_lower__in=mnts)).distinct()
|
|
|
|
|
asnumbers = ASNumber.objects.filter(Q(mnt_by__in=mnts) | Q(mnt_lower__in=mnts)).distinct()
|
|
|
|
|
mntForm = contactForm = None
|
|
|
|
|
|
|
|
|
|
if mnts.count() == 0:
|
|
|
|
@ -49,6 +50,7 @@ def dbDashboard(request):
|
|
|
|
|
|
|
|
|
|
return render(request, "whoisdb/overview.html", {"mnts": mnts, "contacts": contacts, "mntForm": mntForm, "contactForm": contactForm, "netblocks": netblocks, "asblocks": asblocks, "asnumbers": asnumbers})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MaintainerCreate(LoginRequiredMixin, CreateView):
|
|
|
|
|
template_name = "whoisdb/obj_create.html"
|
|
|
|
|
form_class = MntForm
|
|
|
|
@ -71,6 +73,7 @@ class MaintainerCreate(LoginRequiredMixin, CreateView):
|
|
|
|
|
|
|
|
|
|
return super(MaintainerCreate, self).form_valid(form)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MaintainerEdit(LoginRequiredMixin, UpdateView):
|
|
|
|
|
template_name = "whoisdb/maintainer_edit.html"
|
|
|
|
|
model = Maintainer
|
|
|
|
@ -86,6 +89,7 @@ class MaintainerEdit(LoginRequiredMixin, UpdateView):
|
|
|
|
|
def get_queryset(self):
|
|
|
|
|
return self.model.objects.filter(auth=self.request.user)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MaintainerDelete(LoginRequiredMixin, DeleteCheckView):
|
|
|
|
|
template_name = "whoisdb/obj_delete.html"
|
|
|
|
|
model = Maintainer
|
|
|
|
@ -95,7 +99,7 @@ class MaintainerDelete(LoginRequiredMixin, DeleteCheckView):
|
|
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
|
return self.model.objects.filter(auth=self.request.user)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MaintainerDetail(LoginRequiredMixin, DetailView):
|
|
|
|
|
model = Maintainer
|
|
|
|
@ -103,12 +107,14 @@ class MaintainerDetail(LoginRequiredMixin, DetailView):
|
|
|
|
|
slug_url_kwarg = "handle"
|
|
|
|
|
context_object_name = "mnt"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ContactDetail(DetailView):
|
|
|
|
|
model = Contact
|
|
|
|
|
slug_field = "handle"
|
|
|
|
|
slug_url_kwarg = "handle"
|
|
|
|
|
context_object_name = "contact"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ContactEdit(LoginRequiredMixin, UpdateView):
|
|
|
|
|
template_name = "whoisdb/obj_edit.html"
|
|
|
|
|
model = Contact
|
|
|
|
@ -125,6 +131,7 @@ class ContactEdit(LoginRequiredMixin, UpdateView):
|
|
|
|
|
# FIXME: we need all maintainers to be available. autofill own maintainers
|
|
|
|
|
return self.model.objects.filter(mnt_by__in=self.request.user.maintainer_set.all())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ContactCreate(LoginRequiredMixin, CreateView):
|
|
|
|
|
template_name = "whoisdb/obj_create.html"
|
|
|
|
|
form_class = ContactForm
|
|
|
|
@ -138,6 +145,7 @@ class ContactCreate(LoginRequiredMixin, CreateView):
|
|
|
|
|
}
|
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ContactDelete(LoginRequiredMixin, DeleteCheckView):
|
|
|
|
|
template_name = "whoisdb/obj_delete.html"
|
|
|
|
|
model = Contact
|
|
|
|
@ -148,6 +156,7 @@ class ContactDelete(LoginRequiredMixin, DeleteCheckView):
|
|
|
|
|
def get_queryset(self):
|
|
|
|
|
return self.model.objects.filter(mnt_by__in=self.request.user.maintainer_set.all())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# InetNum
|
|
|
|
|
class InetNumCreate(LoginRequiredMixin, CreateView):
|
|
|
|
|
template_name = "whoisdb/obj_create.html"
|
|
|
|
@ -158,7 +167,51 @@ class InetNumCreate(LoginRequiredMixin, CreateView):
|
|
|
|
|
kwargs["user"] = self.request.user
|
|
|
|
|
kwargs["initial"] = {
|
|
|
|
|
"handle": "AUTO",
|
|
|
|
|
"type": Contact.TYPE_PERSON
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InetNumDetail(DetailView):
|
|
|
|
|
model = InetNum
|
|
|
|
|
slug_field = "handle"
|
|
|
|
|
slug_url_kwarg = "handle"
|
|
|
|
|
context_object_name = "inetnum"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InetNumEdit(LoginRequiredMixin, UpdateView):
|
|
|
|
|
template_name = "whoisdb/obj_edit.html"
|
|
|
|
|
model = InetNum
|
|
|
|
|
form_class = InetNumForm
|
|
|
|
|
slug_field = "handle"
|
|
|
|
|
slug_url_kwarg = "handle"
|
|
|
|
|
|
|
|
|
|
def get_form_kwargs(self, *args, **kwargs):
|
|
|
|
|
kwargs = super(InetNumEdit, self).get_form_kwargs(*args, **kwargs)
|
|
|
|
|
kwargs["user"] = self.request.user
|
|
|
|
|
|
|
|
|
|
mnts = self.request.user.maintainer_set.all()
|
|
|
|
|
if not any(mnt in self.object.mnt_by.all() for mnt in mnts):
|
|
|
|
|
# we are in mnt_lower
|
|
|
|
|
kwargs["lower"] = True
|
|
|
|
|
|
|
|
|
|
kwargs["initial"] = {'prefix': str(self.object.getNetwork())}
|
|
|
|
|
|
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
|
# FIXME: we need all maintainers to be available. autofill own maintainers
|
|
|
|
|
mnts = self.request.user.maintainer_set.all()
|
|
|
|
|
return self.model.objects.filter(Q(mnt_by__in=mnts) | Q(mnt_lower__in=mnts)).distinct()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InetNumDelete(LoginRequiredMixin, DeleteCheckView):
|
|
|
|
|
template_name = "whoisdb/obj_delete.html"
|
|
|
|
|
model = InetNum
|
|
|
|
|
slug_field = "handle"
|
|
|
|
|
slug_url_kwarg = "handle"
|
|
|
|
|
success_url = reverse_lazy("whoisdb:dashboard")
|
|
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
|
mnts = self.request.user.maintainer_set.all()
|
|
|
|
|
return self.model.objects.filter(Q(mnt_by__in=mnts) | Q(mnt_lower__in=mnts))
|
|
|
|
|