From f38eaa6ac8e0f78fad0f168ff09b17be9c98a2df Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Fri, 22 May 2015 13:15:06 +0000 Subject: [PATCH] Random fixes --- TODO.md | 3 +++ orchestra/admin/options.py | 19 +++++++++++++++++-- orchestra/contrib/issues/admin.py | 4 ++-- orchestra/contrib/mailboxes/backends.py | 15 ++++++++++----- orchestra/contrib/orchestration/backends.py | 4 ++-- orchestra/contrib/services/helpers.py | 5 ++--- .../templates/admin/settings/change_form.html | 2 +- orchestra/contrib/webapps/backends/php.py | 6 +++--- .../contrib/webapps/backends/wordpress.py | 2 +- orchestra/contrib/webapps/options.py | 2 +- 10 files changed, 42 insertions(+), 20 deletions(-) diff --git a/TODO.md b/TODO.md index 12e80b51..a16e0a27 100644 --- a/TODO.md +++ b/TODO.md @@ -384,3 +384,6 @@ http://wiki2.dovecot.org/Pigeonhole/Sieve/Examples # mail system users group? which one is more convinient? if main group does not exists, backend will fail! Bash/Python/PHPBackend + + +# Gandi sync domains cancelled diff --git a/orchestra/admin/options.py b/orchestra/admin/options.py index c6bab447..692a3da7 100644 --- a/orchestra/admin/options.py +++ b/orchestra/admin/options.py @@ -34,7 +34,6 @@ class ChangeListDefaultFilter(object): default_changelist_filters = () def changelist_view(self, request, extra_context=None): - """ Default filter as 'my_nodes=True' """ defaults = [] for key, value in self.default_changelist_filters: set_url_query(request, key, value) @@ -45,6 +44,22 @@ class ChangeListDefaultFilter(object): if hasattr(response, 'context_data') and 'cl' in response.context_data: response.context_data['cl'].default_changelist_filters = defaults return response + + + defaults = [] + querystring = request.META['QUERY_STRING'] + redirect = False + for field, value in self.default_changelist_filters: + if field not in queryseting: + redirect = True + querystring[field] = value + if redirect: + raise + if not request.META.get('HTTP_REFERER', '').startswith(request.build_absolute_uri()): + querystring = '&'.join('%s=%s' % filed, value in querystring.items()) + from django.http import HttpResponseRedirect + return HttpResponseRedirect(request.path + '?%s' % querystring) + return super(ChangeListDefaultFilter, self).changelist_view(request, extra_context=extra_context) class AtLeastOneRequiredInlineFormSet(BaseInlineFormSet): @@ -162,7 +177,7 @@ class ChangeAddFieldsMixin(object): return super(ChangeAddFieldsMixin, self).get_form(request, obj, **defaults) -class ExtendedModelAdmin(ChangeViewActionsMixin, ChangeAddFieldsMixin, admin.ModelAdmin): +class ExtendedModelAdmin(ChangeViewActionsMixin, ChangeAddFieldsMixin, ChangeListDefaultFilter, admin.ModelAdmin): list_prefetch_related = None def get_queryset(self, request): diff --git a/orchestra/contrib/issues/admin.py b/orchestra/contrib/issues/admin.py index b6d702ac..eac2b7c9 100644 --- a/orchestra/contrib/issues/admin.py +++ b/orchestra/contrib/issues/admin.py @@ -9,7 +9,7 @@ from django.utils.html import strip_tags from django.utils.translation import ugettext_lazy as _ from markdown import markdown -from orchestra.admin import ChangeListDefaultFilter, ExtendedModelAdmin#, ChangeViewActions +from orchestra.admin import ExtendedModelAdmin from orchestra.admin.utils import admin_link, admin_colored, wrap_admin_view, admin_date from orchestra.contrib.contacts.models import Contact @@ -118,7 +118,7 @@ class TicketInline(admin.TabularInline): ticket_id.allow_tags = True -class TicketAdmin(ChangeListDefaultFilter, ExtendedModelAdmin): +class TicketAdmin(ExtendedModelAdmin): list_display = ( 'unbold_id', 'bold_subject', 'display_creator', 'display_owner', 'display_queue', 'display_priority', 'display_state', 'updated' diff --git a/orchestra/contrib/mailboxes/backends.py b/orchestra/contrib/mailboxes/backends.py index fe3bb983..ccb77011 100644 --- a/orchestra/contrib/mailboxes/backends.py +++ b/orchestra/contrib/mailboxes/backends.py @@ -91,7 +91,9 @@ class UNIXUserMaildirBackend(SieveFilteringMixin, ServiceController): self.generate_filter(mailbox, context) def set_quota(self, mailbox, context): - context['quota'] = mailbox.resources.disk.allocated * mailbox.resources.disk.resource.get_scale() + allocated = mailbox.resources.disk.allocated + scale = mailbox.resources.disk.resource.get_scale() + context['quota'] = allocated * scale #unit_to_bytes(mailbox.resources.disk.unit) self.append(textwrap.dedent(""" # Set Maildir quota for %(user)s @@ -121,9 +123,10 @@ class UNIXUserMaildirBackend(SieveFilteringMixin, ServiceController): super(UNIXUserMaildirBackend, self).commit() def get_context(self, mailbox): + account_as_group = settings.MAILBOXES_USE_ACCOUNT_AS_GROUP context = { 'user': mailbox.name, - 'group': mailbox.account.username if settings.MAILBOXES_USE_ACCOUNT_AS_GROUP else mailbox.name, + 'group': mailbox.account.username if account_as_group else mailbox.name, 'name': mailbox.name, 'password': mailbox.password if mailbox.active else '*%s' % mailbox.password, 'home': mailbox.get_home(), @@ -311,9 +314,11 @@ class PostfixAddressBackend(PostfixAddressVirtualDomainBackend): Addresses based on Postfix virtual alias domains, includes PostfixAddressVirtualDomainBackend. """ verbose_name = _("Postfix address") - doc_settings = (settings, - ('MAILBOXES_LOCAL_DOMAIN', 'MAILBOXES_VIRTUAL_ALIAS_DOMAINS_PATH', 'MAILBOXES_VIRTUAL_ALIAS_MAPS_PATH') - ) + doc_settings = (settings, ( + 'MAILBOXES_LOCAL_DOMAIN', + 'MAILBOXES_VIRTUAL_ALIAS_DOMAINS_PATH', + 'MAILBOXES_VIRTUAL_ALIAS_MAPS_PATH' + )) def update_virtual_alias_maps(self, address, context): destination = address.destination diff --git a/orchestra/contrib/orchestration/backends.py b/orchestra/contrib/orchestration/backends.py index 02d62422..aa498d70 100644 --- a/orchestra/contrib/orchestration/backends.py +++ b/orchestra/contrib/orchestration/backends.py @@ -217,8 +217,8 @@ class ServiceBackend(plugins.Plugin, metaclass=ServiceMount): def commit(self): """ hook for executing something at the end - apply the configuration, usually reloading a service - reloading a service is done in a separated method in order to reload + apply the configuration, usually reloading a service + reloading a service is done in a separated method in order to reload the service once in bulk operations """ self.append('exit $exit_code') diff --git a/orchestra/contrib/services/helpers.py b/orchestra/contrib/services/helpers.py index 71f35298..3146dbb3 100644 --- a/orchestra/contrib/services/helpers.py +++ b/orchestra/contrib/services/helpers.py @@ -54,7 +54,7 @@ class Interval(object): return remaining def __repr__(self): - return "Start: {ini} End: {end}".format( + return "".format( ini=self.ini.strftime('%Y-%-m-%-d'), end=self.end.strftime('%Y-%-m-%-d') ) @@ -87,8 +87,7 @@ def get_intersections(order_intervals, compensations): for intersection_interval in intersection: length += len(intersection_interval) intersections.append((length, compensation)) - intersections.sort() - return intersections + return sorted(intersections, key=lambda i: i[0]) def intersect(compensation, order_intervals): diff --git a/orchestra/contrib/settings/templates/admin/settings/change_form.html b/orchestra/contrib/settings/templates/admin/settings/change_form.html index 930ee8cc..c144c1e3 100644 --- a/orchestra/contrib/settings/templates/admin/settings/change_form.html +++ b/orchestra/contrib/settings/templates/admin/settings/change_form.html @@ -55,7 +55,7 @@ {% regroup form.forms by app as formlist %} {% for app in formlist %}
-

{{ app.grouper|lower|capfirst }}

+

{{ app.grouper|lower|capfirst }}

{% for form in app.list %} {{ form.non_field_errors }} diff --git a/orchestra/contrib/webapps/backends/php.py b/orchestra/contrib/webapps/backends/php.py index cab3e92d..8bf483e4 100644 --- a/orchestra/contrib/webapps/backends/php.py +++ b/orchestra/contrib/webapps/backends/php.py @@ -205,8 +205,8 @@ class PHPBackend(WebAppServiceMixin, ServiceController): # Format PHP init vars init_vars = opt.get_php_init_vars(merge=self.MERGE) if init_vars: - init_vars = [ "-d %s='%s'" % (k, v.replace("'", '"')) for k,v in init_vars.items() ] - init_vars = ' \\\n '.join(init_vars) + init_vars = [ " \\\n -d %s='%s'" % (k, v.replace("'", '"')) for k,v in init_vars.items() ] + init_vars = ''.join(init_vars) context.update({ 'php_binary_path': os.path.normpath(settings.WEBAPPS_PHP_CGI_BINARY_PATH % context), 'php_rc': os.path.normpath(settings.WEBAPPS_PHP_CGI_RC_DIR % context), @@ -220,7 +220,7 @@ class PHPBackend(WebAppServiceMixin, ServiceController): export PHPRC=%(php_rc)s export PHP_INI_SCAN_DIR=%(php_ini_scan)s export PHP_FCGI_MAX_REQUESTS=%(max_requests)s - exec %(php_binary_path)s %(php_init_vars)s""") % context + exec %(php_binary_path)s%(php_init_vars)s""") % context def get_fcgid_cmd_options(self, webapp, context): options = self.get_options(webapp) diff --git a/orchestra/contrib/webapps/backends/wordpress.py b/orchestra/contrib/webapps/backends/wordpress.py index c86f4143..2462adcc 100644 --- a/orchestra/contrib/webapps/backends/wordpress.py +++ b/orchestra/contrib/webapps/backends/wordpress.py @@ -95,7 +95,7 @@ class WordPressBackend(WebAppServiceMixin, ServiceController): } exc('chown -R %(user)s:%(group)s %(app_path)s'); - // Execute wordpress installation process + // Run wordpress installation process define('WP_CONTENT_DIR', 'wp-content/'); define('WP_LANG_DIR', WP_CONTENT_DIR . '/languages' ); diff --git a/orchestra/contrib/webapps/options.py b/orchestra/contrib/webapps/options.py index a3d2624e..85165d96 100644 --- a/orchestra/contrib/webapps/options.py +++ b/orchestra/contrib/webapps/options.py @@ -95,7 +95,7 @@ class Processes(AppOption): class PHPEnableFunctions(PHPAppOption): name = 'enable_functions' verbose_name = _("Enable functions") - help_text = '%s' % '
'.join([ + help_text = '%s' % ',
'.join([ ','.join(settings.WEBAPPS_PHP_DISABLED_FUNCTIONS[i:i+10]) for i in range(0, len(settings.WEBAPPS_PHP_DISABLED_FUNCTIONS), 10) ])