From 8cb36619e32cd2d1ab307560c8aec463ef2ba46f Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Thu, 9 Jul 2015 10:44:22 +0000 Subject: [PATCH] Random fixes --- TODO.md | 4 ---- orchestra/admin/decorators.py | 2 +- orchestra/admin/options.py | 30 ++++++++++++-------------- orchestra/admin/utils.py | 2 +- orchestra/contrib/bills/admin.py | 4 +++- orchestra/contrib/orders/models.py | 9 ++++---- orchestra/contrib/payments/models.py | 9 +++++--- orchestra/contrib/webapps/types/php.py | 4 ++-- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/TODO.md b/TODO.md index 5fd1a19a..f4334e58 100644 --- a/TODO.md +++ b/TODO.md @@ -438,8 +438,6 @@ serailzer self.instance on create. # Automatically mark as paid transactions with 0 or prevent its creation? -# Confirmation steps on amend and other billing actions - @register.filter def comma(value): @@ -449,5 +447,3 @@ def comma(value): return ','.join((left, right)) return value - -# db_index on date_hierarchy diff --git a/orchestra/admin/decorators.py b/orchestra/admin/decorators.py index 5531c495..4c812841 100644 --- a/orchestra/admin/decorators.py +++ b/orchestra/admin/decorators.py @@ -70,7 +70,7 @@ def action_with_confirmation(action_name=None, extra_context={}, context = { 'title': _("Are you sure?"), 'content_message': _("Are you sure you want to {action} the selected {item}?").format( - action=action_name, item=objects_name), + action=action_name, item=objects_name), 'action_name': action_name.capitalize(), 'action_value': action_value, 'queryset': queryset, diff --git a/orchestra/admin/options.py b/orchestra/admin/options.py index 9abd71dc..c3a132d4 100644 --- a/orchestra/admin/options.py +++ b/orchestra/admin/options.py @@ -44,22 +44,20 @@ 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) +# 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): diff --git a/orchestra/admin/utils.py b/orchestra/admin/utils.py index 0a70a89a..a74b04f2 100644 --- a/orchestra/admin/utils.py +++ b/orchestra/admin/utils.py @@ -1,4 +1,5 @@ import datetime +import importlib import inspect from functools import wraps @@ -8,7 +9,6 @@ from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse, NoReverseMatch from django.db import models from django.shortcuts import redirect -import importlib from django.utils.html import escape from django.utils.safestring import mark_safe diff --git a/orchestra/contrib/bills/admin.py b/orchestra/contrib/bills/admin.py index a24e298d..1cabf881 100644 --- a/orchestra/contrib/bills/admin.py +++ b/orchestra/contrib/bills/admin.py @@ -331,7 +331,9 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin): (F('lines__subtotal') + Coalesce(F('lines__sublines__total'), 0)) * (1+F('lines__tax')/100) ), ) - qs = qs.prefetch_related(Prefetch('amends', queryset=Bill.objects.filter(is_open=False), to_attr='closed_amends')) + qs = qs.prefetch_related( + Prefetch('amends', queryset=Bill.objects.filter(is_open=False), to_attr='closed_amends') + ) return qs def change_view(self, request, object_id, **kwargs): diff --git a/orchestra/contrib/orders/models.py b/orchestra/contrib/orders/models.py index 71251bd1..9305b16b 100644 --- a/orchestra/contrib/orders/models.py +++ b/orchestra/contrib/orders/models.py @@ -62,10 +62,10 @@ class OrderQuerySet(models.QuerySet): conflictive = self.filter(service__metric='') conflictive = conflictive.exclude(service__billing_period=Service.NEVER) # Exclude rates null or all rates with quantity 0 - conflictive = conflictive.annotate(quantity_sum=Sum('service__rates__quantity')).exclude(quantity_sum=0) - conflictive = conflictive.select_related('service').distinct().group_by('account_id', 'service') + conflictive = conflictive.annotate(quantity_sum=Sum('service__rates__quantity')) + conflictive = conflictive.exclude(quantity_sum=0).select_related('service').distinct() qs = Q() - for account_id, services in conflictive.items(): + for account_id, services in conflictive.group_by('account_id', 'service').items(): for service, orders in services.items(): ini = datetime.date.max end = datetime.date.min @@ -137,7 +137,8 @@ class Order(models.Model): else: services = [service] for service in services: - orders = Order.objects.by_object(instance, service=service).select_related('service').active() + orders = Order.objects.by_object(instance, service=service) + orders = orders.select_related('service').active() if service.handler.matches(instance): if not orders: account_id = getattr(instance, 'account_id', instance.pk) diff --git a/orchestra/contrib/payments/models.py b/orchestra/contrib/payments/models.py index 15e09151..28fa835d 100644 --- a/orchestra/contrib/payments/models.py +++ b/orchestra/contrib/payments/models.py @@ -66,7 +66,10 @@ class TransactionQuerySet(models.QuerySet): source = kwargs.get('source') if source is None or not hasattr(source.method_class, 'process'): # Manual payments don't need processing - kwargs['state']=self.model.WAITTING_EXECUTION + kwargs['state'] = self.model.WAITTING_EXECUTION + amount = kwargs.get('amount') + if amount == 0: + kwargs['state'] = self.model.SECURED return super(TransactionQuerySet, self).create(**kwargs) def secured(self): @@ -100,8 +103,8 @@ class Transaction(models.Model): related_name='transactions') source = models.ForeignKey(PaymentSource, null=True, blank=True, verbose_name=_("source"), related_name='transactions') - process = models.ForeignKey('payments.TransactionProcess', null=True, on_delete=models.SET_NULL, - blank=True, verbose_name=_("process"), related_name='transactions') + process = models.ForeignKey('payments.TransactionProcess', null=True, blank=True, + on_delete=models.SET_NULL, verbose_name=_("process"), related_name='transactions') state = models.CharField(_("state"), max_length=32, choices=STATES, default=WAITTING_PROCESSING) amount = models.DecimalField(_("amount"), max_digits=12, decimal_places=2) diff --git a/orchestra/contrib/webapps/types/php.py b/orchestra/contrib/webapps/types/php.py index d7d93ec6..59c1aac3 100644 --- a/orchestra/contrib/webapps/types/php.py +++ b/orchestra/contrib/webapps/types/php.py @@ -101,8 +101,9 @@ class PHPApp(AppType): init_vars['disable_functions'] = ','.join(disable_functions) # Process timeout if timeout: + timeout = max(settings.WEBAPPS_PYTHON_DEFAULT_TIMEOUT, int(timeout)) # Give a little slack here - timeout = str(int(timeout)-2) + timeout = str(timeout-2) init_vars['max_execution_time'] = timeout # Custom error log if self.PHP_ERROR_LOG_PATH and 'error_log' not in init_vars: @@ -147,4 +148,3 @@ class PHPApp(AppType): def get_php_version_number(self): php_version = self.get_php_version() return utils.extract_version_number(php_version) -