Clean PEP8 violations

This commit is contained in:
Jan Dittberner 2015-11-22 14:03:47 +00:00
parent be0531ec30
commit b11055807f
20 changed files with 153 additions and 132 deletions

View file

@ -153,7 +153,8 @@ class DNSDomain(DomainBase):
type VARCHAR(6) NOT NULL, type VARCHAR(6) NOT NULL,
notified_serial INT DEFAULT NULL, notified_serial INT DEFAULT NULL,
account VARCHAR(40) DEFAULT NULL, account VARCHAR(40) DEFAULT NULL,
CONSTRAINT c_lowercase_name CHECK (((name)::TEXT = LOWER((name)::TEXT))) CONSTRAINT c_lowercase_name CHECK (
((name)::TEXT = LOWER((name)::TEXT)))
); );
CREATE UNIQUE INDEX name_index ON domains(name); CREATE UNIQUE INDEX name_index ON domains(name);
@ -162,8 +163,8 @@ class DNSDomain(DomainBase):
# name is represented by domain # name is represented by domain
master = models.CharField(max_length=128, blank=True, null=True) master = models.CharField(max_length=128, blank=True, null=True)
last_check = models.IntegerField(null=True) last_check = models.IntegerField(null=True)
domaintype = models.CharField(max_length=6, choices=DNS_DOMAIN_TYPES, domaintype = models.CharField(
db_column='type') max_length=6, choices=DNS_DOMAIN_TYPES, db_column='type')
notified_serial = models.IntegerField(null=True) notified_serial = models.IntegerField(null=True)
# account is represented by customer_id # account is represented by customer_id
# check constraint is added via RunSQL in migration # check constraint is added via RunSQL in migration
@ -200,20 +201,22 @@ class DNSRecord(models.Model):
CONSTRAINT domain_exists CONSTRAINT domain_exists
FOREIGN KEY(domain_id) REFERENCES domains(id) FOREIGN KEY(domain_id) REFERENCES domains(id)
ON DELETE CASCADE, ON DELETE CASCADE,
CONSTRAINT c_lowercase_name CHECK (((name)::TEXT = LOWER((name)::TEXT))) CONSTRAINT c_lowercase_name CHECK (
((name)::TEXT = LOWER((name)::TEXT)))
); );
CREATE INDEX rec_name_index ON records(name); CREATE INDEX rec_name_index ON records(name);
CREATE INDEX nametype_index ON records(name,type); CREATE INDEX nametype_index ON records(name,type);
CREATE INDEX domain_id ON records(domain_id); CREATE INDEX domain_id ON records(domain_id);
CREATE INDEX recordorder ON records (domain_id, ordername text_pattern_ops); CREATE INDEX recordorder ON records (
domain_id, ordername text_pattern_ops);
""" """
domain = models.ForeignKey('DNSDomain') domain = models.ForeignKey('DNSDomain')
name = models.CharField(max_length=255, blank=True, null=True, name = models.CharField(
db_index=True) max_length=255, blank=True, null=True, db_index=True)
recordtype = models.CharField(max_length=10, blank=True, null=True, recordtype = models.CharField(
db_column='type') max_length=10, blank=True, null=True, db_column='type')
content = models.CharField(max_length=65535, blank=True, null=True) content = models.CharField(max_length=65535, blank=True, null=True)
ttl = models.IntegerField(null=True) ttl = models.IntegerField(null=True)
prio = models.IntegerField(null=True) prio = models.IntegerField(null=True)
@ -291,7 +294,8 @@ class DNSComment(models.Model):
CONSTRAINT domain_exists CONSTRAINT domain_exists
FOREIGN KEY(domain_id) REFERENCES domains(id) FOREIGN KEY(domain_id) REFERENCES domains(id)
ON DELETE CASCADE, ON DELETE CASCADE,
CONSTRAINT c_lowercase_name CHECK (((name)::TEXT = LOWER((name)::TEXT))) CONSTRAINT c_lowercase_name CHECK (
((name)::TEXT = LOWER((name)::TEXT)))
); );
CREATE INDEX comments_domain_id_idx ON comments (domain_id); CREATE INDEX comments_domain_id_idx ON comments (domain_id);
@ -403,14 +407,16 @@ class DNSTSIGKey(models.Model):
name VARCHAR(255), name VARCHAR(255),
algorithm VARCHAR(50), algorithm VARCHAR(50),
secret VARCHAR(255), secret VARCHAR(255),
CONSTRAINT c_lowercase_name CHECK (((name)::TEXT = LOWER((name)::TEXT))) CONSTRAINT c_lowercase_name CHECK (
((name)::TEXT = LOWER((name)::TEXT)))
); );
CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm); CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm);
""" """
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
algorithm = models.CharField(max_length=50, choices=DNS_TSIG_KEY_ALGORITHMS) algorithm = models.CharField(
max_length=50, choices=DNS_TSIG_KEY_ALGORITHMS)
secret = models.CharField(max_length=255) secret = models.CharField(max_length=255)
# check constraint is added via RunSQL in migration # check constraint is added via RunSQL in migration

View file

@ -41,8 +41,8 @@ class CreateHostingDomainTest(TestCase):
return package return package
def test_get_anonymous(self): def test_get_anonymous(self):
response = self.client.get(reverse('create_hosting_domain', response = self.client.get(
kwargs={'package': 1})) reverse('create_hosting_domain', kwargs={'package': 1}))
self.assertEqual(response.status_code, 403) self.assertEqual(response.status_code, 403)
def test_get_regular_user(self): def test_get_regular_user(self):
@ -50,7 +50,8 @@ class CreateHostingDomainTest(TestCase):
TEST_USER, email=TEST_EMAIL, password=TEST_PASSWORD) TEST_USER, email=TEST_EMAIL, password=TEST_PASSWORD)
package = self._setup_hosting_package(customer) package = self._setup_hosting_package(customer)
self.client.login(username=TEST_USER, password=TEST_PASSWORD) self.client.login(username=TEST_USER, password=TEST_PASSWORD)
response = self.client.get(reverse('create_hosting_domain', response = self.client.get(
reverse('create_hosting_domain',
kwargs={'package': package.id})) kwargs={'package': package.id}))
self.assertEqual(response.status_code, 403) self.assertEqual(response.status_code, 403)
@ -60,7 +61,8 @@ class CreateHostingDomainTest(TestCase):
admin = User.objects.create_superuser( admin = User.objects.create_superuser(
TEST_USER, email=TEST_EMAIL, password=TEST_PASSWORD) TEST_USER, email=TEST_EMAIL, password=TEST_PASSWORD)
self.client.login(username=TEST_USER, password=TEST_PASSWORD) self.client.login(username=TEST_USER, password=TEST_PASSWORD)
response = self.client.get(reverse('create_hosting_domain', response = self.client.get(
reverse('create_hosting_domain',
kwargs={'package': package.id})) kwargs={'package': package.id}))
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
@ -70,7 +72,8 @@ class CreateHostingDomainTest(TestCase):
admin = User.objects.create_superuser( admin = User.objects.create_superuser(
TEST_USER, email=TEST_EMAIL, password=TEST_PASSWORD) TEST_USER, email=TEST_EMAIL, password=TEST_PASSWORD)
self.client.login(username=TEST_USER, password=TEST_PASSWORD) self.client.login(username=TEST_USER, password=TEST_PASSWORD)
response = self.client.get(reverse('create_hosting_domain', response = self.client.get(
reverse('create_hosting_domain',
kwargs={'package': package.id})) kwargs={'package': package.id}))
self.assertTemplateUsed(response, 'domains/hostingdomain_create.html') self.assertTemplateUsed(response, 'domains/hostingdomain_create.html')
@ -78,7 +81,8 @@ class CreateHostingDomainTest(TestCase):
admin = User.objects.create_superuser( admin = User.objects.create_superuser(
TEST_USER, email=TEST_EMAIL, password=TEST_PASSWORD) TEST_USER, email=TEST_EMAIL, password=TEST_PASSWORD)
self.client.login(username=TEST_USER, password=TEST_PASSWORD) self.client.login(username=TEST_USER, password=TEST_PASSWORD)
response = self.client.get(reverse('create_hosting_domain', response = self.client.get(
reverse('create_hosting_domain',
kwargs={'package': 1})) kwargs={'package': 1}))
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
@ -100,7 +104,8 @@ class CreateHostingDomainTest(TestCase):
admin = User.objects.create_superuser( admin = User.objects.create_superuser(
TEST_USER, email=TEST_EMAIL, password=TEST_PASSWORD) TEST_USER, email=TEST_EMAIL, password=TEST_PASSWORD)
self.client.login(username=TEST_USER, password=TEST_PASSWORD) self.client.login(username=TEST_USER, password=TEST_PASSWORD)
response = self.client.get(reverse('create_hosting_domain', response = self.client.get(
reverse('create_hosting_domain',
kwargs={'package': package.id})) kwargs={'package': package.id}))
self.assertIn('hostingpackage', response.context) self.assertIn('hostingpackage', response.context)
self.assertEqual(response.context['hostingpackage'], package) self.assertEqual(response.context['hostingpackage'], package)
@ -111,7 +116,8 @@ class CreateHostingDomainTest(TestCase):
admin = User.objects.create_superuser( admin = User.objects.create_superuser(
TEST_USER, email=TEST_EMAIL, password=TEST_PASSWORD) TEST_USER, email=TEST_EMAIL, password=TEST_PASSWORD)
self.client.login(username=TEST_USER, password=TEST_PASSWORD) self.client.login(username=TEST_USER, password=TEST_PASSWORD)
response = self.client.get(reverse('create_hosting_domain', response = self.client.get(
reverse('create_hosting_domain',
kwargs={'package': package.id})) kwargs={'package': package.id}))
self.assertIn('customer', response.context) self.assertIn('customer', response.context)
self.assertEqual(response.context['customer'], customer) self.assertEqual(response.context['customer'], customer)
@ -122,8 +128,10 @@ class CreateHostingDomainTest(TestCase):
admin = User.objects.create_superuser( admin = User.objects.create_superuser(
TEST_USER, email=TEST_EMAIL, password=TEST_PASSWORD) TEST_USER, email=TEST_EMAIL, password=TEST_PASSWORD)
self.client.login(username=TEST_USER, password=TEST_PASSWORD) self.client.login(username=TEST_USER, password=TEST_PASSWORD)
response = self.client.post(reverse('create_hosting_domain', response = self.client.post(
kwargs={'package': package.id}), data={'domain': 'example.org'}) reverse('create_hosting_domain',
kwargs={'package': package.id}),
data={'domain': 'example.org'})
self.assertRedirects(response, package.get_absolute_url()) self.assertRedirects(response, package.get_absolute_url())
def test_form_valid_message(self): def test_form_valid_message(self):
@ -132,7 +140,8 @@ class CreateHostingDomainTest(TestCase):
admin = User.objects.create_superuser( admin = User.objects.create_superuser(
TEST_USER, email=TEST_EMAIL, password=TEST_PASSWORD) TEST_USER, email=TEST_EMAIL, password=TEST_PASSWORD)
self.client.login(username=TEST_USER, password=TEST_PASSWORD) self.client.login(username=TEST_USER, password=TEST_PASSWORD)
response = self.client.post(reverse('create_hosting_domain', response = self.client.post(
reverse('create_hosting_domain',
kwargs={'package': package.id}), follow=True, kwargs={'package': package.id}), follow=True,
data={'domain': 'example.org'}) data={'domain': 'example.org'})
messages = list(response.context['messages']) messages = list(response.context['messages'])

View file

@ -12,6 +12,7 @@ os.environ.setdefault('DJANGO_SETTINGS_MODULE',
app = Celery('gnuviechadmin') app = Celery('gnuviechadmin')
def get_installed_apps(): def get_installed_apps():
return settings.INSTALLED_APPS return settings.INSTALLED_APPS

View file

@ -13,7 +13,6 @@ from gnuviechadmin import __version__ as gvaversion
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
def navigation(request): def navigation(request):
""" """
Add navigation items to the request context. Add navigation items to the request context.

View file

@ -122,12 +122,12 @@ STATIC_ROOT = normpath(join(SITE_ROOT, 'assets'))
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
STATIC_URL = '/static/' STATIC_URL = '/static/'
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS # noqa
STATICFILES_DIRS = ( STATICFILES_DIRS = (
normpath(join(SITE_ROOT, 'static')), normpath(join(SITE_ROOT, 'static')),
) )
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders # noqa
STATICFILES_FINDERS = ( STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
@ -150,7 +150,7 @@ ALLOWED_HOSTS = []
# ######### FIXTURE CONFIGURATION # ######### FIXTURE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS # noqa
FIXTURE_DIRS = ( FIXTURE_DIRS = (
normpath(join(SITE_ROOT, 'fixtures')), normpath(join(SITE_ROOT, 'fixtures')),
) )
@ -158,7 +158,7 @@ FIXTURE_DIRS = (
# ######### TEMPLATE CONFIGURATION # ######### TEMPLATE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors # noqa
TEMPLATE_CONTEXT_PROCESSORS = ( TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth', 'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug', 'django.core.context_processors.debug',

View file

@ -33,7 +33,7 @@ CACHES = {
# ######### TOOLBAR CONFIGURATION # ######### TOOLBAR CONFIGURATION
# See: http://django-debug-toolbar.readthedocs.org/en/latest/installation.html#explicit-setup # See: http://django-debug-toolbar.readthedocs.org/en/latest/installation.html#explicit-setup # noqa
INSTALLED_APPS += ( INSTALLED_APPS += (
'debug_toolbar', 'debug_toolbar',
) )

View file

@ -7,7 +7,7 @@ from __future__ import absolute_import
from .base import * from .base import *
# ######### HOST CONFIGURATION # ######### HOST CONFIGURATION
# See: https://docs.djangoproject.com/en/1.5/releases/1.5/#allowed-hosts-required-in-production # See: https://docs.djangoproject.com/en/1.5/releases/1.5/#allowed-hosts-required-in-production # noqa
ALLOWED_HOSTS = [SITES_DOMAIN_NAME] ALLOWED_HOSTS = [SITES_DOMAIN_NAME]
# ######### END HOST CONFIGURATION # ######### END HOST CONFIGURATION

View file

@ -8,4 +8,3 @@ class WSGITest(TestCase):
def test_wsgi_application(self): def test_wsgi_application(self):
from gnuviechadmin import wsgi from gnuviechadmin import wsgi
self.assertIsNotNone(wsgi.application) self.assertIsNotNone(wsgi.application)

View file

@ -24,12 +24,13 @@ path.append(SITE_ROOT)
# if running multiple sites in the same mod_wsgi process. To fix this, use # if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use # mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "jajaja.settings" # os.environ["DJANGO_SETTINGS_MODULE"] = "jajaja.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gnuviechadmin.settings.production") os.environ.setdefault(
"DJANGO_SETTINGS_MODULE", "gnuviechadmin.settings.production")
# This application object is used by any WSGI server configured to use this # This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION # file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here. # setting points here.
from django.core.wsgi import get_wsgi_application from django.core.wsgi import get_wsgi_application # noqa
application = get_wsgi_application() application = get_wsgi_application()
# Apply WSGI middleware here. # Apply WSGI middleware here.

View file

@ -362,8 +362,7 @@ class CustomerHostingPackage(HostingPackageBase):
def may_add_database(self): def may_add_database(self):
return ( return (
CustomerUserDatabaseOption.objects.filter( CustomerUserDatabaseOption.objects.filter(
hosting_package=self).count() hosting_package=self).count() >
>
UserDatabase.objects.filter( UserDatabase.objects.filter(
db_user__osuser=self.osuser).count() db_user__osuser=self.osuser).count()
) )

View file

@ -80,7 +80,8 @@ class CreateCustomerHostingPackage(CreateHostingPackage):
get_user_model(), username=self.kwargs['user']) get_user_model(), username=self.kwargs['user'])
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(CreateCustomerHostingPackage, self).get_context_data(**kwargs) context = super(
CreateCustomerHostingPackage, self).get_context_data(**kwargs)
context['customer'] = self.get_customer_object() context['customer'] = self.get_customer_object()
return context return context

View file

@ -7,6 +7,7 @@ from __future__ import absolute_import
from celery import shared_task from celery import shared_task
@shared_task @shared_task
def create_ldap_group(groupname, gid, descr): def create_ldap_group(groupname, gid, descr):
""" """

View file

@ -3,7 +3,8 @@ import os
import sys import sys
if __name__ == "__main__": if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gnuviechadmin.settings.local") os.environ.setdefault(
"DJANGO_SETTINGS_MODULE", "gnuviechadmin.settings.local")
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line

View file

@ -200,12 +200,12 @@ class MailAddress(ActivateAbleMixin, TimeStampedModel, models.Model):
forwards = MailAddressForward.objects.filter( forwards = MailAddressForward.objects.filter(
mailaddress=self).all() mailaddress=self).all()
for item in forwards: for item in forwards:
if not item.target in addresses: if item.target not in addresses:
item.delete() item.delete()
else: else:
retval.append(item) retval.append(item)
for target in addresses: for target in addresses:
if not target in [item.target for item in forwards]: if target not in [item.target for item in forwards]:
mafwd = MailAddressForward(mailaddress=self, target=target) mafwd = MailAddressForward(mailaddress=self, target=target)
if commit: if commit:
mafwd.save() mafwd.save()

View file

@ -349,10 +349,10 @@ class SshPublicKeyAdmin(admin.ModelAdmin):
for user in users: for user in users:
TaskResult.objects.create_task_result( TaskResult.objects.create_task_result(
set_file_ssh_authorized_keys.delay( set_file_ssh_authorized_keys.delay(
User.objects.get(uid=user).username, [ User.objects.get(uid=user).username,
str(key) for key in SshPublicKey.objects.filter( [str(key) for key in SshPublicKey.objects.filter(
user_id=user) user_id=user)]
]), ),
'set_file_ssh_authorized_keys' 'set_file_ssh_authorized_keys'
) )
perform_delete_selected.short_description = _( perform_delete_selected.short_description = _(

View file

@ -82,7 +82,8 @@ def handle_user_created(sender, instance, created, **kwargs):
chain = create_ldap_user.s( chain = create_ldap_user.s(
instance.username, instance.uid, instance.group.gid, instance.username, instance.uid, instance.group.gid,
instance.gecos, instance.homedir, instance.shell, None instance.gecos, instance.homedir, instance.shell, None
) | setup_file_sftp_userdir.s(instance.username ) | setup_file_sftp_userdir.s(
instance.username
) | setup_file_mail_userdir.s(instance.username) ) | setup_file_mail_userdir.s(instance.username)
taskresult = TaskResult.objects.create_task_result( taskresult = TaskResult.objects.create_task_result(
'handle_user_created', chain) 'handle_user_created', chain)
@ -138,8 +139,10 @@ def handle_group_deleted(sender, instance, **kwargs):
@receiver(post_delete, sender=User) @receiver(post_delete, sender=User)
def handle_user_deleted(sender, instance, **kwargs): def handle_user_deleted(sender, instance, **kwargs):
chain = delete_file_mail_userdir.s(instance.username chain = delete_file_mail_userdir.s(
) | delete_file_sftp_userdir.s(instance.username instance.username
) | delete_file_sftp_userdir.s(
instance.username
) | delete_ldap_user.s(instance.username) ) | delete_ldap_user.s(instance.username)
_LOGGER.debug('chain signature %s', chain) _LOGGER.debug('chain signature %s', chain)
taskresult = TaskResult.objects.create_task_result( taskresult = TaskResult.objects.create_task_result(

View file

@ -392,7 +392,8 @@ class UserTest(TestCaseWithCeleryTasks):
self.assertEqual(len(taskres), 5) self.assertEqual(len(taskres), 5)
creators = [t.creator for t in taskres] creators = [t.creator for t in taskres]
for tcount, tcreator in [ for tcount, tcreator in [
(2, 'handle_user_removed_from_group'), (2, 'handle_user_deleted'), (2, 'handle_user_removed_from_group'),
(2, 'handle_user_deleted'),
(1, 'handle_group_deleted')]: (1, 'handle_group_deleted')]:
self.assertEqual(creators.count(tcreator), tcount) self.assertEqual(creators.count(tcreator), tcount)
self.assertEqual(len(User.objects.all()), 0) self.assertEqual(len(User.objects.all()), 0)

View file

@ -98,7 +98,6 @@ class DatabaseUserManager(models.Manager):
return db_user return db_user
@python_2_unicode_compatible @python_2_unicode_compatible
class DatabaseUser(TimeStampedModel, models.Model): class DatabaseUser(TimeStampedModel, models.Model):
osuser = models.ForeignKey(OsUser) osuser = models.ForeignKey(OsUser)

View file

@ -47,6 +47,7 @@ def enable_web_vhost(sitename):
""" """
@shared_task @shared_task
def delete_web_vhost_config(sitename): def delete_web_vhost_config(sitename):
""" """
@ -70,6 +71,7 @@ def create_web_php_fpm_pool_config(username):
""" """
@shared_task @shared_task
def delete_web_php_fpm_pool_config(username): def delete_web_php_fpm_pool_config(username):
""" """