Dashboards

This commit is contained in:
Sebastian Lohff 2017-03-15 03:07:43 +01:00
parent aa6313b464
commit a074cb85ca
4 changed files with 112 additions and 2 deletions

View File

@ -1,13 +1,27 @@
from django.shortcuts import render from django.shortcuts import render
from django.contrib.auth.decorators import login_required 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 @login_required
def profile(request): def profile(request):
return render(request, "profile/profile.html", {}) return render(request, "profile/profile.html", {})
@login_required @login_required
def dashboard(request): 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): def index(request):
return render(request, "index.html", {}) return render(request, "index.html", {})

View File

@ -53,6 +53,7 @@
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Whois DB <span class="caret"></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Whois DB <span class="caret"></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="{% url "whoisdb:dashboard" %}">Overview</a></li> <li><a href="{% url "whoisdb:dashboard" %}">Overview</a></li>
<li><a href="{% url "rrequests:dashboard" %}">Resource Requests</a></li>
<li><a href="{% url "domains:overview" %}">Domains</a></li> <li><a href="{% url "domains:overview" %}">Domains</a></li>
</ul> </ul>
</li> </li>

View File

@ -11,5 +11,94 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row">
<div class="col-sm-4">
<div class="panel panel-default">
<div class="panel-heading"><a href="{% url "whoisdb:dashboard" %}">Whois DB <small>(overview)</small></a></div>
<div class="panel-body">
{% if asns %}
<table class="table">
<tr>
<th>AS Name</th>
<th>Number</th>
</tr>
{% for asn in asns %}
<tr>
<td>{{ asn.handle }}</td>
<td>{{ asn.number }}</td>
</tr>
{% endfor %}
</table>
{% else %}
<p>You don't have any AS numbers</po>
{% endif %}
{% if inetnums %}
<table class="table">
<tr>
<th>Net Name</th>
<th>Prefix</th>
</tr>
{% for inetnum in inetnums %}
<tr>
<td>{{ inetnum.handle }}</td>
<td>{{ inetnum.prefix }}</td>
</tr>
{% endfor %}
</table>
{% else %}
<p>You don't have any AS numbers</p>
{% endif %}
</div>
</div>
</div>
<div class="col-sm-4">
<div class="panel panel-default">
<div class="panel-heading"><a href="{% url "domains:overview" %}">Domains <small>(overview)</small></a></div>
<div class="panel-body">
{% if domains %}
<table class="table">
<tr>
<th>Domain</th>
</tr>
{% for domain in domains %}
<tr>
<td>{{ domain.name }}</td>
</tr>
{% endfor %}
</table>
{% else %}
<p>You don't have any AS numbers</p>
{% endif %}
</div>
</div>
</div>
<div class="col-sm-4">
<div class="panel panel-default">
<div class="panel-heading"><a href="{% url "rrequests:dashboard" %}">Requests <small>(overview)</small></a></div>
<div class="panel-body">
{% if rrequests %}
<table class="table">
<tr>
<th>From</th>
<th>Subject</th>
</tr>
{% for rrequest in rrequests %}
<tr>
<td>{{ rrequest.applicant }} <span class="glyphicon glyphicon-arrow-right"></span> {{ rrequest.provider }}</td>
<td>{{ rrequest.subject }}</td>
</tr>
{% endfor %}
</table>
{% else %}
<p>No open requests</p>
{% endif %}
</div>
</div>
</div>
</div>
{% endblock %} {% endblock %}

View File

@ -146,6 +146,7 @@ class ASBlock(MntdObject):
return reasons return reasons
class ASNumber(MntdObject): class ASNumber(MntdObject):
handleSuffix = "AS" handleSuffix = "AS"
@ -166,6 +167,7 @@ class ASNumber(MntdObject):
return reasons return reasons
class InetNum(MntdObject): class InetNum(MntdObject):
handleSuffix = "NET" handleSuffix = "NET"
@ -183,8 +185,12 @@ class InetNum(MntdObject):
mnt_lower = models.ManyToManyField(Maintainer, related_name='lower_inetnum_set', blank=True) 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): def getNetwork(self):
return ipaddress.ip_network("%s/%s" % (self.address, self.netmask)) return ipaddress.ip_network(self.prefix())
def get_absolute_url(self): def get_absolute_url(self):
return reverse("whoisdb:inetnum-detail", kwargs={"handle": self.handle}) return reverse("whoisdb:inetnum-detail", kwargs={"handle": self.handle})