From 4e900442636be5e40ce8431e1fce50209dd9bc64 Mon Sep 17 00:00:00 2001 From: Marc Date: Tue, 29 Jul 2014 20:25:57 +0000 Subject: [PATCH] Renamed BankTransfer payment method to DirectDebt --- orchestra/apps/issues/actions.py | 49 +++++++++++++++++++----------- orchestra/apps/payments/admin.py | 4 +-- orchestra/apps/payments/forms.py | 2 +- orchestra/apps/payments/methods.py | 12 ++++---- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/orchestra/apps/issues/actions.py b/orchestra/apps/issues/actions.py index 64ac89ed..998d9a6a 100644 --- a/orchestra/apps/issues/actions.py +++ b/orchestra/apps/issues/actions.py @@ -2,6 +2,7 @@ import sys from django.contrib import messages from django.db import transaction +from django.utils.translation import ugettext_lazy as _ from orchestra.admin.decorators import action_with_confirmation @@ -23,25 +24,32 @@ def change_ticket_state_factory(action, final_state): reason = form.cleaned_data['reason'] for ticket in queryset: if ticket.state != final_state: - changes = {'state': (ticket.state, final_state)} + changes = { + 'state': (ticket.state, final_state) + } is_read = ticket.is_read_by(request.user) getattr(ticket, action)() - modeladmin.log_change(request, ticket, "Marked as %s" % final_state.lower()) + msg = _("Marked as %s") % final_state.lower() + modeladmin.log_change(request, ticket, msg) content = markdown_formated_changes(changes) content += reason ticket.messages.create(content=content, author=request.user) if is_read and not ticket.is_read_by(request.user): ticket.mark_as_read_by(request.user) - msg = "%s selected tickets are now %s." % (queryset.count(), final_state.lower()) + context = { + 'count': queryset.count(), + 'state': final_state.lower() + } + msg = _("%s selected tickets are now %s.") % context modeladmin.message_user(request, msg) else: context['form'] = form # action_with_confirmation must display form validation errors return True change_ticket_state.url_name = action - change_ticket_state.verbose_name = u'%s\u2026' % action - change_ticket_state.short_description = '%s selected tickets' % action.capitalize() - change_ticket_state.description = 'Mark ticket as %s.' % final_state.lower() + change_ticket_state.verbose_name = action + change_ticket_state.short_description = _('%s selected tickets') % action.capitalize() + change_ticket_state.description = _('Mark ticket as %s.') % final_state.lower() change_ticket_state.__name__ = action return change_ticket_state @@ -49,7 +57,8 @@ def change_ticket_state_factory(action, final_state): action_map = { Ticket.RESOLVED: 'resolve', Ticket.REJECTED: 'reject', - Ticket.CLOSED: 'close' } + Ticket.CLOSED: 'close' +} thismodule = sys.modules[__name__] @@ -62,19 +71,25 @@ for state, name in action_map.items(): def take_tickets(modeladmin, request, queryset): for ticket in queryset: if ticket.owner != request.user: - changes = {'owner': (ticket.owner, request.user)} + changes = { + 'owner': (ticket.owner, request.user) + } is_read = ticket.is_read_by(request.user) ticket.take(request.user) - modeladmin.log_change(request, ticket, "Taken") + modeladmin.log_change(request, ticket, _("Taken")) content = markdown_formated_changes(changes) ticket.messages.create(content=content, author=request.user) if is_read and not ticket.is_read_by(request.user): ticket.mark_as_read_by(request.user) - msg = "%s selected tickets are now owned by %s." % (queryset.count(), request.user) + context = { + 'count': queryset.count(), + 'user': request.user + } + msg = _("%(count)s selected tickets are now owned by %(user)s.") % context modeladmin.message_user(request, msg) take_tickets.url_name = 'take' -take_tickets.short_description = 'Take selected tickets' -take_tickets.description = 'Make yourself owner of the ticket.' +take_tickets.short_description = _("Take selected tickets") +take_tickets.description = _("Make yourself owner of the ticket.") @transaction.atomic @@ -82,7 +97,7 @@ def mark_as_unread(modeladmin, request, queryset): """ Mark a tickets as unread """ for ticket in queryset: ticket.mark_as_unread_by(request.user) - msg = "%s selected tickets have been marked as unread." % queryset.count() + msg = _("%s selected tickets have been marked as unread.") % queryset.count() modeladmin.message_user(request, msg) @@ -91,7 +106,7 @@ def mark_as_read(modeladmin, request, queryset): """ Mark a tickets as unread """ for ticket in queryset: ticket.mark_as_read_by(request.user) - msg = "%s selected tickets have been marked as read." % queryset.count() + msg = _("%s selected tickets have been marked as read.") % queryset.count() modeladmin.message_user(request, msg) @@ -99,11 +114,11 @@ def mark_as_read(modeladmin, request, queryset): def set_default_queue(modeladmin, request, queryset): """ Set a queue as default issues queue """ if queryset.count() != 1: - messages.warning(request, "Please, select only one queue.") + messages.warning(request, _("Please, select only one queue.")) return Queue.objects.filter(default=True).update(default=False) queue = queryset.get() queue.default = True queue.save() - modeladmin.log_change(request, queue, "Chosen as default.") - messages.info(request, "Chosen '%s' as default queue." % queue) + modeladmin.log_change(request, queue, _("Chosen as default.")) + messages.info(request, _("Chosen '%s' as default queue.") % queue) diff --git a/orchestra/apps/payments/admin.py b/orchestra/apps/payments/admin.py index 1c236891..faf2994b 100644 --- a/orchestra/apps/payments/admin.py +++ b/orchestra/apps/payments/admin.py @@ -6,7 +6,7 @@ from orchestra.admin.utils import admin_colored, admin_link from orchestra.apps.accounts.admin import AccountAdminMixin from .actions import process_transactions -from .methods import BankTransfer +from .methods import DirectDebit from .models import PaymentSource, Transaction, PaymentProcess @@ -35,7 +35,7 @@ class TransactionAdmin(admin.ModelAdmin): class PaymentSourceAdmin(AccountAdminMixin, admin.ModelAdmin): list_display = ('label', 'method', 'number', 'account_link', 'is_active') list_filter = ('method', 'is_active') - form = BankTransfer().get_form() + form = DirectDebit().get_form() # TODO select payment source method diff --git a/orchestra/apps/payments/forms.py b/orchestra/apps/payments/forms.py index 36445b20..47fdc3b0 100644 --- a/orchestra/apps/payments/forms.py +++ b/orchestra/apps/payments/forms.py @@ -24,7 +24,7 @@ class PaymentSourceDataForm(forms.ModelForm): return super(PaymentSourceDataForm, self).save(commit=commit) -class BankTransferForm(PaymentSourceDataForm): +class DirectDebitForm(PaymentSourceDataForm): iban = IBANFormField(label='IBAN', widget=forms.TextInput(attrs={'size': '50'})) name = forms.CharField(max_length=128, label=_("Name"), diff --git a/orchestra/apps/payments/methods.py b/orchestra/apps/payments/methods.py index d287f403..cf3b6231 100644 --- a/orchestra/apps/payments/methods.py +++ b/orchestra/apps/payments/methods.py @@ -13,7 +13,7 @@ from rest_framework import serializers from orchestra.utils import plugins from . import settings -from .forms import BankTransferForm, CreditCardForm +from .forms import DirectDebitForm, CreditCardForm class PaymentMethod(plugins.Plugin): @@ -37,7 +37,7 @@ class PaymentMethod(plugins.Plugin): return data[self.number_field] -class BankTransferSerializer(serializers.Serializer): +class DirectDebitSerializer(serializers.Serializer): iban = serializers.CharField(label='IBAN', validators=[IBANValidator()], min_length=min(IBAN_COUNTRY_CODE_LENGTH.values()), max_length=34) name = serializers.CharField(label=_("Name"), max_length=128) @@ -47,12 +47,12 @@ class CreditCardSerializer(serializers.Serializer): pass -class BankTransfer(PaymentMethod): - verbose_name = _("Bank transfer") +class DirectDebit(PaymentMethod): + verbose_name = _("Direct debit") label_field = 'name' number_field = 'iban' - form = BankTransferForm - serializer = BankTransferSerializer + form = DirectDebitForm + serializer = DirectDebitSerializer def _process_transactions(self, transactions): for transaction in transactions: