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 -*-
from django import forms
from django.contrib.auth.models import User
from main.models import *
from main.models import Host
class HostForm(forms.ModelForm):
class Meta:
model = Host
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>
<table class="table">
<tr><th>domain</th><th>last update</th><th>comment</th><th>action</th></tr>
{% for host in Hosts %}
{% for host in hosts %}
<tr>
<td><b>{{ host.fqdn }}</b></td>
<td>{{ host.last_update|date }}</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>
{% empty %}
<tr>No hosts yet.</tr>
@ -24,7 +24,7 @@
<div class="col-lg-4">
<form method="post" action="">
{% csrf_token %}
{{ HostForm|bootstrap }}
{{ form|bootstrap }}
<button type="submit" class="btn btn-primary">Create</button>
</form>
</div>

View File

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

View File

@ -1,11 +1,16 @@
# -*- 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.http import HttpResponse
from django.http import HttpResponse, HttpResponseRedirect
from django.conf import settings
from django.shortcuts import render, get_object_or_404
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):
context = {}
@ -24,23 +29,32 @@ class HomeView(TemplateView):
context['nav_home'] = True
return context
@login_required
def OverviewView(request):
context = create_context(request)
class OverviewView(CreateView):
model = Host
template_name = "main/overview.html"
form_class = HostForm
@method_decorator(login_required)
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['HostForm'] = HostForm(request.user)
context['Hosts'] = Host.objects.filter(created_by=request.user)
context['hosts'] = Host.objects.filter(created_by=self.request.user)
return context
if request.method == "POST":
print "POST"
form = HostForm(request.user,request.POST)
print form
if form.is_valid():
print "valid"
host.save()
context['HostForm'] = form
return render(request, "main/overview.html", context)
@login_required
def HostView(request,pk=None):
@ -56,3 +70,4 @@ def HostView(request,pk=None):
host = form.save(request.user)
context['HostForm'] = form
return render(request, "main/host.html", context)

View File

@ -50,8 +50,17 @@
</div>
</div>
</div>
<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 %}
<div class="row" style="background-color: #DDDDDD">
<div class="col-sm-4" style="text-align: center">