From cbab1a5d1799e1bbf3cb0993c652056658ec0af1 Mon Sep 17 00:00:00 2001 From: elnappo Date: Fri, 5 Dec 2014 19:38:26 +0100 Subject: [PATCH 1/8] only show "(unkown)" in overview when hosts has this record, add some trans tags --- nsupdate/main/models.py | 4 ++-- nsupdate/main/templates/main/overview.html | 28 +++++++++++----------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/nsupdate/main/models.py b/nsupdate/main/models.py index ab795c8..73c32f4 100644 --- a/nsupdate/main/models.py +++ b/nsupdate/main/models.py @@ -277,9 +277,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') diff --git a/nsupdate/main/templates/main/overview.html b/nsupdate/main/templates/main/overview.html index 1026c50..faa2ebd 100644 --- a/nsupdate/main/templates/main/overview.html +++ b/nsupdate/main/templates/main/overview.html @@ -45,31 +45,31 @@ {{ host.available|yesno }} {{ host.client_faults }} / {{ host.server_faults }} {% if host.abuse_blocked %} -
Abuse-Blocked +
{% trans "Abuse-Blocked" %} {% elif host.abuse %} -
Abuse +
{% trans "Abuse" %} {% endif %} - {{ host.get_ipv4 }} + {{ host.get_ipv4|default_if_none:_("none")}}
- {% 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 %} - no {% else %} - {% endif %}TLS) - {% else %} - (unknown) + {% trans "no" %} {% else %} + {% endif %}{% trans "TLS" %}) + {% elif host.get_ipv4 %} + ({% trans "unknown" %}) {% endif %} - {{ host.get_ipv6 }} + {{ host.get_ipv6|default_if_none:_("none") }}
- {% 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 %} - no {% else %} - {% endif %}TLS) - {% else %} - (unknown) + {% trans "no" %} {% else %} + {% endif %}{% trans "TLS" %}) + {% elif host.get_ipv6 %} + ({% trans "unknown" %}) {% endif %} From 75fc8627d7d632a6117b418a86d36987c12c9662 Mon Sep 17 00:00:00 2001 From: elnappo Date: Fri, 5 Dec 2014 20:33:15 +0100 Subject: [PATCH 2/8] add python_2_unicode_compatible in models.py #189 --- nsupdate/main/models.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/nsupdate/main/models.py b/nsupdate/main/models.py index 73c32f4..2519e0b 100644 --- a/nsupdate/main/models.py +++ b/nsupdate/main/models.py @@ -1,6 +1,7 @@ """ models for hosts, domains, service updaters, ... """ +from __future__ import unicode_literals import re import time @@ -17,6 +18,7 @@ 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 . import dnstools @@ -31,6 +33,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 +48,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') @@ -56,7 +59,7 @@ class BlacklistedHost(models.Model): def host_blacklist_validator(value): for bd in BlacklistedHost.objects.all(): if re.search(bd.name_re, value): - raise ValidationError(u'This name is blacklisted') + raise ValidationError('This name is blacklisted') from collections import namedtuple @@ -76,6 +79,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 +128,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 +149,7 @@ class Domain(models.Model): verbose_name_plural = _('domains') +@python_2_unicode_compatible class Host(models.Model): name = models.CharField( _("name"), @@ -243,9 +248,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 "%s.%s" % (self.name, self.domain.name) class Meta(object): unique_together = (('name', 'domain'), ) @@ -359,6 +363,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 +403,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 "%s.%s" % (self.name, self.main_host.__unicode__()) class Meta(object): unique_together = (('name', 'main_host'), ) @@ -432,6 +436,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"), @@ -468,13 +473,14 @@ class ServiceUpdater(models.Model): verbose_name=_("created by")) def __unicode__(self): - return u"%s" % (self.name, ) + 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,8 +522,8 @@ class ServiceUpdaterHostConfig(models.Model): related_name='serviceupdaterhostconfigs', verbose_name=_("created by")) - def __unicode__(self): - return u"%s (%s)" % (self.hostname, self.service.name, ) + def __str__(self): + return "%s (%s)" % (self.hostname, self.service.name, ) class Meta(object): verbose_name = _('service updater host config') From ca34ca3e0d97e2dca0125ac2d9e4cacfbc71d537 Mon Sep 17 00:00:00 2001 From: elnappo Date: Sat, 6 Dec 2014 12:35:20 +0100 Subject: [PATCH 3/8] remove all __unicode__() for python3 compatibility --- nsupdate/main/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nsupdate/main/models.py b/nsupdate/main/models.py index 2519e0b..f350489 100644 --- a/nsupdate/main/models.py +++ b/nsupdate/main/models.py @@ -404,7 +404,7 @@ class RelatedHost(models.Model): verbose_name=_("main host")) def __str__(self): - return "%s.%s" % (self.name, self.main_host.__unicode__()) + return "%s.%s" % (self.name, self.main_host) class Meta(object): unique_together = (('name', 'main_host'), ) @@ -472,7 +472,7 @@ class ServiceUpdater(models.Model): related_name='serviceupdater', verbose_name=_("created by")) - def __unicode__(self): + def __str__(self): return self.name class Meta(object): From cbc181024f878aedc1fe9ad60d458ef2ea972504 Mon Sep 17 00:00:00 2001 From: elnappo Date: Sat, 6 Dec 2014 12:43:35 +0100 Subject: [PATCH 4/8] python3 compatibility for account models --- nsupdate/accounts/models.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nsupdate/accounts/models.py b/nsupdate/accounts/models.py index 08b3b58..820ea8c 100644 --- a/nsupdate/accounts/models.py +++ b/nsupdate/accounts/models.py @@ -1,6 +1,7 @@ """ models for account-related stuff """ +from __future__ import unicode_literals from django.db import models from django.conf import settings @@ -9,8 +10,10 @@ 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 +@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 "profile for %s" % self.user class Meta: verbose_name = _('user profile') From 1897c9a913ecb638867a44c8982e8c0403c6ae16 Mon Sep 17 00:00:00 2001 From: elnappo Date: Sun, 28 Dec 2014 14:07:06 +0100 Subject: [PATCH 5/8] replace PermissionDenied with Http404 --- nsupdate/main/views.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/nsupdate/main/views.py b/nsupdate/main/views.py index 0ad51f5..275523b 100644 --- a/nsupdate/main/views.py +++ b/nsupdate/main/views.py @@ -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): From 37bb496e3ba29d4cf12ccb6aed6ce679d5f3f1a2 Mon Sep 17 00:00:00 2001 From: elnappo Date: Sun, 28 Dec 2014 14:19:24 +0100 Subject: [PATCH 6/8] dont use unicode_literals --- nsupdate/main/models.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/nsupdate/main/models.py b/nsupdate/main/models.py index f350489..9fbe5d6 100644 --- a/nsupdate/main/models.py +++ b/nsupdate/main/models.py @@ -1,8 +1,6 @@ """ models for hosts, domains, service updaters, ... """ -from __future__ import unicode_literals - import re import time import base64 @@ -59,7 +57,7 @@ class BlacklistedHost(models.Model): def host_blacklist_validator(value): for bd in BlacklistedHost.objects.all(): if re.search(bd.name_re, value): - raise ValidationError('This name is blacklisted') + raise ValidationError(u'This name is blacklisted') from collections import namedtuple @@ -249,7 +247,7 @@ class Host(models.Model): created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='hosts', verbose_name=_("created by"),) def __str__(self): - return "%s.%s" % (self.name, self.domain.name) + return u"%s.%s" % (self.name, self.domain.name) class Meta(object): unique_together = (('name', 'domain'), ) @@ -404,7 +402,7 @@ class RelatedHost(models.Model): verbose_name=_("main host")) def __str__(self): - return "%s.%s" % (self.name, self.main_host) + return u"%s.%s" % (self.name, self.main_host.__unicode__()) class Meta(object): unique_together = (('name', 'main_host'), ) @@ -523,7 +521,7 @@ class ServiceUpdaterHostConfig(models.Model): verbose_name=_("created by")) def __str__(self): - return "%s (%s)" % (self.hostname, self.service.name, ) + return u"%s (%s)" % (self.hostname, self.service.name, ) class Meta(object): verbose_name = _('service updater host config') From bc8041fd2608f6e2feb03cacfc155efc5c88bdc8 Mon Sep 17 00:00:00 2001 From: elnappo Date: Sun, 28 Dec 2014 14:24:05 +0100 Subject: [PATCH 7/8] remove unicode_literals from account models --- nsupdate/accounts/models.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nsupdate/accounts/models.py b/nsupdate/accounts/models.py index 820ea8c..8ddb6b4 100644 --- a/nsupdate/accounts/models.py +++ b/nsupdate/accounts/models.py @@ -1,7 +1,6 @@ """ models for account-related stuff """ -from __future__ import unicode_literals from django.db import models from django.conf import settings @@ -25,7 +24,7 @@ class UserProfile(models.Model): verbose_name=_('language')) def __str__(self): - return "profile for %s" % self.user + return u"profile for %s" % self.user.__unicode__() class Meta: verbose_name = _('user profile') From 419704618d5debbd4c29500d8bb016d40b2be366 Mon Sep 17 00:00:00 2001 From: elnappo Date: Sun, 28 Dec 2014 14:52:17 +0100 Subject: [PATCH 8/8] replace __unicode__() with text_type for python3 --- nsupdate/accounts/models.py | 3 ++- nsupdate/main/models.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/nsupdate/accounts/models.py b/nsupdate/accounts/models.py index 8ddb6b4..8da8e06 100644 --- a/nsupdate/accounts/models.py +++ b/nsupdate/accounts/models.py @@ -10,6 +10,7 @@ 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 @@ -24,7 +25,7 @@ class UserProfile(models.Model): verbose_name=_('language')) def __str__(self): - return u"profile for %s" % self.user.__unicode__() + return u"profile for %s" % text_type(self.user) class Meta: verbose_name = _('user profile') diff --git a/nsupdate/main/models.py b/nsupdate/main/models.py index 9fbe5d6..6afe1ed 100644 --- a/nsupdate/main/models.py +++ b/nsupdate/main/models.py @@ -1,6 +1,7 @@ """ models for hosts, domains, service updaters, ... """ + import re import time import base64 @@ -17,6 +18,8 @@ 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 @@ -402,7 +405,7 @@ class RelatedHost(models.Model): verbose_name=_("main host")) def __str__(self): - return u"%s.%s" % (self.name, self.main_host.__unicode__()) + return u"%s.%s" % (self.name, text_type(self.main_host)) class Meta(object): unique_together = (('name', 'main_host'), )