dnmgmt/dncore/views.py

46 lines
1.4 KiB
Python

from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.db.models import Q
from django.views.generic import CreateView
from django.urls import reverse_lazy
from django.contrib import messages
from whoisdb.models import ASNumber, InetNum
from domains.models import Domain
from rrequests.models import Request
from .forms import CustomUserCreationForm
@login_required
def profile(request):
return render(request, "profile/profile.html", {})
@login_required
def dashboard(request):
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", {})
class RegisterUser(CreateView):
template_name = "dncore/registration.html"
form_class = CustomUserCreationForm
success_url = reverse_lazy("user:login")
def form_valid(self, form):
ret = super(RegisterUser, self).form_valid(form)
messages.success(self.request, "You successfully registered as user %s and can now log in!" % form.instance.username)
return ret