From a074cb85ca8085701b73c00f333b7504b670056e Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Wed, 15 Mar 2017 03:07:43 +0100 Subject: [PATCH] Dashboards --- dncore/views.py | 16 +++++- templates/base.html | 1 + templates/dncore/dashboard.html | 89 +++++++++++++++++++++++++++++++++ whoisdb/models.py | 8 ++- 4 files changed, 112 insertions(+), 2 deletions(-) diff --git a/dncore/views.py b/dncore/views.py index 5053ab1..3d11c7d 100644 --- a/dncore/views.py +++ b/dncore/views.py @@ -1,13 +1,27 @@ from django.shortcuts import render from django.contrib.auth.decorators import login_required +from django.db.models import Q + +from whoisdb.models import ASNumber, InetNum +from domains.models import Domain +from rrequests.models import Request + @login_required def profile(request): return render(request, "profile/profile.html", {}) + @login_required def dashboard(request): - return render(request, "dncore/dashboard.html", {}) + mnts = request.user.maintainer_set.all() + asns = ASNumber.objects.filter(Q(mnt_by__in=mnts) | Q(mnt_lower__in=mnts)) + inetnums = InetNum.objects.filter(Q(mnt_by__in=mnts) | Q(mnt_lower__in=mnts)) + domains = Domain.objects.filter(mnt_by__in=mnts) + rrequests = Request.objects.filter((Q(provider__in=mnts) | Q(applicant__in=mnts)) & Q(status=Request.STATE_OPEN)) + + return render(request, "dncore/dashboard.html", {"asns": asns, "inetnums": inetnums, "domains": domains, 'rrequests': rrequests}) + def index(request): return render(request, "index.html", {}) diff --git a/templates/base.html b/templates/base.html index 86353dd..fc2f371 100644 --- a/templates/base.html +++ b/templates/base.html @@ -53,6 +53,7 @@ diff --git a/templates/dncore/dashboard.html b/templates/dncore/dashboard.html index 24acbdd..e4c0dae 100644 --- a/templates/dncore/dashboard.html +++ b/templates/dncore/dashboard.html @@ -11,5 +11,94 @@ + +
+
+
+ +
+ {% if asns %} + + + + + + {% for asn in asns %} + + + + + {% endfor %} +
AS NameNumber
{{ asn.handle }}{{ asn.number }}
+ {% else %} +

You don't have any AS numbers + {% endif %} + + {% if inetnums %} + + + + + + {% for inetnum in inetnums %} + + + + + {% endfor %} +
Net NamePrefix
{{ inetnum.handle }}{{ inetnum.prefix }}
+ {% else %} +

You don't have any AS numbers

+ {% endif %} + + +
+
+
+
+
+ +
+ {% if domains %} + + + + + {% for domain in domains %} + + + + {% endfor %} +
Domain
{{ domain.name }}
+ {% else %} +

You don't have any AS numbers

+ {% endif %} +
+
+
+
+
+ +
+ {% if rrequests %} + + + + + + {% for rrequest in rrequests %} + + + + + {% endfor %} +
FromSubject
{{ rrequest.applicant }} {{ rrequest.provider }}{{ rrequest.subject }}
+ {% else %} +

No open requests

+ {% endif %} +
+
+
+
{% endblock %} diff --git a/whoisdb/models.py b/whoisdb/models.py index d213d83..358e1ff 100644 --- a/whoisdb/models.py +++ b/whoisdb/models.py @@ -146,6 +146,7 @@ class ASBlock(MntdObject): return reasons + class ASNumber(MntdObject): handleSuffix = "AS" @@ -166,6 +167,7 @@ class ASNumber(MntdObject): return reasons + class InetNum(MntdObject): handleSuffix = "NET" @@ -183,8 +185,12 @@ class InetNum(MntdObject): mnt_lower = models.ManyToManyField(Maintainer, related_name='lower_inetnum_set', blank=True) + def prefix(self): + """ Helper function, mainly used in templates """ + return "%s/%s" % (self.address, self.netmask) + def getNetwork(self): - return ipaddress.ip_network("%s/%s" % (self.address, self.netmask)) + return ipaddress.ip_network(self.prefix()) def get_absolute_url(self): return reverse("whoisdb:inetnum-detail", kwargs={"handle": self.handle})