pep8 and so on

This commit is contained in:
Arne Schauf 2013-09-29 16:03:56 +02:00
parent ebcbc5ed4a
commit 34a8bbe6b8
3 changed files with 15 additions and 11 deletions

View File

@ -38,7 +38,6 @@ class Domain(models.Model):
class Host(models.Model):
"""TODO: hash update_secret on save (if not already hashed)"""
#fqdn = models.CharField(max_length=256, unique=True, verbose_name="Fully qualified domain name")
subdomain = models.CharField(max_length=256, validators=[
RegexValidator(
regex=r'^(([a-z0-9][a-z0-9\-]*[a-z0-9])|[a-z0-9])$',
@ -47,15 +46,18 @@ class Host(models.Model):
domain_blacklist_validator])
domain = models.ForeignKey(Domain)
update_secret = models.CharField(max_length=256)
comment = models.CharField(max_length=256, default='', blank=True, null=True)
comment = models.CharField(
max_length=256, default='', blank=True, null=True)
last_update = models.DateTimeField(auto_now=True)
created = models.DateTimeField(auto_now_add=True)
created_by = models.ForeignKey(User)
def __unicode__(self):
return u"%s.%s - %s" % (self.subdomain, self.domain.domain, self.comment)
return u"%s.%s - %s" % (
self.subdomain, self.domain.domain, self.comment)
class Meta:
unique_together = (('subdomain', 'domain'),)

View File

@ -2,7 +2,6 @@
{% load bootstrap %}
{% block content %}
<div class="row">
<div class="col-lg-8">
<h3>Host List</h3>
@ -39,5 +38,4 @@
<b>your IPv6:</b> <span class="ipv6adr">{{ request.session.ipv6 }}</span>
</div>
</div>
{% endblock %}

View File

@ -1,15 +1,13 @@
# -*- coding: utf-8 -*-
from django.views.generic import TemplateView, CreateView
from django.views.generic.list import ListView
from django.views.generic.edit import UpdateView, DeleteView
from django.http import HttpResponse, HttpResponseRedirect
from django.conf import settings
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.contrib.auth.hashers import make_password
from django.utils.decorators import method_decorator
from django.core.urlresolvers import reverse
from django.core.exceptions import PermissionDenied
import dns.inet
from main.forms import HostForm
@ -44,7 +42,10 @@ class OverviewView(CreateView):
def form_valid(self, form):
self.object = form.save(commit=False)
self.object.created_by = self.request.user
self.object.update_secret = make_password(self.object.update_secret, hasher='sha1')
self.object.update_secret = make_password(
self.object.update_secret,
hasher='sha1'
)
self.object.save()
messages.add_message(self.request, messages.SUCCESS, 'Host added.')
return HttpResponseRedirect(self.get_success_url())
@ -71,7 +72,10 @@ class HostView(UpdateView):
def form_valid(self, form):
self.object = form.save(commit=False)
self.object.created_by = self.request.user
self.object.update_secret = make_password(self.object.update_secret, hasher='sha1')
self.object.update_secret = make_password(
self.object.update_secret,
hasher='sha1'
)
self.object.save()
messages.add_message(self.request, messages.SUCCESS, 'Host updated.')
return HttpResponseRedirect(self.get_success_url())