Random fixes
This commit is contained in:
parent
2490ff83c8
commit
1265881fbf
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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")),
|
||||
)
|
||||
|
||||
|
|
|
@ -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}: <a href="{1}">{2}</a> <i>{3}</i>',
|
||||
capfirst(opts.verbose_name), change_url(bill), bill, emails)
|
||||
)
|
||||
return {
|
||||
'display_objects': bills
|
||||
}
|
||||
|
|
|
@ -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')
|
||||
]
|
||||
|
|
|
@ -11,8 +11,9 @@
|
|||
<p>
|
||||
{% 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 %}
|
||||
{% elif can_raw %}
|
||||
{% 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 %}
|
||||
{% else %}
|
||||
{% 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 %}
|
||||
</p>
|
||||
|
||||
|
|
Loading…
Reference in a new issue