This commit is contained in:
Sebastian Lohff 2017-02-28 19:44:15 +01:00
parent e3311a6df7
commit 814a8b62cb
18 changed files with 576 additions and 40 deletions

4
README
View File

@ -2,3 +2,7 @@ whoisdb
see own objects
list of all ASses?
FIXME
contact soll nur einen mnt_by haben
mnt_by ==> mnt_by_in in filter statements

View File

@ -0,0 +1,15 @@
{% extends "base.html" %}
{% block content %}
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Header</div>
<div class="panel-body">
{{ contact }}
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,13 @@
{% with "whoisdb:"|add:prefix|add:"-detail" as detailView %}
{% with "whoisdb:"|add:prefix|add:"-delete" as deleteView %}
{% with "whoisdb:"|add:prefix|add:"-edit" as editView %}
<tr>
<td><a href="{% url detailView obj.handle %}">{{ obj.handle }}</a></td>
<td>{{ objType }}</td>
<td>{{obj.name }}{{ obj.description }}</td>
<td>{% for contact in obj.admin_c.all %}<a href="{% url "whoisdb:contact-detail" contact.handle %}">{{ contact }}</a> {% endfor %}</td>
<td><a href="{% url editView obj.handle %}">Edit</a> <a href="{% url deleteView obj.handle %}">Delete</a></td>
</tr>
{% endwith %}
{% endwith %}
{% endwith %}

View File

@ -0,0 +1,15 @@
{% extends "base.html" %}
{% block content %}
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Header</div>
<div class="panel-body">
{{ mnt }}
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,21 @@
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Header</div>
<div class="panel-body">
<form method="post" action="#">
{% csrf_token %}
{{ form | crispy }}
<button type="submit" class="btn btn-primary">Create</button>
</form>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,21 @@
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Header</div>
<div class="panel-body">
<form method="post" action="#">
{% csrf_token %}
{{ form | crispy }}
<button type="submit" class="btn btn-primary">Create</button>
</form>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,32 @@
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<div class="row">
<div class="col-sm-12">
<div class="panel panel-{% if reasons %}danger{%else%}default{%endif%}">
<div class="panel-heading">Header</div>
<div class="panel-body">
{% if reasons %}
<p>
You cannot delete this object, as other objects in the database depend on it!
</p>
<p>
<ul>
{% for reason in reasons %}
<li>{{ reason }}</li>
{% endfor %}
</ul>
{% else %}
<form method="post" action="#">
{% csrf_token %}
<button type="submit" class="btn btn-primary">Create</button>
</form>
{% endif %}
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,21 @@
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Header</div>
<div class="panel-body">
<form method="post" action="#">
{% csrf_token %}
{{ form | crispy }}
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -10,13 +10,13 @@
<div class="panel-body">
{% if mnts %}
<ul>
<li><a href="">Create new Maintainer</a></li>
<li><a href="">Create new Role/Person</a></li>
<li><a href="{% url "whoisdb:mnt-create" %}">Create new Maintainer</a></li>
<li><a href="{% url "whoisdb:contact-create" %}">Create new Role/Person</a></li>
<li><a href="">Request resources</a></li>
{% if netblock %}
<li><a href="">Create Subnet</a></li>
{% if netblocks %}
<li><a href="{% url "whoisdb:inetnum-create" %}">Create Subnet</a></li>
{% endif %}
{% if asblock %}
{% if asblocks %}
<li><a href="">Create AS</a></li>
<li><a href="">Create ASblock</a></li>
{% endif %}
@ -28,6 +28,7 @@
<thead>
<tr>
<th>Handle</th>
<th>Type</th>
<th>Name?</th>
<th>Contact</th>
<th>Actions</th>
@ -35,12 +36,19 @@
</thead>
<tbody>
{% for mnt in mnts %}
<tr>
<td>{{ mnt.handle }}</td>
<td>{{ mnt.description }}</td>
<td>{% for contact in mnt.admin_c.all %}{{ contact }}{% endfor %}</td>
<td></td>
</tr>
{% include "whoisdb/handle_table_row.html" with obj=mnt objType="Maintainer" prefix="mnt" %}
{% endfor %}
{% for contact in contacts %}
{% include "whoisdb/handle_table_row.html" with obj=contact objType="Contact / Role" prefix="contact" %}
{% endfor %}
{% for asblock in asblocks %}
{% include "whoisdb/handle_table_row.html" with obj=asblock objType="AS Block" prefix="mnt" %}
{% endfor %}
{% for asnumber in asnumbers %}
{% include "whoisdb/handle_table_row.html" with obj=asnumber objType="AS Number" prefix="contact" %}
{% endfor %}
{% for netblock in netblocks %}
{% include "whoisdb/handle_table_row.html" with obj=netblock objType="IP Netblock" prefix="contact" %}
{% endfor %}
</tbody>
</table>

View File

@ -4,19 +4,71 @@ from django import forms
#from crispy_forms.layout import Submit, Layout
#from django.urls import reverse
from .models import Maintainer, Contact
from .models import Maintainer, Contact, InetNum
class WhoisObjectMixin(object):
def __init__(self, user, *args, **kwargs):
super(WhoisObjectMixin, self).__init__(*args, **kwargs)
self._user = user
instance = getattr(self, 'instance', None)
if instance and instance.pk:
self.fields['handle'].widget.attrs['readonly'] = True
def clean_handle(self):
instance = getattr(self, 'instance', None)
if instance and instance.pk:
return instance.handle
else:
return self.cleaned_data['handle']
def clean(self):
cleaned_data = super(WhoisObjectMixin, self).clean()
if cleaned_data.get("handle") == "AUTO":
cleaned_data['handle'] = self._meta.model.genGenericHandle(cleaned_data.get("name"))
class MntForm(forms.ModelForm):
class Meta:
model = Maintainer
fields = ['handle', 'description', 'admin_c']
def __init__(self, user, *args, **kwargs):
super(MntForm, self).__init__(*args, **kwargs)
self._user = user
if 'admin_c' in self.fields:
self.fields['admin_c'].queryset = Contact.objects.filter(mnt_by=user.maintainer_set.all())
class MntInitialForm(MntForm):
class Meta:
model = Maintainer
fields = ['handle', 'description']
class ContactForm(forms.ModelForm):
class ContactForm(WhoisObjectMixin, forms.ModelForm):
class Meta:
model = Contact
fields = ['type', 'handle', 'name', 'mnt_by']
def __init__(self, *args, **kwargs):
super(ContactForm, self).__init__(*args, **kwargs)
class ContactInitialForm(ContactForm):
class Meta:
model = Contact
fields = ['handle', 'name']
def __init__(self, person=True, *args, **kwargs):
super(ContactForm, self).__init__(*args, **kwargs)
# check if this is a person
self.person = person
class InetNumForm(WhoisObjectMixin, forms.ModelForm):
class Meta:
model = InetNum
fields = ['protocol', 'parent_range', 'address', 'description', 'mnt_lower']
def __init__(self, lower=False, *args, **kwargs):
super(MntForm, self).__init__(*args, **kwargs)
self._editLower = lower
if 'admin_c' in self.fields:
self.fields['admin_c'].queryset = Contact.objects.filter(mnt_by=self.user.maintainer_set.all())
if self._editLower:
def clean(self):
# FIXME: Reset certain field sto instance:
pass

26
whoisdb/generic.py Normal file
View File

@ -0,0 +1,26 @@
from django.views.generic import DeleteView
from django.http import HttpResponseRedirect
from django.contrib import messages
class DeleteCheckView(DeleteView):
""" Check if object actually can be deleted. Provide reasons to template
if not.
"""
def delete(self, request, *args, **kwargs):
self.object = self.get_object()
success_url = self.get_success_url()
reasons = self.object.getNoDeleteReasons()
if reasons:
# do not delete, do what get does...
return self.get(request, *args, **kwargs)
else:
self.object.delete()
messages.info(request, "Object %s has been deleted" % self.object.handle)
return HttpResponseRedirect(success_url)
def get_context_data(self, **kwargs):
if 'reasons' not in kwargs:
kwargs['reasons'] = self.object.getNoDeleteReasons()
return super(DeleteCheckView, self).get_context_data(**kwargs)

View File

@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-28 10:41
from __future__ import unicode_literals
from django.db import migrations, models
import whoisdb.validators
class Migration(migrations.Migration):
dependencies = [
('whoisdb', '0003_auto_20170222_1812'),
]
operations = [
migrations.AddField(
model_name='contact',
name='type',
field=models.CharField(choices=[('person', 'person'), ('role', 'role')], default='person', max_length=10),
preserve_default=False,
),
migrations.AlterField(
model_name='asblock',
name='handle',
field=models.SlugField(max_length=32, unique=True, validators=[whoisdb.validators.HandleValidator()], verbose_name='handle'),
),
migrations.AlterField(
model_name='asnumber',
name='handle',
field=models.SlugField(max_length=32, unique=True, validators=[whoisdb.validators.HandleValidator()], verbose_name='handle'),
),
migrations.AlterField(
model_name='contact',
name='handle',
field=models.SlugField(max_length=32, unique=True, validators=[whoisdb.validators.HandleValidator()], verbose_name='handle'),
),
migrations.AlterField(
model_name='inetnum',
name='handle',
field=models.SlugField(max_length=32, unique=True, validators=[whoisdb.validators.HandleValidator()], verbose_name='handle'),
),
migrations.AlterField(
model_name='maintainer',
name='description',
field=models.CharField(blank=True, help_text='Short description what this maintainer is for', max_length=64),
),
migrations.AlterField(
model_name='maintainer',
name='handle',
field=models.SlugField(help_text='Must end with -MNT, eg FOO3-MNT', max_length=32, unique=True, validators=[whoisdb.validators.HandleValidatorWithSuffix('MNT')], verbose_name='handle'),
),
]

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-28 14:35
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('whoisdb', '0004_auto_20170228_1041'),
]
operations = [
migrations.AddField(
model_name='inetnum',
name='address',
field=models.GenericIPAddressField(db_index=True, default='10.0.0.0'),
preserve_default=False,
),
migrations.AlterField(
model_name='contact',
name='type',
field=models.CharField(choices=[('person', 'PERSON')], max_length=10),
),
]

View File

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-28 14:40
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('whoisdb', '0005_auto_20170228_1435'),
]
operations = [
migrations.AddField(
model_name='inetnum',
name='mnt_by',
field=models.ManyToManyField(to='whoisdb.Maintainer'),
),
migrations.AlterField(
model_name='asnumber',
name='mnt_lower',
field=models.ManyToManyField(blank=True, related_name='lower_asnumber_set', to='whoisdb.Maintainer'),
),
migrations.AlterField(
model_name='inetnum',
name='mnt_lower',
field=models.ManyToManyField(blank=True, related_name='lower_inetnum_set', to='whoisdb.Maintainer'),
),
]

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-28 15:03
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('whoisdb', '0006_auto_20170228_1440'),
]
operations = [
migrations.AddField(
model_name='asblock',
name='mnt_lower',
field=models.ManyToManyField(blank=True, related_name='lower_asblock_set', to='whoisdb.Maintainer'),
),
]

View File

@ -1,4 +1,5 @@
from django.db import models
from django.urls import reverse
from dncore.models import User
from .validators import HandleValidator, HandleValidatorWithSuffix
@ -19,6 +20,10 @@ class WhoisObject(models.Model):
def genHandle(self, main=None):
if not main:
main = self.name
return self.genGenericHandle(main)
@classmethod
def genGenericHandle(clazz, main):
prefix = ""
if " " in main:
parts = main.split(" ")
@ -30,17 +35,23 @@ class WhoisObject(models.Model):
prefix = prefix.upper()
i = 1
handle = "%s%%d-%s" % (prefix, self.handleSuffix)
handle = "%s%%d-%s" % (prefix, clazz.handleSuffix)
while True:
try:
prefix
self.__class__.objects.get(handle=handle % i)
clazz.objects.get(handle=handle % i)
i += 1
except self.DoesNotExist:
except clazz.DoesNotExist:
break
return handle % i
def getNoDeleteReasons(self):
raise NotImplementedError()
def canBeDeleted(self):
return not bool(self.getNoDeleteReasons())
def handleAuto(self, name=None):
if self.handle == "AUTO":
self.handle = self.genHandle(name)
@ -50,13 +61,27 @@ class Maintainer(WhoisObject):
handleSuffix = "MNT"
auth = models.ManyToManyField(User)
handle = models.SlugField(max_length=32, unique=True, verbose_name='handle', validators=[HandleValidatorWithSuffix('MNT')])
description = models.CharField(max_length=64, blank=True)
handle = models.SlugField(max_length=32, unique=True, verbose_name='handle', validators=[HandleValidatorWithSuffix('MNT')], help_text="Must end with -MNT, eg FOO3-MNT")
description = models.CharField(max_length=64, blank=True, help_text="Short description what this maintainer is for")
admin_c = models.ManyToManyField("Contact")
# autoInclude = models.BooleanField(default=True)
def get_absolute_url(self):
return reverse("whoisdb:mnt-detail", kwargs={"handle": self.handle})
def getNoDeleteReasons(self):
reasons = []
mntables = [Contact, ASBlock, ASNumber, InetNum]
for mntable in mntables:
candidates = mntable.objects.filter(mnt_by=self).annotate(mntCount=models.Count('mnt_by')).filter(mntCount__lte=1)
for candidate in candidates:
reasons.append("Object %s would have no maintainers left." % candidate.handle)
return reasons
class MntdObject(WhoisObject):
@ -68,10 +93,27 @@ class MntdObject(WhoisObject):
class Contact(MntdObject):
handleSuffix = "DN"
TYPE = (('person', 'person'), ('role', 'role'))
TYPE_PERSON = 'PERSON'
TYPE_ROLE = 'ROLE'
TYPE = (('person', TYPE_PERSON), ('role', TYPE_ROLE))
TYPE = (('person', TYPE_PERSON),)
name = models.CharField(max_length=128)
type = models.CharField(max_length=10, choices=TYPE)
def get_absolute_url(self):
return reverse("whoisdb:contact-detail", kwargs={"handle": self.handle})
def getNoDeleteReasons(self):
reasons = []
contactables = [Maintainer]
for contactable in contactables:
candidates = contactable.objects.filter(admin_c=self).annotate(contactCount=models.Count('admin_c')).filter(contactCount__lte=1)
for candidate in candidates:
reasons.append("Object %s would have no contact left." % candidate.handle)
return reasons
class ASBlock(MntdObject):
handleSuffix = "ASB"
@ -79,6 +121,7 @@ class ASBlock(MntdObject):
parent_block = models.ForeignKey("ASBlock", models.CASCADE, null=True, blank=True, default=None)
description = models.CharField(max_length=64, blank=True)
mnt_lower = models.ManyToManyField(Maintainer, related_name='lower_asblock_set', blank=True)
class ASNumber(MntdObject):
handleSuffix = "AS"
@ -88,16 +131,20 @@ class ASNumber(MntdObject):
asblock = models.ForeignKey(ASBlock, models.CASCADE)
description = models.CharField(max_length=64, blank=True)
mnt_lower = models.ManyToManyField(Maintainer, related_name='lower_asnumber_set')
mnt_lower = models.ManyToManyField(Maintainer, related_name='lower_asnumber_set', blank=True)
class InetNum(WhoisObject):
class InetNum(MntdObject):
handleSuffix = "NET"
PROTO = (('ipv4', 'ipv4'), ('ipv6', 'ipv6'))
IPv4 = "ipv4"
IPv6 = "ipv6"
PROTO = ((IPv4, 'IPv4'), (IPv6, 'IPv6'))
protocol = models.CharField(max_length=4, choices=PROTO)
address = models.GenericIPAddressField(db_index=True)
netmask = models.PositiveIntegerField()
parent_range = models.ForeignKey("InetNum", models.CASCADE, null=True, blank=True, default=None)
description = models.CharField(max_length=64, blank=True)
mnt_lower = models.ManyToManyField(Maintainer)
mnt_lower = models.ManyToManyField(Maintainer, related_name='lower_inetnum_set', blank=True)

View File

@ -4,5 +4,20 @@ from . import views as whoisdb_views
urlpatterns = [
url(r'^$', whoisdb_views.dbDashboard, name='dashboard'),
url(r'^mnt/create/$', whoisdb_views.MaintainerCreate.as_view(), name='mnt-create'),
url(r'^mnt/show/(?P<handle>[A-Z0-9-]+)/$', whoisdb_views.MaintainerDetail.as_view(), name='mnt-detail'),
url(r'^mnt/edit/(?P<handle>[A-Z0-9-]+)/$', whoisdb_views.MaintainerEdit.as_view(), name='mnt-edit'),
url(r'^mnt/delete/(?P<handle>[A-Z0-9-]+)/$', whoisdb_views.MaintainerDelete.as_view(), name='mnt-delete'),
url(r'^contact/create/$', whoisdb_views.ContactCreate.as_view(), name='contact-create'),
url(r'^contact/show/(?P<handle>[A-Z0-9-]+)/$', whoisdb_views.ContactDetail.as_view(), name='contact-detail'),
url(r'^contact/edit/(?P<handle>[A-Z0-9-]+)/$', whoisdb_views.ContactEdit.as_view(), name='contact-edit'),
url(r'^contact/delete/(?P<handle>[A-Z0-9-]+)/$', whoisdb_views.ContactDelete.as_view(), name='contact-delete'),
url(r'^inetnum/create/$', whoisdb_views.InetNumCreate.as_view(), name='inetnum-create'),
url(r'^inetnum/show/(?P<handle>[A-Z0-9-]+)/$', whoisdb_views.ContactDetail.as_view(), name='inetnum-detail'),
url(r'^inetnum/edit/(?P<handle>[A-Z0-9-]+)/$', whoisdb_views.ContactEdit.as_view(), name='inetnum-edit'),
url(r'^inetnum/delete/(?P<handle>[A-Z0-9-]+)/$', whoisdb_views.ContactDelete.as_view(), name='inetnum-delete'),
]

View File

@ -1,21 +1,29 @@
from django.shortcuts import render
from django.db.models import Q
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.urls import reverse
from .forms import MntForm, ContactForm
from django.urls import reverse, reverse_lazy
from django.views.generic import DetailView, CreateView, UpdateView
from django.contrib.auth.mixins import LoginRequiredMixin
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))
mntForm = contactForm = None
if mnts.count() == 0:
mntForm = contactForm = None
if request.method == "POST":
mntForm = MntForm(data=request.POST, prefix="mnt")
contactForm = ContactForm(person=True, data=request.POST, prefix="contact")
mntForm = MntInitialForm(user=request.user, data=request.POST, prefix="mnt")
contactForm = ContactInitialForm(user=request.user, person=True, data=request.POST, prefix="contact")
if mntForm.is_valid() and contactForm.is_valid():
mnt = mntForm.save(commit=False)
mnt.handleAuto(request.user.username)
@ -23,6 +31,7 @@ def dbDashboard(request):
contact = contactForm.save(commit=False)
contact.handleAuto()
contact.type = Contact.TYPE_PERSON
contact.save()
contact.mnt_by.add(mnt.id)
contact.save()
@ -33,14 +42,123 @@ def dbDashboard(request):
return HttpResponseRedirect(reverse("whoisdb:dashboard"))
else:
mntForm = MntForm(prefix="mnt", initial={'handle': 'AUTO', 'description': 'Primary maintainer of %s' % request.user.username})
contactForm = ContactForm(person=True, initial={'handle': 'AUTO', 'name': request.user.username.capitalize()}, prefix='contact')
mntForm = MntInitialForm(user=request.user, prefix="mnt", initial={'handle': 'AUTO', 'description': 'Primary maintainer of %s' % request.user.username})
contactForm = ContactInitialForm(user=request.user, person=True, initial={'handle': 'AUTO', 'name': request.user.username.capitalize()}, prefix='contact')
return render(request, "whoisdb/overview.html", {"mnts": mnts, "mntForm": mntForm, "contactForm": contactForm})
print(asnumbers, asblocks, netblocks, mnts)
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
def get_form_kwargs(self, *args, **kwargs):
kwargs = super(MaintainerCreate, self).get_form_kwargs(*args, **kwargs)
kwargs["user"] = self.request.user
kwargs["initial"] = {
"handle": "AUTO",
}
return kwargs
def form_valid(self, form):
self.object = form.save(commit=False)
self.object.handleAuto(self.request.user.username)
self.object.save()
self.object.auth.add(self.request.user)
self.object.save()
return super(MaintainerCreate, self).form_valid(form)
class MaintainerEdit(LoginRequiredMixin, UpdateView):
template_name = "whoisdb/maintainer_edit.html"
model = Maintainer
form_class = MntForm
slug_field = "handle"
slug_url_kwarg = "handle"
def get_form_kwargs(self, *args, **kwargs):
kwargs = super(MaintainerEdit, self).get_form_kwargs(*args, **kwargs)
kwargs["user"] = self.request.user
return kwargs
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
slug_field = "handle"
slug_url_kwarg = "handle"
success_url = reverse_lazy("whoisdb:dashboard")
def get_queryset(self):
return self.model.objects.filter(auth=self.request.user)
class MaintainerDetail(LoginRequiredMixin, DetailView):
model = Maintainer
slug_field = "handle"
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
form_class = ContactForm
slug_field = "handle"
slug_url_kwarg = "handle"
def get_form_kwargs(self, *args, **kwargs):
kwargs = super(ContactEdit, self).get_form_kwargs(*args, **kwargs)
kwargs["user"] = self.request.user
return kwargs
def get_queryset(self):
# 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
def get_form_kwargs(self, *args, **kwargs):
kwargs = super(ContactCreate, self).get_form_kwargs(*args, **kwargs)
kwargs["user"] = self.request.user
kwargs["initial"] = {
"handle": "AUTO",
"type": Contact.TYPE_PERSON
}
return kwargs
class ContactDelete(LoginRequiredMixin, DeleteCheckView):
template_name = "whoisdb/obj_delete.html"
model = Contact
slug_field = "handle"
slug_url_kwarg = "handle"
success_url = reverse_lazy("whoisdb:dashboard")
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"
form_class = InetNumForm
def get_form_kwargs(self, *args, **kwargs):
kwargs = super(InetNumCreate, self).get_form_kwargs(*args, **kwargs)
kwargs["user"] = self.request.user
kwargs["initial"] = {
"handle": "AUTO",
"type": Contact.TYPE_PERSON
}
return kwargs
def manageMnt(request, mnt=None):
if mnt:
# object or 404
pass
return render(request, "whoisdb/overview.html", {})