diff --git a/nsupdate/main/forms.py b/nsupdate/main/forms.py index 4d82611..9c6c0b3 100644 --- a/nsupdate/main/forms.py +++ b/nsupdate/main/forms.py @@ -9,10 +9,16 @@ class HostForm(forms.ModelForm): model = Host fields = ['fqdn', 'comment', ] - def create_host(self): + def __init__(self, user, *args, **kwargs): + super(HostForm, self).__init__(*args, **kwargs) + self.created_by = user + + def create_host(self, user): self.clean() host = Host(fqdn=self.cleaned_data['fqdn'], - comment=self.cleaned_data['comment']) + comment=self.cleaned_data['comment'], + created_by=user) host.save() + # TODO: Update NS with self.cleaned_data['ipv4addr'] return host diff --git a/nsupdate/main/templates/main/overview.html b/nsupdate/main/templates/main/overview.html index cc4351a..bb4c899 100644 --- a/nsupdate/main/templates/main/overview.html +++ b/nsupdate/main/templates/main/overview.html @@ -1,17 +1,37 @@ {% extends "base.html" %} +{% load bootstrap %} {% block content %} -

Overview

+
+
+

Host List

+ + + {% for host in Hosts %} + + {% empty %} + No hosts yet. + {% endfor %} +
domainlast updatecomment
{{ host.fqdn }}.nsupdate.info {{ host.last_update|date }} {{ host.comment }}
- IPv4:
- IPv6: - -
- - -
- - {{ HostForm }} +
+ + +
+
+

New host

+
+
+ {% csrf_token %} + {{ HostForm|bootstrap }} + +
+ +
+ +
+
+ {% endblock %} \ No newline at end of file diff --git a/nsupdate/main/urls.py b/nsupdate/main/urls.py index a56707f..5c116ac 100644 --- a/nsupdate/main/urls.py +++ b/nsupdate/main/urls.py @@ -1,6 +1,6 @@ from django.conf.urls import patterns, include, url from main.views import ( - HomeView, OverviewView + HomeView, OverviewView, ) from api.views import ( MyIpView, UpdateIpView @@ -8,7 +8,7 @@ from api.views import ( urlpatterns = patterns('', url(r'^$', HomeView.as_view(), name="home"), - url(r'^overview/', OverviewView.as_view(), name="overview"), + url(r'^overview/$', OverviewView, name='overview'), url(r'^myip$', MyIpView), url(r'^updateip$', UpdateIpView), ) diff --git a/nsupdate/main/views.py b/nsupdate/main/views.py index 20c53b7..729feb3 100644 --- a/nsupdate/main/views.py +++ b/nsupdate/main/views.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- from django.views.generic import TemplateView +from django.views.generic.list import ListView from django.http import HttpResponse from django.conf import settings +from django.shortcuts import render from main.forms import * class HomeView(TemplateView): @@ -12,20 +14,22 @@ class HomeView(TemplateView): context['nav_home'] = True return context +def OverviewView(request): + context = {} + context['nav_overview'] = True + context['WWW_IPV4_HOST'] = settings.WWW_IPV4_HOST + context['WWW_IPV6_HOST'] = settings.WWW_IPV6_HOST + context['session'] = request.session + context['HostForm'] = HostForm(request.user) + context['Hosts'] = Host.objects.filter(created_by=request.user) + if request.method == "POST": + print "POST" + form = HostForm(request.user,request.POST) + print form + if form.is_valid(): + print "valid" + host = form.create_host(request.user) + host.save() -class OverviewView(TemplateView): - template_name = "main/overview.html" - - def get_context_data(self, *args, **kwargs): - context = super(OverviewView, self).get_context_data(*args, **kwargs) - context['nav_overview'] = True - context['WWW_IPV4_HOST'] = settings.WWW_IPV4_HOST - context['WWW_IPV6_HOST'] = settings.WWW_IPV6_HOST - context['session'] = self.request.session - context['HostForm'] = HostForm(self.request.POST) - if self.request.method == "POST": - form = HostForm(self.request.POST) - if form.is_valid(): - host = form.create_host() - host.save() - return context + context['HostForm'] = form + return render(request, "main/overview.html", context) \ No newline at end of file