diff --git a/orchestra/contrib/bills/filters.py b/orchestra/contrib/bills/filters.py index cb1b38e3..4aa772fd 100644 --- a/orchestra/contrib/bills/filters.py +++ b/orchestra/contrib/bills/filters.py @@ -101,16 +101,16 @@ class PaymentStateListFilter(SimpleListFilter): elif self.value() == 'PAID': zeros = queryset.filter(approx_total=0, approx_total__isnull=True) zeros = zeros.values_list('id', flat=True) - ammounts = Transaction.objects.exclude(bill_id__in=zeros).secured().group_by('bill_id') + amounts = Transaction.objects.exclude(bill_id__in=zeros).secured().group_by('bill_id') paid = [] relevant = queryset.exclude(approx_total=0, approx_total__isnull=True, is_open=True) for bill_id, total in relevant.values_list('id', 'approx_total'): try: - ammount = sum([t.ammount for t in ammounts[bill_id]]) + amount = sum([t.amount for t in amounts[bill_id]]) except KeyError: pass else: - if abs(total) <= abs(ammount): + if abs(total) <= abs(amount): paid.append(bill_id) return queryset.filter( Q(approx_total=0) | @@ -120,8 +120,9 @@ class PaymentStateListFilter(SimpleListFilter): elif self.value() == 'PENDING': has_transaction = queryset.exclude(transactions__isnull=True) non_rejected = has_transaction.exclude(transactions__state=Transaction.REJECTED) - non_rejected = non_rejected.values_list('id', flat=True).distinct() - return queryset.filter(pk__in=non_rejected) + paid = non_rejected.exclude(transactions__state=Transaction.SECURED) + paid = paid.values_list('id', flat=True).distinct() + return queryset.filter(pk__in=paid) elif self.value() == 'BAD_DEBT': closed = queryset.filter(is_open=False).exclude(approx_total=0) return closed.filter( diff --git a/orchestra/contrib/domains/admin.py b/orchestra/contrib/domains/admin.py index 7f7e0573..4ad7d3d5 100644 --- a/orchestra/contrib/domains/admin.py +++ b/orchestra/contrib/domains/admin.py @@ -94,7 +94,13 @@ class DomainAdmin(AccountAdminMixin, ExtendedModelAdmin): link = '%s %s' % (admin_url, website.name, site_link) links.append(link) return '
'.join(links) - return _("No website") + context = { + 'title': _("View on site"), + 'url': 'http://%s' % domain.name, + 'image': '' % static('orchestra/images/view-on-site.png'), + } + site_link = '%(image)s' % context + return _("No website %s") % site_link display_websites.admin_order_field = 'websites__name' display_websites.short_description = _("Websites") display_websites.allow_tags = True diff --git a/orchestra/contrib/payments/admin.py b/orchestra/contrib/payments/admin.py index ccbfe126..e71e34bc 100644 --- a/orchestra/contrib/payments/admin.py +++ b/orchestra/contrib/payments/admin.py @@ -105,7 +105,6 @@ class TransactionAdmin(SelectAccountAdminMixin, ExtendedModelAdmin): source_link = admin_link('source') process_link = admin_link('process', short_description=_("proc")) account_link = admin_link('bill__account') - display_state = admin_colored('state', colors=STATE_COLORS) def get_change_view_actions(self, obj=None): actions = super(TransactionAdmin, self).get_change_view_actions() @@ -120,6 +119,15 @@ class TransactionAdmin(SelectAccountAdminMixin, ExtendedModelAdmin): elif obj.state in [Transaction.REJECTED, Transaction.SECURED]: return [] return [action for action in actions if action.__name__ not in exclude] + + def display_state(self, obj): + state = admin_colored('state', colors=STATE_COLORS)(obj) + help_text = obj.get_state_help() + state = state.replace('= self.bill.total: raise ValidationError(_("New transactions can not be allocated for this bill.")) - def check_state(self, *args): - if self.state not in args: - raise TypeError("Transaction not in %s" % ' or '.join(args)) + def get_state_help(self): + if self.source: + return self.source.method_instance.state_help.get(self.state) or self.STATE_HELP.get(self.state) + return self.STATE_HELP.get(self.state) def mark_as_processed(self): - self.check_state(self.WAITTING_PROCESSING) self.state = self.WAITTING_EXECUTION self.save(update_fields=('state', 'modified_at')) def mark_as_executed(self): - self.check_state(self.WAITTING_EXECUTION) self.state = self.EXECUTED self.save(update_fields=('state', 'modified_at')) def mark_as_secured(self): - self.check_state(self.EXECUTED) self.state = self.SECURED self.save(update_fields=('state', 'modified_at')) @@ -178,26 +186,19 @@ class TransactionProcess(models.Model): def __str__(self): return '#%i' % self.id - def check_state(self, *args): - if self.state not in args: - raise TypeError("Transaction process not in %s" % ' or '.join(args)) - def mark_as_executed(self): - self.check_state(self.CREATED) self.state = self.EXECUTED for transaction in self.transactions.all(): transaction.mark_as_executed() self.save(update_fields=('state',)) def abort(self): - self.check_state(self.CREATED, self.EXCECUTED) self.state = self.ABORTED for transaction in self.transaction.all(): transaction.mark_as_aborted() self.save(update_fields=('state',)) def commit(self): - self.check_state(self.CREATED, self.EXECUTED) self.state = self.COMMITED for transaction in self.transactions.processing(): transaction.mark_as_secured() diff --git a/orchestra/contrib/saas/backends/wordpressmu.py b/orchestra/contrib/saas/backends/wordpressmu.py index 5d6dc25d..906f3a49 100644 --- a/orchestra/contrib/saas/backends/wordpressmu.py +++ b/orchestra/contrib/saas/backends/wordpressmu.py @@ -17,24 +17,24 @@ class WordpressMuBackend(ServiceController): model = 'saas.SaaS' default_route_match = "saas.service == 'wordpress'" doc_settings = (settings, - ('SAAS_WORDPRESS_ADMIN_PASSWORD', 'SAAS_WORDPRESS_BASE_URL') + ('SAAS_WORDPRESS_ADMIN_PASSWORD', 'SAAS_WORDPRESS_MAIN_URL') ) def login(self, session): - base_url = self.get_base_url() - login_url = base_url + '/wp-login.php' + main_url = self.get_main_url() + login_url = main_url + '/wp-login.php' login_data = { 'log': 'admin', 'pwd': settings.SAAS_WORDPRESS_ADMIN_PASSWORD, 'redirect_to': '/wp-admin/' } response = session.post(login_url, data=login_data) - if response.url != base_url + '/wp-admin/': + if response.url != main_url + '/wp-admin/': raise IOError("Failure login to remote application") - def get_base_url(self): - base_url = settings.SAAS_WORDPRESS_BASE_URL - return base_url.rstrip('/') + def get_main_url(self): + main_url = settings.SAAS_WORDPRESS_MAIN_URL + return main_url.rstrip('/') def validate_response(self, response): if response.status_code != 200: @@ -42,7 +42,7 @@ class WordpressMuBackend(ServiceController): raise RuntimeError(errors[0] if errors else 'Unknown %i error' % response.status_code) def get_id(self, session, saas): - search = self.get_base_url() + search = self.get_main_url() search += '/wp-admin/network/sites.php?s=%s&action=blogs' % saas.name regex = re.compile( '