diff --git a/orchestra/admin/forms.py b/orchestra/admin/forms.py index 90fa72e9..efb6db3c 100644 --- a/orchestra/admin/forms.py +++ b/orchestra/admin/forms.py @@ -173,7 +173,7 @@ class AdminPasswordChangeForm(forms.Form): for ix, rel in enumerate(self.related): password = self.cleaned_data['%s_%s' % (field_name, ix)] if password: - if raw: + if self.raw: rel.password = password else: set_password = getattr(rel, 'set_password') diff --git a/orchestra/contrib/accounts/models.py b/orchestra/contrib/accounts/models.py index 1272becf..1fd8484d 100644 --- a/orchestra/contrib/accounts/models.py +++ b/orchestra/contrib/accounts/models.py @@ -104,18 +104,23 @@ class Account(auth.AbstractBaseUser): signals.post_save.send(sender=type(obj), instance=obj) # OperationsMiddleware.collect(Operation.SAVE, instance=obj, update_fields=()) - def send_email(self, template, context, email_from=None, contacts=[], attachments=[], html=None): - contacts = self.contacts.filter(email_usages=contacts) - email_to = contacts.values_list('email', flat=True) + def get_contacts_emails(self, usages=None): + contacts = self.contacts.all() + if usages is not None: + contactes = contacts.filter(email_usages=usages) + return contacts.values_list('email', flat=True) + + def send_email(self, template, context, email_from=None, usages=None, attachments=[], html=None): + contacts = self.contacts.filter(email_usages=usages) + email_to = self.get_contacts_emails(usages) extra_context = { 'account': self, 'email_from': email_from or djsettings.SERVER_EMAIL, } extra_context.update(context) with translation.override(self.language): - send_email_template( - template, extra_context, email_to, email_from=email_from, html=html, - attachments=attachments) + send_email_template(template, extra_context, email_to, email_from=email_from, + html=html, attachments=attachments) def get_full_name(self): return self.full_name or self.short_name or self.username diff --git a/orchestra/contrib/bills/actions.py b/orchestra/contrib/bills/actions.py index 058d66fa..dc36938b 100644 --- a/orchestra/contrib/bills/actions.py +++ b/orchestra/contrib/bills/actions.py @@ -20,7 +20,7 @@ from orchestra.admin.utils import get_object_from_url, change_url from . import settings from .forms import SelectSourceForm -from .helpers import validate_contact +from .helpers import validate_contact, set_context_emails from .models import Bill, BillLine @@ -117,7 +117,7 @@ def send_bills_action(modeladmin, request, queryset): num)) -@action_with_confirmation() +@action_with_confirmation(extra_context=set_context_emails) def send_bills(modeladmin, request, queryset): return send_bills_action(modeladmin, request, queryset) send_bills.verbose_name = lambda bill: _("Resend" if getattr(bill, 'is_sent', False) else "Send") diff --git a/orchestra/contrib/bills/filters.py b/orchestra/contrib/bills/filters.py index 27a4b239..de45ca37 100644 --- a/orchestra/contrib/bills/filters.py +++ b/orchestra/contrib/bills/filters.py @@ -140,9 +140,9 @@ class AmendedListFilter(SimpleListFilter): def lookups(self, request, model_admin): return ( - ('1', _("Amended")), - ('2', _("Open amends")), ('3', _("Closed amends")), + ('2', _("Open amends")), + ('1', _("Any amends")), ('0', _("No amends")), ) diff --git a/orchestra/contrib/bills/helpers.py b/orchestra/contrib/bills/helpers.py index f503b3b7..99fc3319 100644 --- a/orchestra/contrib/bills/helpers.py +++ b/orchestra/contrib/bills/helpers.py @@ -1,9 +1,13 @@ from django.contrib import messages from django.core.urlresolvers import reverse from django.utils.encoding import force_text +from django.utils.html import format_html from django.utils.safestring import mark_safe +from django.utils.text import capfirst from django.utils.translation import ugettext_lazy as _ +from orchestra.admin.utils import change_url + def validate_contact(request, bill, error=True): """ checks if all the preconditions for bill generation are met """ @@ -25,3 +29,16 @@ def validate_contact(request, bill, error=True): send(request, mark_safe(message)) valid = False return valid + + +def set_context_emails(modeladmin, request, queryset): + opts = modeladmin.model._meta + bills = [] + for bill in queryset: + emails = ', '.join(bill.get_billing_contact_emails()) + bills.append(format_html('{0}: {2} {3}', + capfirst(opts.verbose_name), change_url(bill), bill, emails) + ) + return { + 'display_objects': bills + } diff --git a/orchestra/contrib/bills/models.py b/orchestra/contrib/bills/models.py index 5a6453ed..5e2896a0 100644 --- a/orchestra/contrib/bills/models.py +++ b/orchestra/contrib/bills/models.py @@ -277,6 +277,9 @@ class Bill(models.Model): self.save() return transaction + def get_billing_contact_emails(self): + return self.account.get_contacts_emails(usages=(Contact.BILLING,)) + def send(self): pdf = self.as_pdf() self.account.send_email( @@ -286,7 +289,7 @@ class Bill(models.Model): 'settings': settings, }, email_from=settings.BILLS_SELLER_EMAIL, - contacts=(Contact.BILLING,), + usages=(Contact.BILLING,), attachments=[ ('%s.pdf' % self.number, pdf, 'application/pdf') ] diff --git a/orchestra/templates/admin/orchestra/change_password.html b/orchestra/templates/admin/orchestra/change_password.html index bc18e4a6..9339aa00 100644 --- a/orchestra/templates/admin/orchestra/change_password.html +++ b/orchestra/templates/admin/orchestra/change_password.html @@ -11,8 +11,9 @@

{% if raw %} {% blocktrans with username=obj_username %}Enter a new password hash for user {{ username }}. Switch to text password form.{% endblocktrans %} -{% elif can_raw %} -{% blocktrans with username=obj_username %}Enter a new password for user {{ username }}, suggestion '{{ password }}'. Switch to raw password form.{% endblocktrans %} +{% else %} +{% blocktrans with username=obj_username %}Enter a new password for user {{ username }}, suggestion '{{ password }}'.{% endblocktrans %} +{% if can_raw %}{% blocktrans %}Switch to raw password form.{% endblocktrans %}{% endif %} {% endif %}