noot
This commit is contained in:
parent
4303a1d674
commit
e3311a6df7
|
@ -9,6 +9,41 @@
|
|||
<div class="panel-heading">Header</div>
|
||||
<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="">Request resources</a></li>
|
||||
{% if netblock %}
|
||||
<li><a href="">Create Subnet</a></li>
|
||||
{% endif %}
|
||||
{% if asblock %}
|
||||
<li><a href="">Create AS</a></li>
|
||||
<li><a href="">Create ASblock</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
You have the following Maintainers associated with you
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Handle</th>
|
||||
<th>Name?</th>
|
||||
<th>Contact</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</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>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% else %}
|
||||
You don't have a maintainer! Start by creating a Maintainer and a Person Object!
|
||||
|
|
|
@ -1,42 +1,88 @@
|
|||
from django.db import models
|
||||
|
||||
from dncore.models import User
|
||||
from .validators import HandleValidator
|
||||
from .validators import HandleValidator, HandleValidatorWithSuffix
|
||||
|
||||
|
||||
class WhoisObject(models.Model):
|
||||
handle_suffix = ""
|
||||
class Meta:
|
||||
abstract = True
|
||||
handleSuffix = ""
|
||||
|
||||
handle = models.SlugField(max_length=32, unique=True, verbose_name='handle', validators=[HandleValidator()])
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
last_modified = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
def __str__(self):
|
||||
return self.handle
|
||||
|
||||
def genHandle(self, main=None):
|
||||
if not main:
|
||||
main = self.name
|
||||
prefix = ""
|
||||
if " " in main:
|
||||
parts = main.split(" ")
|
||||
prefix = "".join(map(lambda _x: _x[0], parts))
|
||||
if len(prefix) < 3 and len(parts[-1]) > 1:
|
||||
prefix += parts[-1][1:4 - len(prefix)]
|
||||
else:
|
||||
prefix = main[0:3]
|
||||
prefix = prefix.upper()
|
||||
|
||||
i = 1
|
||||
handle = "%s%%d-%s" % (prefix, self.handleSuffix)
|
||||
while True:
|
||||
try:
|
||||
prefix
|
||||
self.__class__.objects.get(handle=handle % i)
|
||||
i += 1
|
||||
except self.DoesNotExist:
|
||||
break
|
||||
|
||||
return handle % i
|
||||
|
||||
def handleAuto(self, name=None):
|
||||
if self.handle == "AUTO":
|
||||
self.handle = self.genHandle(name)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
admin_c = models.ManyToManyField("Contact")
|
||||
|
||||
class MntdObject(WhoisObject):
|
||||
mnt_by = models.ManyToManyField(Maintainer)
|
||||
# autoInclude = models.BooleanField(default=True)
|
||||
|
||||
|
||||
|
||||
class MntdObject(WhoisObject):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
mnt_by = models.ManyToManyField(Maintainer)
|
||||
|
||||
|
||||
class Contact(MntdObject):
|
||||
handleSuffix = "DN"
|
||||
TYPE = (('person', 'person'), ('role', 'role'))
|
||||
|
||||
name = models.CharField(max_length=128)
|
||||
|
||||
|
||||
class ASBlock(MntdObject):
|
||||
handleSuffix = "ASB"
|
||||
|
||||
parent_block = models.ForeignKey("ASBlock", models.CASCADE, null=True, blank=True, default=None)
|
||||
description = models.CharField(max_length=64, blank=True)
|
||||
|
||||
|
||||
class ASNumber(MntdObject):
|
||||
handleSuffix = "AS"
|
||||
|
||||
number = models.PositiveIntegerField(unique=True, db_index=True)
|
||||
volatile = models.BooleanField(default=False)
|
||||
asblock = models.ForeignKey(ASBlock, models.CASCADE)
|
||||
|
@ -44,10 +90,10 @@ class ASNumber(MntdObject):
|
|||
|
||||
mnt_lower = models.ManyToManyField(Maintainer, related_name='lower_asnumber_set')
|
||||
|
||||
#class Route(MntObject):
|
||||
#
|
||||
|
||||
class InetNum(WhoisObject):
|
||||
handleSuffix = "NET"
|
||||
|
||||
PROTO = (('ipv4', 'ipv4'), ('ipv6', 'ipv6'))
|
||||
protocol = models.CharField(max_length=4, choices=PROTO)
|
||||
netmask = models.PositiveIntegerField()
|
||||
|
|
|
@ -5,11 +5,25 @@ from django.utils.translation import ugettext_lazy as _
|
|||
|
||||
import re
|
||||
|
||||
|
||||
@deconstructible
|
||||
class HandleValidator(validators.RegexValidator):
|
||||
regex = r'^[A-Z]+[0-9]+(-[A-Z]+)'
|
||||
regex = r'^(?:[A-Z]+[0-9]+(-[A-Z]+)|AUTO)'
|
||||
message = _(
|
||||
'Enter a valid handle (all uppercase)'
|
||||
)
|
||||
flags = re.ASCII if six.PY3 else 0
|
||||
|
||||
|
||||
@deconstructible
|
||||
class HandleValidatorWithSuffix(validators.RegexValidator):
|
||||
flags = re.ASCII if six.PY3 else 0
|
||||
|
||||
def __init__(self, suffix):
|
||||
self.regex = r'^(?:[A-Z]+[0-9]+-%s|AUTO)' % re.escape(suffix)
|
||||
print(self.regex)
|
||||
self.message = _(
|
||||
'Enter a valid handle with suffix %s (all uppercase)' % suffix
|
||||
)
|
||||
|
||||
super(HandleValidatorWithSuffix, self).__init__()
|
||||
|
|
|
@ -5,27 +5,42 @@ from django.urls import reverse
|
|||
|
||||
from .forms import MntForm, ContactForm
|
||||
|
||||
|
||||
@login_required
|
||||
def dbDashboard(request):
|
||||
mnts = request.user.maintainer_set.all()
|
||||
mntForm = contactForm = None
|
||||
|
||||
if mnts.count() == 0:
|
||||
mntForm = contactForm = None
|
||||
if request.method == "POST":
|
||||
mntForm = MntForm(data=request.POST, prefix="mnt_")
|
||||
mntForm = MntForm(data=request.POST, prefix="mnt")
|
||||
contactForm = ContactForm(person=True, data=request.POST, prefix="contact")
|
||||
if mntForm.is_valid() and contactForm.is_valid():
|
||||
print("NOOT")
|
||||
mnt = mntForm.save(commit=False)
|
||||
mnt.handleAuto(request.user.username)
|
||||
mnt.save()
|
||||
|
||||
#return HttpResponseRedirect(reverse("whoisdb:dashboard"))
|
||||
contact = contactForm.save(commit=False)
|
||||
contact.handleAuto()
|
||||
contact.save()
|
||||
contact.mnt_by.add(mnt.id)
|
||||
contact.save()
|
||||
|
||||
mnt.auth.add(request.user.id)
|
||||
mnt.admin_c.add(contact.id)
|
||||
mnt.save()
|
||||
|
||||
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 = MntForm(prefix="mnt", initial={'handle': 'AUTO', 'description': 'Main maintainer of %s' % request.user.username})
|
||||
contactForm = ContactForm(person=True, initial={'handle': 'AUTO'}, prefix='contact_')
|
||||
return render(request, "whoisdb/overview.html", {"mnts": mnts, "mntForm": mntForm, "contactForm": contactForm})
|
||||
|
||||
|
||||
def manageMnt(request, mnt=None):
|
||||
if mnt:
|
||||
# object or 404
|
||||
pass
|
||||
return render(request, "whoisdb/overview.html", {})
|
||||
|
||||
|
|
Loading…
Reference in New Issue