Merge pull request #191 from elnappo/master
add python 3 compatibility and some minor stuff
This commit is contained in:
commit
e51d453494
@ -9,8 +9,11 @@ from django.dispatch import receiver
|
||||
from django.contrib.auth.signals import user_logged_in
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import LANGUAGE_SESSION_KEY
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.six import text_type
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class UserProfile(models.Model):
|
||||
"""
|
||||
stuff we need additionally to what Django stores in User model
|
||||
@ -21,8 +24,8 @@ class UserProfile(models.Model):
|
||||
default='', blank=True, null=True,
|
||||
verbose_name=_('language'))
|
||||
|
||||
def __unicode__(self):
|
||||
return u"profile for %s" % self.user.__unicode__()
|
||||
def __str__(self):
|
||||
return u"profile for %s" % text_type(self.user)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('user profile')
|
||||
|
@ -17,6 +17,9 @@ from django.db.models.signals import pre_delete, post_save
|
||||
from django.contrib.auth.hashers import make_password
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.six import text_type
|
||||
|
||||
|
||||
from . import dnstools
|
||||
|
||||
@ -31,6 +34,7 @@ def result_fmt(msg):
|
||||
return msg[:RESULT_MSG_LEN]
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class BlacklistedHost(models.Model):
|
||||
name_re = models.CharField(
|
||||
_('name RegEx'),
|
||||
@ -45,8 +49,8 @@ class BlacklistedHost(models.Model):
|
||||
related_name='blacklisted_domains',
|
||||
verbose_name=_('created by'))
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s" % (self.name_re, )
|
||||
def __str__(self):
|
||||
return self.name_re
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('blacklisted host')
|
||||
@ -76,6 +80,7 @@ UPDATE_ALGORITHMS = {
|
||||
UPDATE_ALGORITHM_CHOICES = [(k, k) for k in UPDATE_ALGORITHMS]
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Domain(models.Model):
|
||||
name = models.CharField(
|
||||
_("name"),
|
||||
@ -124,8 +129,8 @@ class Domain(models.Model):
|
||||
created = models.DateTimeField(_("created at"), auto_now_add=True)
|
||||
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='domains', verbose_name=_("created by"))
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s" % (self.name, )
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def generate_ns_secret(self):
|
||||
algorithm = self.nameserver_update_algorithm
|
||||
@ -145,6 +150,7 @@ class Domain(models.Model):
|
||||
verbose_name_plural = _('domains')
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Host(models.Model):
|
||||
name = models.CharField(
|
||||
_("name"),
|
||||
@ -243,9 +249,8 @@ class Host(models.Model):
|
||||
created = models.DateTimeField(_("created at"), auto_now_add=True)
|
||||
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='hosts', verbose_name=_("created by"),)
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s.%s" % (
|
||||
self.name, self.domain.name)
|
||||
def __str__(self):
|
||||
return u"%s.%s" % (self.name, self.domain.name)
|
||||
|
||||
class Meta(object):
|
||||
unique_together = (('name', 'domain'), )
|
||||
@ -277,9 +282,9 @@ class Host(models.Model):
|
||||
try:
|
||||
return dnstools.query_ns(self.get_fqdn(), record)
|
||||
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
||||
return 'none'
|
||||
return None
|
||||
except (dns.resolver.NoNameservers, dns.resolver.Timeout, dnstools.NameServerNotAvailable):
|
||||
return 'error'
|
||||
return _('error')
|
||||
|
||||
def get_ipv4(self):
|
||||
return self.get_ip('ipv4')
|
||||
@ -359,6 +364,7 @@ def post_save_host(sender, **kwargs):
|
||||
post_save.connect(post_save_host, sender=Host)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class RelatedHost(models.Model):
|
||||
# host addr = network_of_main_host + interface_id
|
||||
name = models.CharField(
|
||||
@ -398,9 +404,8 @@ class RelatedHost(models.Model):
|
||||
related_name='relatedhosts',
|
||||
verbose_name=_("main host"))
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s.%s" % (
|
||||
self.name, self.main_host.__unicode__())
|
||||
def __str__(self):
|
||||
return u"%s.%s" % (self.name, text_type(self.main_host))
|
||||
|
||||
class Meta(object):
|
||||
unique_together = (('name', 'main_host'), )
|
||||
@ -432,6 +437,7 @@ class RelatedHost(models.Model):
|
||||
pre_delete.connect(pre_delete_host, sender=RelatedHost)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class ServiceUpdater(models.Model):
|
||||
name = models.CharField(
|
||||
_("name"),
|
||||
@ -467,14 +473,15 @@ class ServiceUpdater(models.Model):
|
||||
related_name='serviceupdater',
|
||||
verbose_name=_("created by"))
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s" % (self.name, )
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Meta(object):
|
||||
verbose_name = _('service updater')
|
||||
verbose_name_plural = _('service updaters')
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class ServiceUpdaterHostConfig(models.Model):
|
||||
service = models.ForeignKey(ServiceUpdater, on_delete=models.CASCADE, verbose_name=_("service"))
|
||||
|
||||
@ -516,7 +523,7 @@ class ServiceUpdaterHostConfig(models.Model):
|
||||
related_name='serviceupdaterhostconfigs',
|
||||
verbose_name=_("created by"))
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return u"%s (%s)" % (self.hostname, self.service.name, )
|
||||
|
||||
class Meta(object):
|
||||
|
@ -45,31 +45,31 @@
|
||||
<td>{{ host.available|yesno }}</td>
|
||||
<td>{{ host.client_faults }} / {{ host.server_faults }}
|
||||
{% if host.abuse_blocked %}
|
||||
<br><span class="label label-danger">Abuse-Blocked</span>
|
||||
<br><span class="label label-danger">{% trans "Abuse-Blocked" %}</span>
|
||||
{% elif host.abuse %}
|
||||
<br><span class="label label-warning">Abuse</span>
|
||||
<br><span class="label label-warning">{% trans "Abuse" %}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ host.get_ipv4 }}
|
||||
<td>{{ host.get_ipv4|default_if_none:_("none")}}
|
||||
<br>
|
||||
{% if host.last_update_ipv4 %}
|
||||
{% if host.last_update_ipv4 and host.get_ipv4 %}
|
||||
({{ host.last_update_ipv4|naturaltime }},
|
||||
{% if not host.tls_update_ipv4 %}
|
||||
<span class="label label-warning">no {% else %}
|
||||
<span class="label label-success">{% endif %}TLS</span>)
|
||||
{% else %}
|
||||
(unknown)
|
||||
<span class="label label-warning">{% trans "no" %} {% else %}
|
||||
<span class="label label-success">{% endif %}{% trans "TLS" %}</span>)
|
||||
{% elif host.get_ipv4 %}
|
||||
({% trans "unknown" %})
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ host.get_ipv6 }}
|
||||
<td>{{ host.get_ipv6|default_if_none:_("none") }}
|
||||
<br>
|
||||
{% if host.last_update_ipv6 %}
|
||||
{% if host.last_update_ipv6 and host.get_ipv6 %}
|
||||
({{ host.last_update_ipv6|naturaltime }},
|
||||
{% if not host.tls_update_ipv6 %}
|
||||
<span class="label label-warning">no {% else %}
|
||||
<span class="label label-success">{% endif %}TLS</span>)
|
||||
{% else %}
|
||||
(unknown)
|
||||
<span class="label label-warning">{% trans "no" %} {% else %}
|
||||
<span class="label label-success">{% endif %}{% trans "TLS" %}</span>)
|
||||
{% elif host.get_ipv6 %}
|
||||
({% trans "unknown" %})
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -15,7 +15,7 @@ from django.contrib.auth import get_user_model
|
||||
from django.contrib import messages
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.http import Http404
|
||||
from django.utils.timezone import now
|
||||
|
||||
from . import dnstools
|
||||
@ -37,7 +37,7 @@ class GenerateSecretView(UpdateView):
|
||||
def get_object(self, *args, **kwargs):
|
||||
obj = super(GenerateSecretView, self).get_object(*args, **kwargs)
|
||||
if obj.created_by != self.request.user:
|
||||
raise PermissionDenied() # or Http404
|
||||
raise Http404
|
||||
return obj
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
@ -60,7 +60,7 @@ class GenerateNSSecretView(UpdateView):
|
||||
def get_object(self, *args, **kwargs):
|
||||
obj = super(GenerateNSSecretView, self).get_object(*args, **kwargs)
|
||||
if obj.created_by != self.request.user:
|
||||
raise PermissionDenied() # or Http404
|
||||
raise Http404
|
||||
return obj
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
@ -260,7 +260,7 @@ class HostView(UpdateView):
|
||||
def get_object(self, *args, **kwargs):
|
||||
obj = super(HostView, self).get_object(*args, **kwargs)
|
||||
if obj.created_by != self.request.user:
|
||||
raise PermissionDenied() # or Http404
|
||||
raise Http404
|
||||
return obj
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
@ -283,7 +283,7 @@ class DeleteHostView(DeleteView):
|
||||
if obj.created_by != self.request.user or obj.abuse_blocked:
|
||||
# disallow deletion if abuse_blocked is set, otherwise the
|
||||
# abuser can just delete and recreate the host
|
||||
raise PermissionDenied() # or Http404
|
||||
raise Http404
|
||||
return obj
|
||||
|
||||
def get_success_url(self):
|
||||
@ -303,7 +303,7 @@ class RelatedHostOverviewView(TemplateView):
|
||||
try:
|
||||
self.__main_host = Host.objects.get(pk=kwargs.pop('mpk', None), created_by=self.request.user)
|
||||
except Host.DoesNotExist:
|
||||
raise PermissionDenied() # or Http404
|
||||
raise Http404
|
||||
return super(RelatedHostOverviewView, self).dispatch(*args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
@ -324,7 +324,7 @@ class AddRelatedHostView(CreateView):
|
||||
try:
|
||||
self.__main_host = Host.objects.get(pk=kwargs.pop('mpk', None), created_by=self.request.user)
|
||||
except Host.DoesNotExist:
|
||||
raise PermissionDenied() # or Http404
|
||||
raise Http404
|
||||
return super(AddRelatedHostView, self).dispatch(*args, **kwargs)
|
||||
|
||||
def get_success_url(self):
|
||||
@ -370,7 +370,7 @@ class RelatedHostView(UpdateView):
|
||||
def get_object(self, *args, **kwargs):
|
||||
obj = super(RelatedHostView, self).get_object(*args, **kwargs)
|
||||
if obj.main_host.created_by != self.request.user:
|
||||
raise PermissionDenied() # or Http404
|
||||
raise Http404
|
||||
return obj
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
@ -390,7 +390,7 @@ class DeleteRelatedHostView(DeleteView):
|
||||
def get_object(self, *args, **kwargs):
|
||||
obj = super(DeleteRelatedHostView, self).get_object(*args, **kwargs)
|
||||
if obj.main_host.created_by != self.request.user:
|
||||
raise PermissionDenied() # or Http404
|
||||
raise Http404
|
||||
return obj
|
||||
|
||||
def get_success_url(self):
|
||||
@ -448,7 +448,7 @@ class DomainView(UpdateView):
|
||||
def get_object(self, *args, **kwargs):
|
||||
obj = super(DomainView, self).get_object(*args, **kwargs)
|
||||
if obj.created_by != self.request.user:
|
||||
raise PermissionDenied() # or Http404
|
||||
raise Http404
|
||||
return obj
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
@ -468,7 +468,7 @@ class DeleteDomainView(DeleteView):
|
||||
def get_object(self, *args, **kwargs):
|
||||
obj = super(DeleteDomainView, self).get_object(*args, **kwargs)
|
||||
if obj.created_by != self.request.user:
|
||||
raise PermissionDenied() # or Http404
|
||||
raise Http404
|
||||
return obj
|
||||
|
||||
def get_success_url(self):
|
||||
@ -490,7 +490,7 @@ class UpdaterHostConfigOverviewView(CreateView):
|
||||
try:
|
||||
self.__host = Host.objects.get(pk=kwargs.pop('pk', None), created_by=self.request.user)
|
||||
except Host.DoesNotExist:
|
||||
raise PermissionDenied() # or Http404
|
||||
raise Http404
|
||||
return super(UpdaterHostConfigOverviewView, self).dispatch(*args, **kwargs)
|
||||
|
||||
def get_success_url(self):
|
||||
@ -533,7 +533,7 @@ class UpdaterHostConfigView(UpdateView):
|
||||
def get_object(self, *args, **kwargs):
|
||||
obj = super(UpdaterHostConfigView, self).get_object(*args, **kwargs)
|
||||
if obj.created_by != self.request.user:
|
||||
raise PermissionDenied() # or Http404
|
||||
raise Http404
|
||||
return obj
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
@ -552,7 +552,7 @@ class DeleteUpdaterHostConfigView(DeleteView):
|
||||
def get_object(self, *args, **kwargs):
|
||||
obj = super(DeleteUpdaterHostConfigView, self).get_object(*args, **kwargs)
|
||||
if obj.created_by != self.request.user:
|
||||
raise PermissionDenied() # or Http404
|
||||
raise Http404
|
||||
return obj
|
||||
|
||||
def get_success_url(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user