62 lines
1.9 KiB
Python
Raw Normal View History

2013-09-28 12:06:26 +02:00
# -*- coding: utf-8 -*-
from django.views.generic import TemplateView
2013-09-28 21:32:29 +02:00
from django.views.generic.list import ListView
from django.http import HttpResponse
from django.conf import settings
from django.shortcuts import render, get_object_or_404
from django.contrib.auth.decorators import login_required
2013-09-28 22:20:19 +02:00
from main.forms import HostForm
from main.models import Host
2013-09-28 12:06:26 +02:00
def create_context(request):
context = {}
context['WWW_IPV4_HOST'] = settings.WWW_IPV4_HOST
context['WWW_IPV6_HOST'] = settings.WWW_IPV6_HOST
context['session'] = request.session
return context
2013-09-28 12:06:26 +02:00
class HomeView(TemplateView):
template_name = "base.html"
def get_context_data(self, *args, **kwargs):
context = super(HomeView, self).get_context_data(*args, **kwargs)
context['nav_home'] = True
return context
@login_required
2013-09-28 21:32:29 +02:00
def OverviewView(request):
context = create_context(request)
2013-09-28 21:32:29 +02:00
context['nav_overview'] = True
context['HostForm'] = HostForm(request.user)
context['Hosts'] = Host.objects.filter(created_by=request.user)
2013-09-28 21:32:29 +02:00
if request.method == "POST":
print "POST"
form = HostForm(request.user,request.POST)
print form
if form.is_valid():
print "valid"
host.save()
2013-09-28 16:46:33 +02:00
2013-09-28 21:32:29 +02:00
context['HostForm'] = form
2013-09-28 22:20:19 +02:00
return render(request, "main/overview.html", context)
<<<<<<< HEAD
=======
@login_required
def HostView(request,pk=None):
context = create_context(request)
context['nav_overview'] = True
context['HostForm'] = HostForm(request.user,instance=get_object_or_404(Host, pk=pk, 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.save(request.user)
context['HostForm'] = form
return render(request, "main/host.html", context)
>>>>>>> 3b2fa9008fe6aa3d20e7b3ae9504fadedb4165c4