Orders content_object_repr for deleted content_objects

This commit is contained in:
Marc Aymerich 2015-07-15 12:13:03 +00:00
parent caa087deb6
commit 857f0c0958
11 changed files with 306 additions and 140 deletions

View file

@ -424,3 +424,6 @@ Colaesce('total', 'computed_total')
Case
# case on payment transaction state ? case when trans.amount >
# ORDERS keep content_object verbose name for deleted objects

View file

@ -109,7 +109,7 @@ def admin_link(*args, **kwargs):
return '---'
display = kwargs.get('display')
if display:
display = getattr(obj, display, 'merda')
display = getattr(obj, display, None)
else:
display = obj
try:

View file

@ -20,24 +20,36 @@ class Domain(models.Model):
top = models.ForeignKey('domains.Domain', null=True, related_name='subdomain_set',
editable=False)
serial = models.IntegerField(_("serial"), default=utils.generate_zone_serial, editable=False,
help_text=_("A timestamp that changes whenever you update your domain."))
help_text=_("A revision number that changes whenever you update your domain."))
refresh = models.IntegerField(_("refresh"), null=True, blank=True,
validators=[validators.validate_zone_interval],
help_text=_("The number of seconds before the zone should be refreshed "
"(<tt>%s</tt> by default).") % settings.DOMAINS_DEFAULT_REFRESH)
help_text=_("The time a secondary DNS server waits before querying the primary DNS "
"server's SOA record to check for changes. When the refresh time expires, "
"the secondary DNS server requests a copy of the current SOA record from "
"the primary. The primary DNS server complies with this request. "
"The secondary DNS server compares the serial number of the primary DNS "
"server's current SOA record and the serial number in it's own SOA record. "
"If they are different, the secondary DNS server will request a zone "
"transfer from the primary DNS server. "
"The default value is <tt>%s</tt>.") % settings.DOMAINS_DEFAULT_REFRESH)
retry = models.IntegerField(_("retry"), null=True, blank=True,
validators=[validators.validate_zone_interval],
help_text=_("The number of seconds before a failed refresh should be retried "
"(<tt>%s</tt> by default).") % settings.DOMAINS_DEFAULT_RETRY)
help_text=_("The time a secondary server waits before retrying a failed zone transfer. "
"Normally, the retry time is less than the refresh time. "
"The default value is <tt>%s</tt>.") % settings.DOMAINS_DEFAULT_RETRY)
expire = models.IntegerField(_("expire"), null=True, blank=True,
validators=[validators.validate_zone_interval],
help_text=_("The upper limit in seconds before a zone is considered no longer "
"authoritative (<tt>%s</tt> by default).") % settings.DOMAINS_DEFAULT_EXPIRE)
min_ttl = models.IntegerField(_("refresh"), null=True, blank=True,
help_text=_("The time that a secondary server will keep trying to complete a zone "
"transfer. If this time expires prior to a successful zone transfer, "
"the secondary server will expire its zone file. This means the secondary "
"will stop answering queries. "
"The default value is <tt>%s</tt>.") % settings.DOMAINS_DEFAULT_EXPIRE)
min_ttl = models.IntegerField(_("min TTL"), null=True, blank=True,
validators=[validators.validate_zone_interval],
help_text=_("The negative result TTL (for example, how long a resolver should "
"consider a negative result for a subdomain to be valid before retrying) "
"(<tt>%s</tt> by default).") % settings.DOMAINS_DEFAULT_MIN_TTL)
help_text=_("The minimum time-to-live value applies to all resource records in the "
"zone file. This value is supplied in query responses to inform other "
"servers how long they should keep the data in cache. "
"The default value is <tt>%s</tt>.") % settings.DOMAINS_DEFAULT_MIN_TTL)
def __str__(self):
return self.name

View file

@ -1,5 +1,5 @@
from django.contrib import admin
from django.core.urlresolvers import reverse
from django.core.urlresolvers import reverse, NoReverseMatch
from django.db.models import Prefetch
from django.utils import timezone
from django.utils.html import escape
@ -7,7 +7,7 @@ from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from orchestra.admin import ExtendedModelAdmin
from orchestra.admin.utils import admin_link, admin_date
from orchestra.admin.utils import admin_link, admin_date, change_url
from orchestra.contrib.accounts.admin import AccountAdminMixin
from orchestra.utils.humanize import naturaldate
@ -60,18 +60,33 @@ class OrderAdmin(AccountAdminMixin, ExtendedModelAdmin):
date_hierarchy = 'registered_on'
inlines = (MetricStorageInline,)
add_inlines = ()
search_fields = ('account__username', 'description')
search_fields = ('account__username', 'content_object_repr', 'description',)
list_prefetch_related = (
'content_object',
Prefetch('metrics', queryset=MetricStorage.objects.order_by('-id')),
)
list_select_related = ('account', 'service')
readonly_fields = ('content_object_repr', 'content_object_link')
service_link = admin_link('service')
content_object_link = admin_link('content_object', order=False)
display_registered_on = admin_date('registered_on')
display_cancelled_on = admin_date('cancelled_on')
def content_object_link(self, order):
if order.content_object:
try:
url = change_url(order.content_object)
except NoReverseMatch:
# Does not has admin
return order.content_object_repr
description = str(order.content_object)
return '<a href="{url}">{description}</a>'.format(
url=url, description=description)
return order.content_object_repr
content_object_link.short_description = _("Content object")
content_object_link.allow_tags = True
content_object_link.admin_order_field = 'content_object_repr'
def display_billed_until(self, order):
billed_until = order.billed_until
red = False

View file

@ -118,6 +118,8 @@ class Order(models.Model):
billed_until = models.DateField(_("billed until"), null=True, blank=True)
ignore = models.BooleanField(_("ignore"), default=False)
description = models.TextField(_("description"), blank=True)
content_object_repr = models.CharField(_("content object representation"), max_length=256,
editable=False)
content_object = GenericForeignKey()
objects = OrderQuerySet.as_manager()
@ -146,8 +148,12 @@ class Order(models.Model):
# New account workaround -> user.account_id == None
continue
ignore = service.handler.get_ignore(instance)
order = cls(content_object=instance, service=service,
account_id=account_id, ignore=ignore)
order = cls(
content_object=instance,
content_object_repr=str(instance),
service=service,
account_id=account_id,
ignore=ignore)
if commit:
order.save()
updates.append((order, 'created'))
@ -187,9 +193,16 @@ class Order(models.Model):
logger.info("UPDATED order id:{id}, description:{description}{metric}".format(
id=self.id, description=description, metric=metric).encode('ascii', 'replace')
)
update_fields = []
if self.description != description:
self.description = description
self.save(update_fields=['description'])
update_fields.append('description')
content_object_repr = str(instance)
if self.content_object_repr != content_object_repr:
self.content_object_repr = content_object_repr
update_fields.append('content_object_repr')
if update_fields:
self.save(update_fields=update_fields)
def cancel(self, commit=True):
self.cancelled_on = timezone.now()

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-05-28 16:40+0000\n"
"POT-Creation-Date: 2015-07-15 12:08+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -18,133 +18,154 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: actions.py:21
#: actions.py:24
msgid "Selected transactions must be on '{state}' state"
msgstr ""
#: actions.py:30
#: actions.py:34
msgid "Processed"
msgstr ""
#: actions.py:37
msgid "Selected transaction has been processed."
#: actions.py:41
msgid "One selected transaction has been processed."
msgstr ""
#: actions.py:38
#: actions.py:42
#, python-format
msgid "%s Selected transactions have been processed."
msgstr ""
#: actions.py:41
#: actions.py:45
msgid ""
"The following transaction process has been generated, you may want to save "
"it on your computer now."
msgstr ""
#: actions.py:43
#: actions.py:47
#, python-format
msgid ""
"The following %s transaction processes have been generated, you may want to "
"save it on your computer now."
msgstr ""
#: actions.py:46
#: actions.py:50
msgid "Process"
msgstr ""
#: actions.py:59 actions.py:130 models.py:93 models.py:161
#: actions.py:63 actions.py:134 models.py:97 models.py:164
msgid "Executed"
msgstr ""
#: actions.py:62
#: actions.py:66
msgid "One selected transaction has been marked as executed."
msgstr ""
#: actions.py:63
#: actions.py:67
#, python-format
msgid "%s selected transactions have been marked as executed."
msgstr ""
#: actions.py:67 actions.py:138
#: actions.py:71 actions.py:142
msgid "Mark as executed"
msgstr ""
#: actions.py:75 models.py:94
#: actions.py:79 models.py:98
msgid "Secured"
msgstr ""
#: actions.py:78
#: actions.py:82
msgid "One selected transaction has been marked as secured."
msgstr ""
#: actions.py:79
#: actions.py:83
#, python-format
msgid "%s selected transactions have been marked as secured."
msgstr ""
#: actions.py:83
#: actions.py:87
msgid "Mark as secured"
msgstr ""
#: actions.py:91 actions.py:162 models.py:95
#: actions.py:95 actions.py:166 models.py:99
msgid "Rejected"
msgstr ""
#: actions.py:94 actions.py:165
#: actions.py:98 actions.py:169
msgid "One selected transaction has been marked as rejected."
msgstr ""
#: actions.py:95 actions.py:166
#: actions.py:99 actions.py:170
#, python-format
msgid "%s selected transactions have been marked as rejected."
msgstr ""
#: actions.py:99
#: actions.py:103
msgid "Mark as rejected"
msgstr ""
#: actions.py:133
#: actions.py:137
msgid "One selected process has been marked as executed."
msgstr ""
#: actions.py:134
#: actions.py:138
#, python-format
msgid "%s selected processes have been marked as executed."
msgstr ""
#: actions.py:146 models.py:162
#: actions.py:150 models.py:165
msgid "Aborted"
msgstr ""
#: actions.py:149
#: actions.py:153
msgid "One selected process has been aborted."
msgstr ""
#: actions.py:150
#: actions.py:154
#, python-format
msgid "%s selected processes have been aborted."
msgstr ""
#: actions.py:154
#: actions.py:158
msgid "Abort"
msgstr ""
#: actions.py:170
#: actions.py:174
msgid "Commit"
msgstr ""
#: admin.py:42
#: admin.py:43
msgid "ID"
msgstr ""
#: admin.py:101
#: admin.py:105
msgid "proc"
msgstr ""
#: admin.py:152
#: admin.py:158
msgid "Transactions"
msgstr ""
#: helpers.py:11
msgid "No transaction process selected."
msgstr ""
#: helpers.py:15
msgid "Done nothing. Not all related transactions in waitting execution."
msgstr ""
#: helpers.py:32
msgid "Unprocessed"
msgstr ""
#: helpers.py:34
#, python-format
msgid ""
"One related transaction has been marked as <i>waitting for processing</i>"
msgid_plural ""
"%i related transactions have been marked as <i>waitting for processing</i>."
msgstr[0] ""
msgstr[1] ""
#: methods/creditcard.py:11
msgid "Label"
msgstr ""
@ -165,86 +186,123 @@ msgstr ""
msgid "SEPA Direct Debit"
msgstr ""
#: methods/sepadirectdebit.py:48
msgid ""
"This bill will be automatically charged to your bank account with IBAN "
"number<br><strong>%s</strong>."
msgstr ""
"Aquesta factura es cobrarà automaticament en el teu compte bancari amb IBAN "
"<br><strong>%s</strong>."
#: models.py:19
#: models.py:20
msgid "account"
msgstr ""
#: models.py:21
#: models.py:22
msgid "method"
msgstr ""
#: models.py:23 models.py:166
#: models.py:24 models.py:169
msgid "data"
msgstr ""
#: models.py:24
#: models.py:25
msgid "active"
msgstr ""
#: models.py:91
#: models.py:95
msgid "Waitting processing"
msgstr ""
#: models.py:92
#: models.py:96
msgid "Waitting execution"
msgstr ""
#: models.py:98
#: models.py:102
msgid "bill"
msgstr ""
#: models.py:101
#: models.py:105
msgid "source"
msgstr ""
#: models.py:103
#: models.py:107
msgid "process"
msgstr ""
#: models.py:104 models.py:168
#: models.py:108 models.py:171
msgid "state"
msgstr ""
#: models.py:106
#: models.py:110
msgid "amount"
msgstr ""
#: models.py:108 models.py:169
#: models.py:112 models.py:172
msgid "created"
msgstr ""
#: models.py:109
#: models.py:113
msgid "modified"
msgstr ""
#: models.py:124
#: models.py:128
msgid "New transactions can not be allocated for this bill."
msgstr ""
#: models.py:160
#: models.py:163 templates/admin/payments/transaction/report.html:63
msgid "Created"
msgstr ""
#: models.py:163
#: models.py:166
msgid "Commited"
msgstr ""
#: models.py:167
#: models.py:170
msgid "file"
msgstr ""
#: models.py:170
#: models.py:173
msgid "updated"
msgstr ""
#: models.py:173
#: models.py:176
msgid "Transaction processes"
msgstr ""
#: settings.py:12
#, fuzzy, python-format
#| msgid ""
#| "This bill will be automatically charged to your bank account with IBAN "
#| "number<br><strong>%s</strong>."
msgid ""
"<strong>Direct debit</strong>, this bill will be automatically charged to "
"your bank account with IBAN number<br><strong>%(number)s</strong>."
msgstr ""
"<strong>Càrrec per domiciliació</strong>, aquesta factura es cobrarà "
"automaticament en el teu compte bancari amb IBAN <br><strong>%s</strong>."
#: templates/admin/payments/transaction/report.html:38
msgid "Summary"
msgstr ""
#: templates/admin/payments/transaction/report.html:39
#: templates/admin/payments/transaction/report.html:61
msgid "Amount"
msgstr ""
#: templates/admin/payments/transaction/report.html:48
msgid "TOTAL"
msgstr ""
#: templates/admin/payments/transaction/report.html:57
msgid "Bill"
msgstr ""
#: templates/admin/payments/transaction/report.html:58
msgid "Account"
msgstr ""
#: templates/admin/payments/transaction/report.html:59
msgid "Contact"
msgstr ""
#: templates/admin/payments/transaction/report.html:62
msgid "State"
msgstr ""
#: templates/admin/payments/transaction/report.html:64
msgid "Updated"
msgstr ""

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-05-28 16:40+0000\n"
"POT-Creation-Date: 2015-07-15 12:08+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -18,133 +18,154 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: actions.py:21
#: actions.py:24
msgid "Selected transactions must be on '{state}' state"
msgstr ""
#: actions.py:30
#: actions.py:34
msgid "Processed"
msgstr ""
#: actions.py:37
msgid "Selected transaction has been processed."
#: actions.py:41
msgid "One selected transaction has been processed."
msgstr ""
#: actions.py:38
#: actions.py:42
#, python-format
msgid "%s Selected transactions have been processed."
msgstr ""
#: actions.py:41
#: actions.py:45
msgid ""
"The following transaction process has been generated, you may want to save "
"it on your computer now."
msgstr ""
#: actions.py:43
#: actions.py:47
#, python-format
msgid ""
"The following %s transaction processes have been generated, you may want to "
"save it on your computer now."
msgstr ""
#: actions.py:46
#: actions.py:50
msgid "Process"
msgstr ""
#: actions.py:59 actions.py:130 models.py:93 models.py:161
#: actions.py:63 actions.py:134 models.py:97 models.py:164
msgid "Executed"
msgstr ""
#: actions.py:62
#: actions.py:66
msgid "One selected transaction has been marked as executed."
msgstr ""
#: actions.py:63
#: actions.py:67
#, python-format
msgid "%s selected transactions have been marked as executed."
msgstr ""
#: actions.py:67 actions.py:138
#: actions.py:71 actions.py:142
msgid "Mark as executed"
msgstr ""
#: actions.py:75 models.py:94
#: actions.py:79 models.py:98
msgid "Secured"
msgstr ""
#: actions.py:78
#: actions.py:82
msgid "One selected transaction has been marked as secured."
msgstr ""
#: actions.py:79
#: actions.py:83
#, python-format
msgid "%s selected transactions have been marked as secured."
msgstr ""
#: actions.py:83
#: actions.py:87
msgid "Mark as secured"
msgstr ""
#: actions.py:91 actions.py:162 models.py:95
#: actions.py:95 actions.py:166 models.py:99
msgid "Rejected"
msgstr ""
#: actions.py:94 actions.py:165
#: actions.py:98 actions.py:169
msgid "One selected transaction has been marked as rejected."
msgstr ""
#: actions.py:95 actions.py:166
#: actions.py:99 actions.py:170
#, python-format
msgid "%s selected transactions have been marked as rejected."
msgstr ""
#: actions.py:99
#: actions.py:103
msgid "Mark as rejected"
msgstr ""
#: actions.py:133
#: actions.py:137
msgid "One selected process has been marked as executed."
msgstr ""
#: actions.py:134
#: actions.py:138
#, python-format
msgid "%s selected processes have been marked as executed."
msgstr ""
#: actions.py:146 models.py:162
#: actions.py:150 models.py:165
msgid "Aborted"
msgstr ""
#: actions.py:149
#: actions.py:153
msgid "One selected process has been aborted."
msgstr ""
#: actions.py:150
#: actions.py:154
#, python-format
msgid "%s selected processes have been aborted."
msgstr ""
#: actions.py:154
#: actions.py:158
msgid "Abort"
msgstr ""
#: actions.py:170
#: actions.py:174
msgid "Commit"
msgstr ""
#: admin.py:42
#: admin.py:43
msgid "ID"
msgstr ""
#: admin.py:101
#: admin.py:105
msgid "proc"
msgstr ""
#: admin.py:152
#: admin.py:158
msgid "Transactions"
msgstr ""
#: helpers.py:11
msgid "No transaction process selected."
msgstr ""
#: helpers.py:15
msgid "Done nothing. Not all related transactions in waitting execution."
msgstr ""
#: helpers.py:32
msgid "Unprocessed"
msgstr ""
#: helpers.py:34
#, python-format
msgid ""
"One related transaction has been marked as <i>waitting for processing</i>"
msgid_plural ""
"%i related transactions have been marked as <i>waitting for processing</i>."
msgstr[0] ""
msgstr[1] ""
#: methods/creditcard.py:11
msgid "Label"
msgstr ""
@ -165,86 +186,123 @@ msgstr ""
msgid "SEPA Direct Debit"
msgstr ""
#: methods/sepadirectdebit.py:48
msgid ""
"This bill will be automatically charged to your bank account with IBAN "
"number<br><strong>%s</strong>."
msgstr ""
"Esta factura se cobrará automaticamente en tu cuenta bancaria con IBAN "
"<br><strong>%s</strong>."
#: models.py:19
#: models.py:20
msgid "account"
msgstr ""
#: models.py:21
#: models.py:22
msgid "method"
msgstr ""
#: models.py:23 models.py:166
#: models.py:24 models.py:169
msgid "data"
msgstr ""
#: models.py:24
#: models.py:25
msgid "active"
msgstr ""
#: models.py:91
#: models.py:95
msgid "Waitting processing"
msgstr ""
#: models.py:92
#: models.py:96
msgid "Waitting execution"
msgstr ""
#: models.py:98
#: models.py:102
msgid "bill"
msgstr ""
#: models.py:101
#: models.py:105
msgid "source"
msgstr ""
#: models.py:103
#: models.py:107
msgid "process"
msgstr ""
#: models.py:104 models.py:168
#: models.py:108 models.py:171
msgid "state"
msgstr ""
#: models.py:106
#: models.py:110
msgid "amount"
msgstr ""
#: models.py:108 models.py:169
#: models.py:112 models.py:172
msgid "created"
msgstr ""
#: models.py:109
#: models.py:113
msgid "modified"
msgstr ""
#: models.py:124
#: models.py:128
msgid "New transactions can not be allocated for this bill."
msgstr ""
#: models.py:160
#: models.py:163 templates/admin/payments/transaction/report.html:63
msgid "Created"
msgstr ""
#: models.py:163
#: models.py:166
msgid "Commited"
msgstr ""
#: models.py:167
#: models.py:170
msgid "file"
msgstr ""
#: models.py:170
#: models.py:173
msgid "updated"
msgstr ""
#: models.py:173
#: models.py:176
msgid "Transaction processes"
msgstr ""
#: settings.py:12
#, fuzzy, python-format
#| msgid ""
#| "This bill will be automatically charged to your bank account with IBAN "
#| "number<br><strong>%s</strong>."
msgid ""
"<strong>Direct debit</strong>, this bill will be automatically charged to "
"your bank account with IBAN number<br><strong>%(number)s</strong>."
msgstr ""
"<strong>Adeudo por domiciliación</strong>, esta factura se cobrará "
"automaticamente en tu cuenta bancaria con IBAN <br><strong>%s</strong>."
#: templates/admin/payments/transaction/report.html:38
msgid "Summary"
msgstr ""
#: templates/admin/payments/transaction/report.html:39
#: templates/admin/payments/transaction/report.html:61
msgid "Amount"
msgstr ""
#: templates/admin/payments/transaction/report.html:48
msgid "TOTAL"
msgstr ""
#: templates/admin/payments/transaction/report.html:57
msgid "Bill"
msgstr ""
#: templates/admin/payments/transaction/report.html:58
msgid "Account"
msgstr ""
#: templates/admin/payments/transaction/report.html:59
msgid "Contact"
msgstr ""
#: templates/admin/payments/transaction/report.html:62
msgid "State"
msgstr ""
#: templates/admin/payments/transaction/report.html:64
msgid "Updated"
msgstr ""

View file

@ -19,14 +19,14 @@ from .options import PaymentMethod
class SEPADirectDebitForm(PluginDataForm):
iban = forms.CharField(label='IBAN',
widget=forms.TextInput(attrs={'size': '50'}))
widget=forms.TextInput(attrs={'size': '50'}))
name = forms.CharField(max_length=128, label=_("Name"),
widget=forms.TextInput(attrs={'size': '50'}))
widget=forms.TextInput(attrs={'size': '50'}))
class SEPADirectDebitSerializer(serializers.Serializer):
iban = serializers.CharField(label='IBAN', validators=[IBANValidator()],
min_length=min(IBAN_COUNTRY_CODE_LENGTH.values()), max_length=34)
min_length=min(IBAN_COUNTRY_CODE_LENGTH.values()), max_length=34)
name = serializers.CharField(label=_("Name"), max_length=128)
def validate(self, data):
@ -45,8 +45,10 @@ class SEPADirectDebit(PaymentMethod):
due_delta = datetime.timedelta(days=5)
def get_bill_message(self):
return _("This bill will be automatically charged to your bank account "
" with IBAN number<br><strong>%s</strong>.") % self.instance.number
context = {
'number': self.instance.number
}
return settings.PAYMENTS_DD_BILL_MESSAGE % context
@classmethod
def process(cls, transactions):

View file

@ -8,6 +8,11 @@ PAYMENT_CURRENCY = Setting('PAYMENT_CURRENCY',
)
PAYMENTS_DD_BILL_MESSAGE = Setting('PAYMENTS_DD_BILL_MESSAGE',
_("<strong>Direct debit</strong>, this bill will be automatically charged "
"to your bank account with IBAN number<br><strong>%(number)s</strong>."),
)
PAYMENTS_DD_CREDITOR_NAME = Setting('PAYMENTS_DD_CREDITOR_NAME',
'Orchestra'
)