Random fixes

This commit is contained in:
Marc Aymerich 2016-05-20 08:29:25 +00:00
parent 2490ff83c8
commit 1265881fbf
7 changed files with 40 additions and 14 deletions

View File

@ -173,7 +173,7 @@ class AdminPasswordChangeForm(forms.Form):
for ix, rel in enumerate(self.related): for ix, rel in enumerate(self.related):
password = self.cleaned_data['%s_%s' % (field_name, ix)] password = self.cleaned_data['%s_%s' % (field_name, ix)]
if password: if password:
if raw: if self.raw:
rel.password = password rel.password = password
else: else:
set_password = getattr(rel, 'set_password') set_password = getattr(rel, 'set_password')

View File

@ -104,18 +104,23 @@ class Account(auth.AbstractBaseUser):
signals.post_save.send(sender=type(obj), instance=obj) signals.post_save.send(sender=type(obj), instance=obj)
# OperationsMiddleware.collect(Operation.SAVE, instance=obj, update_fields=()) # OperationsMiddleware.collect(Operation.SAVE, instance=obj, update_fields=())
def send_email(self, template, context, email_from=None, contacts=[], attachments=[], html=None): def get_contacts_emails(self, usages=None):
contacts = self.contacts.filter(email_usages=contacts) contacts = self.contacts.all()
email_to = contacts.values_list('email', flat=True) 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 = { extra_context = {
'account': self, 'account': self,
'email_from': email_from or djsettings.SERVER_EMAIL, 'email_from': email_from or djsettings.SERVER_EMAIL,
} }
extra_context.update(context) extra_context.update(context)
with translation.override(self.language): with translation.override(self.language):
send_email_template( send_email_template(template, extra_context, email_to, email_from=email_from,
template, extra_context, email_to, email_from=email_from, html=html, html=html, attachments=attachments)
attachments=attachments)
def get_full_name(self): def get_full_name(self):
return self.full_name or self.short_name or self.username return self.full_name or self.short_name or self.username

View File

@ -20,7 +20,7 @@ from orchestra.admin.utils import get_object_from_url, change_url
from . import settings from . import settings
from .forms import SelectSourceForm from .forms import SelectSourceForm
from .helpers import validate_contact from .helpers import validate_contact, set_context_emails
from .models import Bill, BillLine from .models import Bill, BillLine
@ -117,7 +117,7 @@ def send_bills_action(modeladmin, request, queryset):
num)) num))
@action_with_confirmation() @action_with_confirmation(extra_context=set_context_emails)
def send_bills(modeladmin, request, queryset): def send_bills(modeladmin, request, queryset):
return send_bills_action(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") send_bills.verbose_name = lambda bill: _("Resend" if getattr(bill, 'is_sent', False) else "Send")

View File

@ -140,9 +140,9 @@ class AmendedListFilter(SimpleListFilter):
def lookups(self, request, model_admin): def lookups(self, request, model_admin):
return ( return (
('1', _("Amended")),
('2', _("Open amends")),
('3', _("Closed amends")), ('3', _("Closed amends")),
('2', _("Open amends")),
('1', _("Any amends")),
('0', _("No amends")), ('0', _("No amends")),
) )

View File

@ -1,9 +1,13 @@
from django.contrib import messages from django.contrib import messages
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils.encoding import force_text from django.utils.encoding import force_text
from django.utils.html import format_html
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.text import capfirst
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from orchestra.admin.utils import change_url
def validate_contact(request, bill, error=True): def validate_contact(request, bill, error=True):
""" checks if all the preconditions for bill generation are met """ """ 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)) send(request, mark_safe(message))
valid = False valid = False
return valid 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}: <a href="{1}">{2}</a> <i>{3}</i>',
capfirst(opts.verbose_name), change_url(bill), bill, emails)
)
return {
'display_objects': bills
}

View File

@ -277,6 +277,9 @@ class Bill(models.Model):
self.save() self.save()
return transaction return transaction
def get_billing_contact_emails(self):
return self.account.get_contacts_emails(usages=(Contact.BILLING,))
def send(self): def send(self):
pdf = self.as_pdf() pdf = self.as_pdf()
self.account.send_email( self.account.send_email(
@ -286,7 +289,7 @@ class Bill(models.Model):
'settings': settings, 'settings': settings,
}, },
email_from=settings.BILLS_SELLER_EMAIL, email_from=settings.BILLS_SELLER_EMAIL,
contacts=(Contact.BILLING,), usages=(Contact.BILLING,),
attachments=[ attachments=[
('%s.pdf' % self.number, pdf, 'application/pdf') ('%s.pdf' % self.number, pdf, 'application/pdf')
] ]

View File

@ -11,8 +11,9 @@
<p> <p>
{% if raw %} {% if raw %}
{% blocktrans with username=obj_username %}Enter a new password hash for user <strong>{{ username }}</strong>. Switch to <a href="./?raw=0">text password form</a>.{% endblocktrans %} {% blocktrans with username=obj_username %}Enter a new password hash for user <strong>{{ username }}</strong>. Switch to <a href="./?raw=0">text password form</a>.{% endblocktrans %}
{% elif can_raw %} {% else %}
{% blocktrans with username=obj_username %}Enter a new password for user <strong>{{ username }}</strong>, suggestion '{{ password }}'. Switch to <a href="./?raw=1">raw password form</a>.{% endblocktrans %} {% blocktrans with username=obj_username %}Enter a new password for user <strong>{{ username }}</strong>, suggestion '{{ password }}'.{% endblocktrans %}
{% if can_raw %}{% blocktrans %}Switch to <a href="./?raw=1">raw password form</a>.{% endblocktrans %}{% endif %}
{% endif %} {% endif %}
</p> </p>