From 7128db26406c2986e7776071b700ae87ede1e0b0 Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Mon, 5 Oct 2015 13:31:08 +0000 Subject: [PATCH] PEP8 compliance --- README.md | 4 +-- orchestra/admin/actions.py | 2 -- orchestra/admin/options.py | 2 +- orchestra/api/options.py | 2 +- orchestra/api/serializers.py | 26 ++----------------- .../project_template/project_name/urls.py | 1 - orchestra/contrib/accounts/actions.py | 11 +++----- orchestra/contrib/accounts/admin.py | 21 ++++++++------- orchestra/contrib/accounts/filters.py | 2 -- orchestra/contrib/bills/actions.py | 3 --- orchestra/contrib/bills/admin.py | 2 +- orchestra/contrib/bills/helpers.py | 1 - orchestra/contrib/contacts/api.py | 1 - orchestra/contrib/domains/admin.py | 1 - orchestra/contrib/history/apps.py | 1 - orchestra/contrib/issues/filters.py | 1 - orchestra/contrib/mailboxes/filters.py | 1 - orchestra/contrib/orchestration/backends.py | 3 ++- orchestra/contrib/orchestration/helpers.py | 3 +-- orchestra/contrib/orchestration/manager.py | 6 ++--- orchestra/contrib/orchestration/methods.py | 7 +++-- orchestra/contrib/payments/methods/options.py | 2 +- .../payments/methods/sepadirectdebit.py | 1 - orchestra/contrib/payments/settings.py | 2 +- orchestra/contrib/resources/actions.py | 2 -- orchestra/contrib/resources/admin.py | 2 +- orchestra/contrib/resources/aggregations.py | 2 -- orchestra/contrib/resources/models.py | 6 ++--- orchestra/contrib/resources/validators.py | 2 +- orchestra/contrib/saas/backends/moodle.py | 3 +-- orchestra/contrib/saas/backends/phplist.py | 3 ++- orchestra/contrib/saas/filters.py | 1 - orchestra/contrib/saas/services/bscw.py | 2 +- orchestra/contrib/saas/services/gitlab.py | 1 - orchestra/contrib/saas/services/helpers.py | 8 +++--- orchestra/contrib/services/handlers.py | 2 +- orchestra/contrib/settings/__init__.py | 4 +-- orchestra/contrib/systemusers/admin.py | 1 - orchestra/contrib/systemusers/forms.py | 2 +- orchestra/contrib/tasks/__init__.py | 2 -- orchestra/contrib/tasks/decorators.py | 7 ++--- orchestra/contrib/tasks/schedules.py | 1 - orchestra/contrib/vps/admin.py | 2 -- orchestra/contrib/webapps/apps.py | 2 +- orchestra/contrib/webapps/options.py | 2 +- orchestra/contrib/webapps/types/__init__.py | 1 - orchestra/core/context_processors.py | 1 - orchestra/forms/widgets.py | 2 +- .../management/commands/setuppostgres.py | 12 ++++----- orchestra/models/fields.py | 1 - orchestra/permissions/options.py | 1 - orchestra/plugins/admin.py | 2 +- orchestra/templatetags/markdown.py | 1 - orchestra/urls.py | 1 - orchestra/utils/apps.py | 1 - orchestra/utils/db.py | 2 +- orchestra/utils/mail.py | 1 - setup.py | 9 ++++--- 58 files changed, 71 insertions(+), 127 deletions(-) diff --git a/README.md b/README.md index b78869fc..50a60b96 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,8 @@ source env-django-orchestra/bin/activate pip3 install django-orchestra==dev \ --allow-external django-orchestra \ --allow-unverified django-orchestra -# The only non-pip required dependency for runing pip install is python3-dev -# sudo apt-get install python3.4-dev +# The only non-pip required dependency for runing pip3 install is python3-dev +sudo apt-get install python3-dev pip3 install -r http://git.io/orchestra-requirements.txt # Create a new Orchestra site diff --git a/orchestra/admin/actions.py b/orchestra/admin/actions.py index 0f47ab48..8b15ff3a 100644 --- a/orchestra/admin/actions.py +++ b/orchestra/admin/actions.py @@ -52,8 +52,6 @@ class SendEmail(object): } return self.confirm_email(request, **options) - opts = self.modeladmin.model._meta - app_label = opts.app_label self.context.update({ 'title': _("Send e-mail to %s") % self.opts.verbose_name_plural, 'content_title': "", diff --git a/orchestra/admin/options.py b/orchestra/admin/options.py index 1006b657..920db520 100644 --- a/orchestra/admin/options.py +++ b/orchestra/admin/options.py @@ -21,7 +21,7 @@ from ..utils.python import random_ascii, pairwise from .forms import AdminPasswordChangeForm #from django.contrib.auth.forms import AdminPasswordChangeForm -from .utils import set_url_query, action_to_view +from .utils import action_to_view sensitive_post_parameters_m = method_decorator(sensitive_post_parameters()) diff --git a/orchestra/api/options.py b/orchestra/api/options.py index 09150bd6..0620d9c7 100644 --- a/orchestra/api/options.py +++ b/orchestra/api/options.py @@ -34,7 +34,7 @@ class LogApiMixin(object): def partial_update(self, request, *args, **kwargs): from django.contrib.admin.models import CHANGE response = super(LogApiMixin, self).partial_update(request, *args, **kwargs) - message = _('Changed %s') % str(response.data) + message = _('Changed %s') % response.data self.log(request, message, CHANGE) return response diff --git a/orchestra/api/serializers.py b/orchestra/api/serializers.py index ef67b074..09aa329e 100644 --- a/orchestra/api/serializers.py +++ b/orchestra/api/serializers.py @@ -1,5 +1,6 @@ import copy +from django.core.exceptions import ValidationError from django.db import models from django.forms import widgets from django.utils.translation import ugettext_lazy as _ @@ -69,7 +70,7 @@ class RelatedHyperlinkedModelSerializer(HyperlinkedModelSerializer): 'url': "URL is required." }) account = self.get_account() - queryset = self.Meta.model.objects.filter(account=self.get_account()) + queryset = self.Meta.model.objects.filter(account=account) self.fields['url'].queryset = queryset obj = self.fields['url'].to_internal_value(url) return obj @@ -108,26 +109,3 @@ class SetPasswordHyperlinkedSerializer(HyperlinkedModelSerializer): instance.set_password(password) instance.save() return instance - - -#class MultiSelectField(serializers.ChoiceField): -# widget = widgets.CheckboxSelectMultiple -# -# def field_from_native(self, data, files, field_name, into): -# """ convert multiselect data into comma separated string """ -# if field_name in data: -# data = data.copy() -# try: -# # data is a querydict when using forms -# data[field_name] = ','.join(data.getlist(field_name)) -# except AttributeError: -# data[field_name] = ','.join(data[field_name]) -# return super(MultiSelectField, self).field_from_native(data, files, field_name, into) -# -# def valid_value(self, value): -# """ checks for each item if is a valid value """ -# for val in value.split(','): -# valid = super(MultiSelectField, self).valid_value(val) -# if not valid: -# return False -# return True diff --git a/orchestra/conf/project_template/project_name/urls.py b/orchestra/conf/project_template/project_name/urls.py index 3ffcec45..3ae27421 100644 --- a/orchestra/conf/project_template/project_name/urls.py +++ b/orchestra/conf/project_template/project_name/urls.py @@ -4,4 +4,3 @@ from django.conf.urls import include, url urlpatterns = [ url(r'', include('orchestra.urls')), ] - diff --git a/orchestra/contrib/accounts/actions.py b/orchestra/contrib/accounts/actions.py index 032af361..f5703ebd 100644 --- a/orchestra/contrib/accounts/actions.py +++ b/orchestra/contrib/accounts/actions.py @@ -1,6 +1,6 @@ from django.contrib import messages from django.contrib.admin import helpers -from django.contrib.admin.utils import NestedObjects, quote, model_ngettext +from django.contrib.admin.utils import NestedObjects, quote from django.contrib.auth import get_permission_codename from django.core.urlresolvers import reverse, NoReverseMatch from django.db import router @@ -77,7 +77,6 @@ def delete_related_services(modeladmin, request, queryset): related_services = [] to_delete = [] - user = request.user admin_site = modeladmin.admin_site def format(obj, account=False): @@ -87,16 +86,14 @@ def delete_related_services(modeladmin, request, queryset): if has_admin: try: - admin_url = reverse('admin:%s_%s_change' % (opts.app_label, opts.model_name), - None, (quote(obj._get_pk_val()),) + admin_url = reverse( + 'admin:%s_%s_change' % (opts.app_label, opts.model_name), + None, (quote(obj._get_pk_val()),) ) except NoReverseMatch: # Change url doesn't exist -- don't display link to edit return no_edit_link - p = '%s.%s' % (opts.app_label, get_permission_codename('delete', opts)) - if not user.has_perm(p): - perms_needed.add(opts.verbose_name) # Display a link to the admin page. context = (capfirst(opts.verbose_name), admin_url, obj) if account: diff --git a/orchestra/contrib/accounts/admin.py b/orchestra/contrib/accounts/admin.py index 05bfc961..d61b0c5d 100644 --- a/orchestra/contrib/accounts/admin.py +++ b/orchestra/contrib/accounts/admin.py @@ -91,8 +91,8 @@ class AccountAdmin(ChangePasswordAdminMixin, auth.UserAdmin, ExtendedModelAdmin) ) } context.update(extra_context or {}) - return super(AccountAdmin, self).change_view(request, object_id, - form_url=form_url, extra_context=context) + return super(AccountAdmin, self).change_view( + request, object_id, form_url, context) def get_fieldsets(self, request, obj=None): fieldsets = super(AccountAdmin, self).get_fieldsets(request, obj) @@ -233,11 +233,14 @@ class AccountAdminMixin(object): if self.account: # Hack widget render in order to append ?account=id to the add url old_render = formfield.widget.render + def render(*args, **kwargs): output = old_render(*args, **kwargs) output = output.replace('/add/"', '/add/?account=%s"' % self.account.pk) - output = re.sub(r'/add/\?([^".]*)"', r'/add/?\1&account=%s"' % self.account.pk, output) + with_qargs = r'/add/?\1&account=%s"' % self.account.pk + output = re.sub(r'/add/\?([^".]*)"', with_qargs, output) return mark_safe(output) + formfield.widget.render = render # Filter related object by account formfield.queryset = formfield.queryset.filter(account=self.account) @@ -282,8 +285,8 @@ class AccountAdminMixin(object): 'account_opts': Account._meta, } context.update(extra_context or {}) - return super(AccountAdminMixin, self).changeform_view(request, - object_id=object_id, form_url=form_url, extra_context=context) + return super(AccountAdminMixin, self).changeform_view( + request, object_id, form_url=form_url, extra_context=context) def changelist_view(self, request, extra_context=None): account_id = request.GET.get('account') @@ -318,7 +321,7 @@ class SelectAccountAdminMixin(AccountAdminMixin): account = self.account else: account = Account.objects.get(pk=request.GET['account']) - [ setattr(inline, 'account', account) for inline in inlines ] + [setattr(inline, 'account', account) for inline in inlines] return inlines def get_urls(self): @@ -333,7 +336,7 @@ class SelectAccountAdminMixin(AccountAdminMixin): wrap_admin_view(self, account_list), name='%s_%s_select_account' % info), ] - return select_urls + urls + return select_urls + urls def add_view(self, request, form_url='', extra_context=None): """ Redirects to select account view if required """ @@ -355,8 +358,8 @@ class SelectAccountAdminMixin(AccountAdminMixin): 'account_opts': Account._meta, } context.update(extra_context or {}) - return super(AccountAdminMixin, self).add_view(request, - form_url=form_url, extra_context=context) + return super(AccountAdminMixin, self).add_view( + request, form_url=form_url, extra_context=context) return HttpResponseRedirect('./select-account/?%s' % request.META['QUERY_STRING']) def save_model(self, request, obj, form, change): diff --git a/orchestra/contrib/accounts/filters.py b/orchestra/contrib/accounts/filters.py index 3db9857e..49caf1c5 100644 --- a/orchestra/contrib/accounts/filters.py +++ b/orchestra/contrib/accounts/filters.py @@ -37,5 +37,3 @@ class IsActiveListFilter(SimpleListFilter): elif self.value() == 'False': return queryset.filter(Q(is_active=False) | Q(account__is_active=False)) return queryset - - diff --git a/orchestra/contrib/bills/actions.py b/orchestra/contrib/bills/actions.py index e9721ef3..1d1be374 100644 --- a/orchestra/contrib/bills/actions.py +++ b/orchestra/contrib/bills/actions.py @@ -1,11 +1,9 @@ import io import zipfile from datetime import date -from decimal import Decimal from django.contrib import messages from django.contrib.admin import helpers -from django.core.exceptions import ValidationError from django.core.urlresolvers import reverse from django.db import transaction from django.http import HttpResponse @@ -17,7 +15,6 @@ from django.utils.translation import ungettext, ugettext_lazy as _ from orchestra.admin.forms import adminmodelformset_factory from orchestra.admin.decorators import action_with_confirmation from orchestra.admin.utils import get_object_from_url, change_url -from orchestra.utils.html import html_to_pdf from . import settings from .forms import SelectSourceForm diff --git a/orchestra/contrib/bills/admin.py b/orchestra/contrib/bills/admin.py index c71b2697..8b6ccfb9 100644 --- a/orchestra/contrib/bills/admin.py +++ b/orchestra/contrib/bills/admin.py @@ -52,7 +52,7 @@ class BillLineInline(admin.TabularInline): if sublines: content = '\n'.join(['%s: %s' % (sub.description, sub.total) for sub in sublines]) img = static('admin/img/icon_alert.gif') - return '%s ' % (content, str(total), img) + return '%s ' % (content, total, img) return total display_total.short_description = _("Total") display_total.allow_tags = True diff --git a/orchestra/contrib/bills/helpers.py b/orchestra/contrib/bills/helpers.py index 7c4d71e7..f503b3b7 100644 --- a/orchestra/contrib/bills/helpers.py +++ b/orchestra/contrib/bills/helpers.py @@ -25,4 +25,3 @@ def validate_contact(request, bill, error=True): send(request, mark_safe(message)) valid = False return valid - diff --git a/orchestra/contrib/contacts/api.py b/orchestra/contrib/contacts/api.py index 96cd6ce9..6a2c5ee9 100644 --- a/orchestra/contrib/contacts/api.py +++ b/orchestra/contrib/contacts/api.py @@ -13,4 +13,3 @@ class ContactViewSet(LogApiMixin, AccountApiMixin, viewsets.ModelViewSet): router.register(r'contacts', ContactViewSet) - diff --git a/orchestra/contrib/domains/admin.py b/orchestra/contrib/domains/admin.py index 8b7645bc..e2beb8bf 100644 --- a/orchestra/contrib/domains/admin.py +++ b/orchestra/contrib/domains/admin.py @@ -1,4 +1,3 @@ -from django import forms from django.contrib import admin from django.db.models.functions import Concat, Coalesce from django.utils.translation import ugettext_lazy as _ diff --git a/orchestra/contrib/history/apps.py b/orchestra/contrib/history/apps.py index 04d2233c..6ec322ef 100644 --- a/orchestra/contrib/history/apps.py +++ b/orchestra/contrib/history/apps.py @@ -1,4 +1,3 @@ -from django import db from django.apps import AppConfig from orchestra.core import administration diff --git a/orchestra/contrib/issues/filters.py b/orchestra/contrib/issues/filters.py index f8943645..c2e2e41d 100644 --- a/orchestra/contrib/issues/filters.py +++ b/orchestra/contrib/issues/filters.py @@ -54,4 +54,3 @@ class TicketStateListFilter(SimpleListFilter): choices = iter(super(TicketStateListFilter, self).choices(cl)) next(choices) return choices - diff --git a/orchestra/contrib/mailboxes/filters.py b/orchestra/contrib/mailboxes/filters.py index 9ea18f81..ff11d4b3 100644 --- a/orchestra/contrib/mailboxes/filters.py +++ b/orchestra/contrib/mailboxes/filters.py @@ -45,4 +45,3 @@ class HasAddressListFilter(HasMailboxListFilter): elif self.value() == 'False': return queryset.filter(addresses__isnull=True) return queryset - diff --git a/orchestra/contrib/orchestration/backends.py b/orchestra/contrib/orchestration/backends.py index aa498d70..f8f9651d 100644 --- a/orchestra/contrib/orchestration/backends.py +++ b/orchestra/contrib/orchestration/backends.py @@ -158,7 +158,8 @@ class ServiceBackend(plugins.Plugin, metaclass=ServiceMount): return list(scripts.items()) def get_banner(self): - time = timezone.now().strftime("%h %d, %Y %I:%M:%S %Z") + now = timezone.localtime(timezone.now()) + time = now.strftime("%h %d, %Y %I:%M:%S %Z") return "Generated by Orchestra at %s" % time def create_log(self, server, **kwargs): diff --git a/orchestra/contrib/orchestration/helpers.py b/orchestra/contrib/orchestration/helpers.py index 7c4ebf4d..601ea43f 100644 --- a/orchestra/contrib/orchestration/helpers.py +++ b/orchestra/contrib/orchestration/helpers.py @@ -43,7 +43,7 @@ def get_backends_help_text(backends): if isinstance(value, str): help_settings.append("%s = '%s'" % (name, value)) else: - help_settings.append("%s = %s" % (name, str(value))) + help_settings.append("%s = %s" % (name, value)) help_text += help_settings help_texts[backend.get_name()] = '
'.join(help_text) return help_texts @@ -154,4 +154,3 @@ def message_user(request, logs): else: msg = async_msg.format(url=url, async_url=async_url, async=async) messages.success(request, mark_safe(msg + '.')) - diff --git a/orchestra/contrib/orchestration/manager.py b/orchestra/contrib/orchestration/manager.py index 74e3358a..44f19ed3 100644 --- a/orchestra/contrib/orchestration/manager.py +++ b/orchestra/contrib/orchestration/manager.py @@ -32,7 +32,7 @@ def keep_log(execute, log, operations): log.state = log.EXCEPTION log.stderr = trace log.save() - subject = 'EXCEPTION executing backend(s) %s %s' % (str(args), str(kwargs)) + subject = 'EXCEPTION executing backend(s) %s %s' % (args, kwargs) logger.error(subject) logger.error(trace) mail_admins(subject, trace) @@ -40,7 +40,7 @@ def keep_log(execute, log, operations): finally: # Store and log the operation for operation in operations: - logger.info("Executed %s" % str(operation)) + logger.info("Executed %s" % operation) operation.store(log) if not log.is_success: send_report(execute, args, log) @@ -57,7 +57,7 @@ def generate(operations): serialize = False # Generate scripts per route+backend for operation in operations: - logger.debug("Queued %s" % str(operation)) + logger.debug("Queued %s" % operation) if operation.routes is None: operation.routes = router.objects.get_for_operation(operation, cache=cache) for route in operation.routes: diff --git a/orchestra/contrib/orchestration/methods.py b/orchestra/contrib/orchestration/methods.py index ba9dd456..a37a2d9a 100644 --- a/orchestra/contrib/orchestration/methods.py +++ b/orchestra/contrib/orchestration/methods.py @@ -107,14 +107,11 @@ def OpenSSH(backend, log, server, cmds, async=False): log.save(update_fields=('script', 'state', 'updated_at')) if not cmds: return - channel = None - ssh = None try: ssh = sshrun(server.get_address(), script, executable=backend.script_executable, persist=True, async=async, silent=True) logger.debug('%s running on %s' % (backend, server)) if async: - second = False for state in ssh: log.stdout += state.stdout.decode('utf8') log.stderr += state.stderr.decode('utf8') @@ -148,7 +145,7 @@ def SSH(*args, **kwargs): def Python(backend, log, server, cmds, async=False): script = '' for cmd in cmds: - script += '# %s\n' % (str(cmd.func.__name__) + str(cmd.args)) + script += '# %s %s\n' % (cmd.func.__name__, cmd.args) script += textwrap.dedent(''.join(inspect.getsourcelines(cmd.func)[0])) log.state = log.STARTED log.script = '\n'.join((log.script, script)) @@ -160,6 +157,8 @@ def Python(backend, log, server, cmds, async=False): result = cmd(server) for line in stdout: log.stdout += line + '\n' + if result: + log.stdout += '# Result: %s\n' % result if async: log.save(update_fields=('stdout', 'updated_at')) except: diff --git a/orchestra/contrib/payments/methods/options.py b/orchestra/contrib/payments/methods/options.py index ef2e927a..9a98d988 100644 --- a/orchestra/contrib/payments/methods/options.py +++ b/orchestra/contrib/payments/methods/options.py @@ -27,7 +27,7 @@ class PaymentMethod(plugins.Plugin): try: plugins.append(import_class(cls)) except ImportError as exc: - logger.error('Error loading %s: %s' % (cls, str(exc))) + logger.error('Error loading %s: %s' % (cls, exc)) return plugins def get_label(self): diff --git a/orchestra/contrib/payments/methods/sepadirectdebit.py b/orchestra/contrib/payments/methods/sepadirectdebit.py index cb26c8c0..49b5203c 100644 --- a/orchestra/contrib/payments/methods/sepadirectdebit.py +++ b/orchestra/contrib/payments/methods/sepadirectdebit.py @@ -298,4 +298,3 @@ class SEPADirectDebit(PaymentMethod): pretty_print=True, xml_declaration=True, encoding='UTF-8') - diff --git a/orchestra/contrib/payments/settings.py b/orchestra/contrib/payments/settings.py index 6356f9f5..4a37ed9d 100644 --- a/orchestra/contrib/payments/settings.py +++ b/orchestra/contrib/payments/settings.py @@ -1,4 +1,4 @@ -from django.utils.translation import ungettext, ugettext, ugettext_lazy as _ +from django.utils.translation import ugettext_lazy as _ from orchestra.contrib.settings import Setting diff --git a/orchestra/contrib/resources/actions.py b/orchestra/contrib/resources/actions.py index 4e1d3b71..a40e7aa1 100644 --- a/orchestra/contrib/resources/actions.py +++ b/orchestra/contrib/resources/actions.py @@ -1,5 +1,3 @@ -from collections import OrderedDict - from django.core.urlresolvers import reverse from django.shortcuts import redirect, render from django.utils.safestring import mark_safe diff --git a/orchestra/contrib/resources/admin.py b/orchestra/contrib/resources/admin.py index 99474792..ac2d84f1 100644 --- a/orchestra/contrib/resources/admin.py +++ b/orchestra/contrib/resources/admin.py @@ -13,7 +13,7 @@ from django.shortcuts import redirect from django.templatetags.static import static from django.utils.functional import cached_property from django.utils.safestring import mark_safe -from django.utils.translation import ungettext, ugettext, ugettext_lazy as _ +from django.utils.translation import ungettext, ugettext_lazy as _ from orchestra.admin import ExtendedModelAdmin from orchestra.admin.utils import insertattr, get_modeladmin, admin_link, admin_date diff --git a/orchestra/contrib/resources/aggregations.py b/orchestra/contrib/resources/aggregations.py index 1c48dfd2..6b2f6f39 100644 --- a/orchestra/contrib/resources/aggregations.py +++ b/orchestra/contrib/resources/aggregations.py @@ -1,9 +1,7 @@ -import copy import datetime import decimal import itertools -from dateutil.relativedelta import relativedelta from django.utils import timezone from django.utils.translation import ugettext_lazy as _ diff --git a/orchestra/contrib/resources/models.py b/orchestra/contrib/resources/models.py index e2c2e4fb..0ce5e1dc 100644 --- a/orchestra/contrib/resources/models.py +++ b/orchestra/contrib/resources/models.py @@ -80,7 +80,7 @@ class Resource(models.Model): ) def __str__(self): - return "{}-{}".format(str(self.content_type), self.name) + return "%s-%s" % (self.content_type, self.name) @cached_property def aggregation_class(self): @@ -122,7 +122,7 @@ class Resource(models.Model): def sync_periodic_task(self, delete=False): """ sync periodic task on save/delete resource operations """ - name = 'monitor.%s' % str(self) + name = 'monitor.%s' % self if delete or not self.crontab or not self.is_active: PeriodicTask.objects.filter(name=name).delete() elif self.pk: @@ -196,7 +196,7 @@ class ResourceData(models.Model): verbose_name_plural = _("resource data") def __str__(self): - return "%s: %s" % (str(self.resource), str(self.content_object)) + return "%s: %s" % (self.resource, self.content_object) @property def unit(self): diff --git a/orchestra/contrib/resources/validators.py b/orchestra/contrib/resources/validators.py index 2d0db904..606641cc 100644 --- a/orchestra/contrib/resources/validators.py +++ b/orchestra/contrib/resources/validators.py @@ -7,5 +7,5 @@ def validate_scale(value): int(eval(value)) except Exception as e: raise ValidationError( - _("'%s' is not a valid scale expression. (%s)") % (value, str(e)) + _("'%s' is not a valid scale expression. (%s)") % (value, e) ) diff --git a/orchestra/contrib/saas/backends/moodle.py b/orchestra/contrib/saas/backends/moodle.py index fa7dbe88..b4d28477 100644 --- a/orchestra/contrib/saas/backends/moodle.py +++ b/orchestra/contrib/saas/backends/moodle.py @@ -1,10 +1,9 @@ -import os import textwrap from urllib.parse import urlparse from django.utils.translation import ugettext_lazy as _ -from orchestra.contrib.orchestration import ServiceController, replace +from orchestra.contrib.orchestration import ServiceController from .. import settings diff --git a/orchestra/contrib/saas/backends/phplist.py b/orchestra/contrib/saas/backends/phplist.py index 8cf09582..3b73f6d7 100644 --- a/orchestra/contrib/saas/backends/phplist.py +++ b/orchestra/contrib/saas/backends/phplist.py @@ -58,7 +58,8 @@ class PhpListSaaSBackend(ServiceController): 'adminemail': saas.account.username, 'adminpassword': saas.password, } - response = requests.post(install_link, data=post, verify=settings.SAAS_PHPLIST_VERIFY_SSL) + response = requests.post( + install_link, data=post, verify=settings.SAAS_PHPLIST_VERIFY_SSL) sys.stdout.write(response.content.decode('utf8')+'\n') if response.status_code != 200: self.error("Bad status code %i." % response.status_code) diff --git a/orchestra/contrib/saas/filters.py b/orchestra/contrib/saas/filters.py index 0354a081..3bada2b3 100644 --- a/orchestra/contrib/saas/filters.py +++ b/orchestra/contrib/saas/filters.py @@ -18,4 +18,3 @@ class CustomURLListFilter(SimpleListFilter): elif self.value() == 'False': return queryset.filter(custom_url='') return queryset - diff --git a/orchestra/contrib/saas/services/bscw.py b/orchestra/contrib/saas/services/bscw.py index 06f1892f..6a45b759 100644 --- a/orchestra/contrib/saas/services/bscw.py +++ b/orchestra/contrib/saas/services/bscw.py @@ -8,7 +8,7 @@ from .options import SoftwareService class BSCWForm(SaaSPasswordForm): - email = forms.EmailField(label=_("Email"), widget=forms.TextInput(attrs={'size':'40'})) + email = forms.EmailField(label=_("Email"), widget=forms.TextInput(attrs={'size': '40'})) class BSCWDataSerializer(serializers.Serializer): diff --git a/orchestra/contrib/saas/services/gitlab.py b/orchestra/contrib/saas/services/gitlab.py index 7fc73770..082df590 100644 --- a/orchestra/contrib/saas/services/gitlab.py +++ b/orchestra/contrib/saas/services/gitlab.py @@ -33,4 +33,3 @@ class GitLabService(SoftwareService): change_readonly_fileds = ('email', 'user_id',) verbose_name = "GitLab" icon = 'orchestra/icons/apps/gitlab.png' - diff --git a/orchestra/contrib/saas/services/helpers.py b/orchestra/contrib/saas/services/helpers.py index 7bebd7c4..03ed1e20 100644 --- a/orchestra/contrib/saas/services/helpers.py +++ b/orchestra/contrib/saas/services/helpers.py @@ -5,7 +5,6 @@ from django.core.exceptions import ValidationError from django.utils.translation import ugettext_lazy as _ from orchestra.contrib.websites.models import Website, WebsiteDirective, Content -from orchestra.contrib.websites.utils import normurlpath from orchestra.contrib.websites.validators import validate_domain_protocol from orchestra.utils.python import AttrDict @@ -55,7 +54,7 @@ def clean_custom_url(saas): (url.netloc, account, domain.account), }) # Create new website for custom_url - website = Website(name=url.netloc , protocol=protocol, account=account) + website = Website(name=url.netloc, protocol=protocol, account=account) full_clean(website) try: validate_domain_protocol(website, domain, protocol) @@ -78,7 +77,8 @@ def clean_custom_url(saas): Content.objects.filter(website=website).values_list('path', flat=True) ) values = defaultdict(list) - for wdirective in WebsiteDirective.objects.filter(website=website).exclude(pk=directive.pk): + directives = WebsiteDirective.objects.filter(website=website) + for wdirective in directives.exclude(pk=directive.pk): fdirective = AttrDict({ 'name': wdirective.name, 'value': wdirective.value @@ -110,7 +110,7 @@ def create_or_update_directive(saas): Domain = Website.domains.field.rel.to domain = Domain.objects.get(name=url.netloc) # Create new website for custom_url - website = Website(name=url.netloc , protocol=protocol, account=account) + website = Website(name=url.netloc, protocol=protocol, account=account) website.save() website.domains.add(domain) # get or create directive diff --git a/orchestra/contrib/services/handlers.py b/orchestra/contrib/services/handlers.py index a5dba71c..b26129f1 100644 --- a/orchestra/contrib/services/handlers.py +++ b/orchestra/contrib/services/handlers.py @@ -261,7 +261,7 @@ class ServiceHandler(plugins.Plugin, metaclass=plugins.PluginMount): elif len(dates) == 1: ini, end = dates[0], dates[0] else: - raise AttributeError("WTF is '%s'?" % str(dates)) + raise AttributeError("WTF is '%s'?" % dates) discounts = discounts or () size = self.get_price_size(ini, end) diff --git a/orchestra/contrib/settings/__init__.py b/orchestra/contrib/settings/__init__.py index 0393f872..1dc831a5 100644 --- a/orchestra/contrib/settings/__init__.py +++ b/orchestra/contrib/settings/__init__.py @@ -45,10 +45,10 @@ class Setting(object): @classmethod def validate_choices(cls, value): if not isinstance(value, (list, tuple)): - raise ValidationError("%s is not a valid choices." % str(value)) + raise ValidationError("%s is not a valid choices." % value) for choice in value: if not isinstance(choice, (list, tuple)) or len(choice) != 2: - raise ValidationError("%s is not a valid choice." % str(choice)) + raise ValidationError("%s is not a valid choice." % choice) value, verbose = choice if not isinstance(verbose, (str, Promise)): raise ValidationError("%s is not a valid verbose name." % value) diff --git a/orchestra/contrib/systemusers/admin.py b/orchestra/contrib/systemusers/admin.py index 6acf85fc..db7c5ca7 100644 --- a/orchestra/contrib/systemusers/admin.py +++ b/orchestra/contrib/systemusers/admin.py @@ -2,7 +2,6 @@ from django.contrib import admin from django.utils.translation import ugettext_lazy as _ from orchestra.admin import ExtendedModelAdmin, ChangePasswordAdminMixin -from orchestra.admin.actions import disable from orchestra.contrib.accounts.actions import list_accounts from orchestra.contrib.accounts.admin import SelectAccountAdminMixin from orchestra.contrib.accounts.filters import IsActiveListFilter diff --git a/orchestra/contrib/systemusers/forms.py b/orchestra/contrib/systemusers/forms.py index dc30fbfd..b706159f 100644 --- a/orchestra/contrib/systemusers/forms.py +++ b/orchestra/contrib/systemusers/forms.py @@ -49,7 +49,7 @@ class SystemUserFormMixin(object): } else { field.removeClass("hidden"); input.removeAttr("type"); - };""" % str(list(settings.SYSTEMUSERS_DISABLED_SHELLS)) + };""" % list(settings.SYSTEMUSERS_DISABLED_SHELLS) ) self.fields['home'].widget.attrs['onChange'] = textwrap.dedent("""\ field = $(".field-box.field-directory"); diff --git a/orchestra/contrib/tasks/__init__.py b/orchestra/contrib/tasks/__init__.py index e380d425..61023b65 100644 --- a/orchestra/contrib/tasks/__init__.py +++ b/orchestra/contrib/tasks/__init__.py @@ -1,5 +1,3 @@ -import sys - from . import settings from .decorators import task, periodic_task, keep_state, apply_async diff --git a/orchestra/contrib/tasks/decorators.py b/orchestra/contrib/tasks/decorators.py index 343c80c0..72fd2af7 100644 --- a/orchestra/contrib/tasks/decorators.py +++ b/orchestra/contrib/tasks/decorators.py @@ -29,13 +29,14 @@ def keep_state(fn): _task_id = get_id() if _name is None: _name = get_name(fn) - state = TaskState.objects.create(state=states.STARTED, task_id=_task_id, name=_name, args=str(args), - kwargs=str(kwargs), tstamp=now) + state = TaskState.objects.create( + state=states.STARTED, task_id=_task_id, name=_name, + args=str(args), kwargs=str(kwargs), tstamp=now) try: result = fn(*args, **kwargs) except: trace = traceback.format_exc() - subject = 'EXCEPTION executing task %s(args=%s, kwargs=%s)' % (_name, str(args), str(kwargs)) + subject = 'EXCEPTION executing task %s(args=%s, kwargs=%s)' % (_name, args, kwargs) logger.error(subject) logger.error(trace) state.state = states.FAILURE diff --git a/orchestra/contrib/tasks/schedules.py b/orchestra/contrib/tasks/schedules.py index 18a5d82a..c5af3bff 100644 --- a/orchestra/contrib/tasks/schedules.py +++ b/orchestra/contrib/tasks/schedules.py @@ -116,4 +116,3 @@ # 'Invalid beginning range: {0} < {1}.'.format(i, self.min_)) # return i - diff --git a/orchestra/contrib/vps/admin.py b/orchestra/contrib/vps/admin.py index eca1ca35..14ef8787 100644 --- a/orchestra/contrib/vps/admin.py +++ b/orchestra/contrib/vps/admin.py @@ -1,6 +1,4 @@ -from django.conf.urls import url from django.contrib import admin -from django.contrib.auth.admin import UserAdmin from django.utils.translation import ugettext_lazy as _ from orchestra.admin import ExtendedModelAdmin, ChangePasswordAdminMixin diff --git a/orchestra/contrib/webapps/apps.py b/orchestra/contrib/webapps/apps.py index 7eb86eef..b183c2c8 100644 --- a/orchestra/contrib/webapps/apps.py +++ b/orchestra/contrib/webapps/apps.py @@ -8,6 +8,6 @@ class WebAppsConfig(AppConfig): verbose_name = 'Webapps' def ready(self): - from . import signals from .models import WebApp services.register(WebApp, icon='Applications-other.png') + from . import signals diff --git a/orchestra/contrib/webapps/options.py b/orchestra/contrib/webapps/options.py index 2fadd3dd..2b238937 100644 --- a/orchestra/contrib/webapps/options.py +++ b/orchestra/contrib/webapps/options.py @@ -59,7 +59,7 @@ class PHPAppOption(AppOption): php_version = self.instance.webapp.type_instance.get_php_version_number() if php_version and self.deprecated and float(php_version) > self.deprecated: raise ValidationError( - _("This option is deprecated since PHP version %s.") % str(self.deprecated) + _("This option is deprecated since PHP version %s.") % self.deprecated ) diff --git a/orchestra/contrib/webapps/types/__init__.py b/orchestra/contrib/webapps/types/__init__.py index de3df198..5abc8aec 100644 --- a/orchestra/contrib/webapps/types/__init__.py +++ b/orchestra/contrib/webapps/types/__init__.py @@ -80,4 +80,3 @@ class AppType(plugins.Plugin): 'user': self.instance.account.username, 'home': self.instance.account.main_systemuser.get_home(), } - diff --git a/orchestra/core/context_processors.py b/orchestra/core/context_processors.py index 13a415d8..52db2046 100644 --- a/orchestra/core/context_processors.py +++ b/orchestra/core/context_processors.py @@ -7,4 +7,3 @@ def site(request): 'ORCHESTRA_SITE_NAME': settings.ORCHESTRA_SITE_NAME, 'ORCHESTRA_SITE_VERBOSE_NAME': settings.ORCHESTRA_SITE_VERBOSE_NAME } - diff --git a/orchestra/forms/widgets.py b/orchestra/forms/widgets.py index 04467721..88ccdc93 100644 --- a/orchestra/forms/widgets.py +++ b/orchestra/forms/widgets.py @@ -25,7 +25,7 @@ class SpanWidget(forms.Widget): # Display icon if isinstance(original, bool): icon = static('admin/img/icon-%s.gif' % ('yes' if original else 'no',)) - return mark_safe('%s' % (icon, str(display))) + return mark_safe('%s' % (icon, display)) tag = self.tag[:-1] endtag = '/'.join((self.tag[0], self.tag[1:])) return mark_safe('%s%s >%s%s' % (tag, forms.utils.flatatt(final_attrs), display, endtag)) diff --git a/orchestra/management/commands/setuppostgres.py b/orchestra/management/commands/setuppostgres.py index df94895e..bcd14424 100644 --- a/orchestra/management/commands/setuppostgres.py +++ b/orchestra/management/commands/setuppostgres.py @@ -96,12 +96,12 @@ class Command(BaseCommand): if run("grep '^DATABASES\s*=\s*{' %(settings)s" % context, valid_codes=(0,1)).exit_code == 0: # Update existing settings_file run(textwrap.dedent("""sed -i \\ - -e "s/'ENGINE':[^#]*/'ENGINE': 'django.db.backends.postgresql_psycopg2', /" \\ - -e "s/'NAME':[^#]*/'NAME': '%(db_name)s', /" \\ - -e "s/'USER':[^#]*/'USER': '%(db_user)s', /" \\ - -e "s/'PASSWORD':[^#]*/'PASSWORD': '%(db_password)s', /" \\ - -e "s/'HOST':[^#]*/'HOST': '%(db_host)s', /" \\ - -e "s/'PORT':[^#]*/'PORT': '%(db_port)s', /" %(settings)s\ + -e "s/'ENGINE':[^#]*/'ENGINE': 'django.db.backends.postgresql_psycopg2', /" \\ + -e "s/'NAME':[^#]*/'NAME': '%(db_name)s', /" \\ + -e "s/'USER':[^#]*/'USER': '%(db_user)s', /" \\ + -e "s/'PASSWORD':[^#]*/'PASSWORD': '%(db_password)s', /" \\ + -e "s/'HOST':[^#]*/'HOST': '%(db_host)s', /" \\ + -e "s/'PORT':[^#]*/'PORT': '%(db_port)s', /" %(settings)s\ """) % context ) else: diff --git a/orchestra/models/fields.py b/orchestra/models/fields.py index c6f4e34a..7f857682 100644 --- a/orchestra/models/fields.py +++ b/orchestra/models/fields.py @@ -7,7 +7,6 @@ from django.db.models.fields.files import FileField, FieldFile from django.utils.text import capfirst from ..forms.fields import MultiSelectFormField -from ..utils.apps import isinstalled class MultiSelectField(models.CharField, metaclass=models.SubfieldBase): diff --git a/orchestra/permissions/options.py b/orchestra/permissions/options.py index 42523eee..74806885 100644 --- a/orchestra/permissions/options.py +++ b/orchestra/permissions/options.py @@ -104,4 +104,3 @@ class RelatedPermission(Permission): setattr(call, name, func) return call - diff --git a/orchestra/plugins/admin.py b/orchestra/plugins/admin.py index dac9d5b3..9f6422f6 100644 --- a/orchestra/plugins/admin.py +++ b/orchestra/plugins/admin.py @@ -115,7 +115,7 @@ class SelectPluginAdminMixin(object): def display_plugin_field(field_name): def inner(modeladmin, obj, field_name=field_name): try: - plugin_class = getattr(obj, '%s_class' % field_name) + getattr(obj, '%s_class' % field_name) except KeyError: value = getattr(obj, field_name) return "%s" % value diff --git a/orchestra/templatetags/markdown.py b/orchestra/templatetags/markdown.py index 2e5a9d99..9ec18900 100644 --- a/orchestra/templatetags/markdown.py +++ b/orchestra/templatetags/markdown.py @@ -8,4 +8,3 @@ register = template.Library() @register.filter(name='markdown') def do_markdown(text): return markdown(text) - diff --git a/orchestra/urls.py b/orchestra/urls.py index 769d77d3..72057de3 100644 --- a/orchestra/urls.py +++ b/orchestra/urls.py @@ -1,5 +1,4 @@ from django.contrib import admin -from django.conf import settings from django.conf.urls import include, url from . import api diff --git a/orchestra/utils/apps.py b/orchestra/utils/apps.py index c66189f6..d5fcc6c7 100644 --- a/orchestra/utils/apps.py +++ b/orchestra/utils/apps.py @@ -21,4 +21,3 @@ def remove_app(INSTALLED_APPS, app): apps.remove(app) return tuple(apps) return INSTALLED_APPS - diff --git a/orchestra/utils/db.py b/orchestra/utils/db.py index 254ea046..b17ae154 100644 --- a/orchestra/utils/db.py +++ b/orchestra/utils/db.py @@ -25,7 +25,7 @@ def close_connection(execute): def wrapper(*args, **kwargs): try: log = execute(*args, **kwargs) - except Exception as e: + except: raise else: wrapper.log = log diff --git a/orchestra/utils/mail.py b/orchestra/utils/mail.py index e4c925a4..c159ee03 100644 --- a/orchestra/utils/mail.py +++ b/orchestra/utils/mail.py @@ -38,4 +38,3 @@ def send_email_template(template, context, to, email_from=None, html=None, attac subject, html_message = render_email_template(html, context) msg.attach_alternative(html_message, "text/html") msg.send() - diff --git a/setup.py b/setup.py index 4b7c64d6..a32b7eed 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ -import os, sys +import os +import sys from distutils.sysconfig import get_python_lib from setuptools import setup, find_packages @@ -17,7 +18,7 @@ setup( version = version, author = "Marc Aymerich", author_email = "marcay@pangea.org", - url = "http://orchestra.pangea.org", + url = "https://github.com/glic3rinu/django-orchestra", license = "GPLv3", description = "A framework for building web hosting control panels", long_description = ( @@ -40,8 +41,8 @@ setup( 'License :: OSI Approved :: BSD License', 'Operating System :: POSIX :: Linux', 'Programming Language :: Python', - 'Programming Language :: Python :: 2.6', - 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', 'Topic :: Internet :: WWW/HTTP', 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', 'Topic :: Internet :: WWW/HTTP :: Site Management',