Merge branch 'master' of github.com:asmaps/nsupdate.info

Conflicts:
	nsupdate/nsupdate/templates/base.html
This commit is contained in:
Fabian Faessler 2013-09-28 23:14:47 +02:00
commit 155b1966d5
5 changed files with 51 additions and 50 deletions

View File

@ -1,32 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django import forms from django import forms
from django.contrib.auth.models import User from main.models import Host
from main.models import *
class HostForm(forms.ModelForm): class HostForm(forms.ModelForm):
class Meta: class Meta:
model = Host model = Host
fields = ['fqdn', 'comment', 'update_secret'] fields = ['fqdn', 'comment', 'update_secret']
def __init__(self, user, *args, **kwargs):
super(HostForm, self).__init__(*args, **kwargs)
self.created_by = user
def save(self, user, commit=True):
instance = super(HostForm, self).save(commit=False)
instance.created_by = user
if commit:
instance.save()
return instance
def create_host(self, user):
self.clean()
host = Host(fqdn=self.cleaned_data['fqdn'],
comment=self.cleaned_data['comment'],
update_secret=self.cleaned_data['update_secret'],
created_by=user)
host.save()
# TODO: Update NS with self.cleaned_data['ipv4addr']
return host

View File

@ -8,12 +8,12 @@
<h3>Host List</h3> <h3>Host List</h3>
<table class="table"> <table class="table">
<tr><th>domain</th><th>last update</th><th>comment</th><th>action</th></tr> <tr><th>domain</th><th>last update</th><th>comment</th><th>action</th></tr>
{% for host in Hosts %} {% for host in hosts %}
<tr> <tr>
<td><b>{{ host.fqdn }}</b></td> <td><b>{{ host.fqdn }}</b></td>
<td>{{ host.last_update|date }}</td> <td>{{ host.last_update|date }}</td>
<td>{{ host.comment }}</td> <td>{{ host.comment }}</td>
<td><a href="{% url 'host-view' host.pk %}"><span class="glyphicon glyphicon-edit"></span></a> <td><a href="{% url 'host_view' host.pk %}"><span class="glyphicon glyphicon-edit"></span></a>
</tr> </tr>
{% empty %} {% empty %}
<tr>No hosts yet.</tr> <tr>No hosts yet.</tr>
@ -24,7 +24,7 @@
<div class="col-lg-4"> <div class="col-lg-4">
<form method="post" action=""> <form method="post" action="">
{% csrf_token %} {% csrf_token %}
{{ HostForm|bootstrap }} {{ form|bootstrap }}
<button type="submit" class="btn btn-primary">Create</button> <button type="submit" class="btn btn-primary">Create</button>
</form> </form>
</div> </div>
@ -39,4 +39,4 @@
<img src="//{{ WWW_IPV6_HOST }}/updateip" /> <img src="//{{ WWW_IPV6_HOST }}/updateip" />
</div> </div>
{% endblock %} {% endblock %}

View File

@ -8,8 +8,8 @@ from api.views import (
urlpatterns = patterns('', urlpatterns = patterns('',
url(r'^$', HomeView.as_view(), name="home"), url(r'^$', HomeView.as_view(), name="home"),
url(r'^overview/$', OverviewView, name='overview'), url(r'^overview/$', OverviewView.as_view(), name='overview'),
url(r'^host/(?P<pk>\w+)$', HostView, name='host-view'), url(r'^host/(?P<pk>\d+)/$', HostView, name='host_view'),
url(r'^myip$', MyIpView), url(r'^myip$', MyIpView),
url(r'^updateip$', UpdateIpView), url(r'^updateip$', UpdateIpView),
url(r'^nic/update$', NicUpdateView), url(r'^nic/update$', NicUpdateView),

View File

@ -1,11 +1,16 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.views.generic import TemplateView from django.views.generic import TemplateView, CreateView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.http import HttpResponse from django.http import HttpResponse, HttpResponseRedirect
from django.conf import settings from django.conf import settings
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from main.forms import * from django.contrib import messages
from django.utils.decorators import method_decorator
from django.core.urlresolvers import reverse
from main.forms import HostForm
from main.models import Host
def create_context(request): def create_context(request):
context = {} context = {}
@ -24,23 +29,32 @@ class HomeView(TemplateView):
context['nav_home'] = True context['nav_home'] = True
return context return context
@login_required
def OverviewView(request):
context = create_context(request)
context['nav_overview'] = True
context['HostForm'] = HostForm(request.user)
context['Hosts'] = Host.objects.filter(created_by=request.user)
if request.method == "POST": class OverviewView(CreateView):
print "POST" model = Host
form = HostForm(request.user,request.POST) template_name = "main/overview.html"
print form form_class = HostForm
if form.is_valid():
print "valid" @method_decorator(login_required)
host.save() def dispatch(self, *args, **kwargs):
return super(OverviewView, self).dispatch(*args, **kwargs)
def get_success_url(self):
return reverse('overview')
def form_valid(self, form):
self.object = form.save(commit=False)
self.object.created_by = self.request.user
self.object.save()
messages.add_message(self.request, messages.SUCCESS, 'Host added.')
return HttpResponseRedirect(self.get_success_url())
def get_context_data(self, *args, **kwargs):
context = super(OverviewView, self).get_context_data(*args, **kwargs)
context['nav_overview'] = True
context['hosts'] = Host.objects.filter(created_by=self.request.user)
return context
context['HostForm'] = form
return render(request, "main/overview.html", context)
@login_required @login_required
def HostView(request,pk=None): def HostView(request,pk=None):
@ -55,4 +69,5 @@ def HostView(request,pk=None):
print "valid" print "valid"
host = form.save(request.user) host = form.save(request.user)
context['HostForm'] = form context['HostForm'] = form
return render(request, "main/host.html", context) return render(request, "main/host.html", context)

View File

@ -50,8 +50,17 @@
</div> </div>
</div> </div>
</div> </div>
<div class="container content wrap"> <div class="container content wrap">
<div id="message_box">
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{ message.tags }}">
<button type="button" class="close" data-dismiss="alert">&times;</button>
{{ message }}
</div>
{% endfor %}
{% endif %}
</div>
{% block content %} {% block content %}
<div class="row" style="background-color: #DDDDDD"> <div class="row" style="background-color: #DDDDDD">
<div class="col-sm-4" style="text-align: center"> <div class="col-sm-4" style="text-align: center">