Fixed random bugs

This commit is contained in:
Marc Aymerich 2016-04-27 08:35:13 +00:00
parent 682a8947d3
commit c201b6f03d
10 changed files with 52 additions and 24 deletions

View File

@ -35,7 +35,7 @@ def create_account_creation_form():
initial=True, required=False, label=label, help_text=help_text) initial=True, required=False, label=label, help_text=help_text)
create_related.append((model, key, kwargs, help_text)) create_related.append((model, key, kwargs, help_text))
def clean(self): def clean(self, create_related=create_related):
""" unique usernames between accounts and system users """ """ unique usernames between accounts and system users """
cleaned_data = UserCreationForm.clean(self) cleaned_data = UserCreationForm.clean(self)
try: try:
@ -51,7 +51,6 @@ def create_account_creation_form():
if systemuser_model.objects.filter(username=account.username).exists(): if systemuser_model.objects.filter(username=account.username).exists():
errors['username'] = _("A system user with this name already exists.") errors['username'] = _("A system user with this name already exists.")
for model, key, related_kwargs, __ in create_related: for model, key, related_kwargs, __ in create_related:
model = apps.get_model(model)
kwargs = { kwargs = {
key: eval(related_kwargs[key], {'account': account}) key: eval(related_kwargs[key], {'account': account})
} }

View File

@ -287,6 +287,7 @@ def amend_bills(modeladmin, request, queryset):
tax=tax tax=tax
) )
amend_ids.append(amend.pk) amend_ids.append(amend.pk)
modeladmin.log_change(request, bill, 'Amended, amend id is %i' % amend.id)
num = len(amend_ids) num = len(amend_ids)
if num == 1: if num == 1:
amend_url = reverse('admin:bills_bill_change', args=amend_ids) amend_url = reverse('admin:bills_bill_change', args=amend_ids)

View File

@ -441,15 +441,15 @@ class BillLine(models.Model):
def get_verbose_period(self): def get_verbose_period(self):
from django.template.defaultfilters import date from django.template.defaultfilters import date
date_format = "N 'y" date_format = "N 'y"
if self.start_on.day != 1 or self.end_on.day != 1: if self.start_on.day != 1 or (self.end_on and self.end_on.day != 1):
date_format = "N j, 'y" date_format = "N j, 'y"
end = date(self.end_on, date_format) end = date(self.end_on, date_format)
else: elif self.end_on:
end = date((self.end_on - datetime.timedelta(days=1)), date_format) end = date((self.end_on - datetime.timedelta(days=1)), date_format)
ini = date(self.start_on, date_format).capitalize() ini = date(self.start_on, date_format).capitalize()
end = end.capitalize()
if not self.end_on: if not self.end_on:
return ini return ini
end = end.capitalize()
if ini == end: if ini == end:
return ini return ini
return "{ini} / {end}".format(ini=ini, end=end) return "{ini} / {end}".format(ini=ini, end=end)

View File

@ -1,5 +1,6 @@
from django.contrib import admin from django.contrib import admin
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db import models
from django.db.models.functions import Concat, Coalesce from django.db.models.functions import Concat, Coalesce
from django.templatetags.static import static from django.templatetags.static import static
from django.utils.translation import ugettext, ugettext_lazy as _ from django.utils.translation import ugettext, ugettext_lazy as _
@ -51,11 +52,13 @@ class DomainInline(admin.TabularInline):
class DomainAdmin(AccountAdminMixin, ExtendedModelAdmin): class DomainAdmin(AccountAdminMixin, ExtendedModelAdmin):
list_display = ( list_display = (
'structured_name', 'display_is_top', 'display_websites', 'account_link' 'structured_name', 'display_is_top', 'display_websites', 'display_addresses', 'account_link'
) )
add_fields = ('name', 'account') add_fields = ('name', 'account')
fields = ('name', 'account_link', 'display_websites') fields = ('name', 'account_link', 'display_websites', 'display_addresses')
readonly_fields = ('account_link', 'top_link', 'display_websites', 'implicit_records') readonly_fields = (
'account_link', 'top_link', 'display_websites', 'display_addresses', 'implicit_records'
)
inlines = (RecordInline, DomainInline) inlines = (RecordInline, DomainInline)
list_filter = (TopDomainListFilter, HasWebsiteFilter, HasAddressFilter) list_filter = (TopDomainListFilter, HasWebsiteFilter, HasAddressFilter)
change_readonly_fields = ('name', 'serial') change_readonly_fields = ('name', 'serial')
@ -100,10 +103,31 @@ class DomainAdmin(AccountAdminMixin, ExtendedModelAdmin):
add_url, _("Add website"), image add_url, _("Add website"), image
) )
return _("No website %s") % (add_link) return _("No website %s") % (add_link)
return '---'
display_websites.admin_order_field = 'websites__name' display_websites.admin_order_field = 'websites__name'
display_websites.short_description = _("Websites") display_websites.short_description = _("Websites")
display_websites.allow_tags = True display_websites.allow_tags = True
def display_addresses(self, domain):
if apps.isinstalled('orchestra.contrib.mailboxes'):
add_url = reverse('admin:mailboxes_address_add')
add_url += '?account=%i&domain=%i' % (domain.account_id, domain.pk)
image = '<img src="%s"></img>' % static('orchestra/images/add.png')
add_link = '<a href="%s" title="%s">%s</a>' % (
add_url, _("Add address"), image
)
addresses = domain.addresses.all()
if addresses:
url = reverse('admin:mailboxes_address_changelist')
url += '?domain=%i' % addresses[0].domain_id
title = '\n'.join([address.email for address in addresses])
return '<a href="%s" title="%s">%s</a> %s' % (url, title, len(addresses), add_link)
return _("No address %s") % (add_link)
return '---'
display_addresses.short_description = _("Addresses")
display_addresses.admin_order_field = 'addresses__count'
display_addresses.allow_tags = True
def implicit_records(self, domain): def implicit_records(self, domain):
defaults = [] defaults = []
types = set(domain.records.values_list('type', flat=True)) types = set(domain.records.values_list('type', flat=True))
@ -169,6 +193,8 @@ class DomainAdmin(AccountAdminMixin, ExtendedModelAdmin):
).order_by('-structured_id', 'structured_name') ).order_by('-structured_id', 'structured_name')
if apps.isinstalled('orchestra.contrib.websites'): if apps.isinstalled('orchestra.contrib.websites'):
qs = qs.prefetch_related('websites__domains') qs = qs.prefetch_related('websites__domains')
if apps.isinstalled('orchestra.contrib.mailboxes'):
qs = qs.annotate(models.Count('addresses'))
return qs return qs
def save_model(self, request, obj, form, change): def save_model(self, request, obj, form, change):

View File

@ -65,11 +65,13 @@ class Ticket(models.Model):
) )
creator = models.ForeignKey(djsettings.AUTH_USER_MODEL, verbose_name=_("created by"), creator = models.ForeignKey(djsettings.AUTH_USER_MODEL, verbose_name=_("created by"),
related_name='tickets_created', null=True) related_name='tickets_created', null=True, on_delete=models.SET_NULL)
creator_name = models.CharField(_("creator name"), max_length=256, blank=True) creator_name = models.CharField(_("creator name"), max_length=256, blank=True)
owner = models.ForeignKey(djsettings.AUTH_USER_MODEL, null=True, blank=True, owner = models.ForeignKey(djsettings.AUTH_USER_MODEL, null=True, blank=True,
on_delete=models.SET_NULL,
related_name='tickets_owned', verbose_name=_("assigned to")) related_name='tickets_owned', verbose_name=_("assigned to"))
queue = models.ForeignKey(Queue, related_name='tickets', null=True, blank=True) queue = models.ForeignKey(Queue, related_name='tickets', null=True, blank=True,
on_delete=models.SET_NULL)
subject = models.CharField(_("subject"), max_length=256) subject = models.CharField(_("subject"), max_length=256)
description = models.TextField(_("description")) description = models.TextField(_("description"))
priority = models.CharField(_("priority"), max_length=32, choices=PRIORITIES, default=MEDIUM) priority = models.CharField(_("priority"), max_length=32, choices=PRIORITIES, default=MEDIUM)

View File

@ -134,7 +134,7 @@ class MailmanController(MailmanVirtualDomainController):
echo "${aliases}" >> %(virtual_alias)s echo "${aliases}" >> %(virtual_alias)s
UPDATED_VIRTUAL_ALIAS=1 UPDATED_VIRTUAL_ALIAS=1
else else
existing=$(grep -E '^\s*(%(address_name)s|%(name)s)@%(address_domain)s\s\s*%(name)s\s*$' %(virtual_alias)s|wc -l) existing=$({ grep -E '^\s*(%(address_name)s|%(name)s)@%(address_domain)s\s\s*%(name)s\s*$' %(virtual_alias)s || test $? -lt 2; }|wc -l)
if [[ $existing -ne %(num_entries)s ]]; then if [[ $existing -ne %(num_entries)s ]]; then
sed -i -e '/^.*\s%(name)s\(%(suffixes_regex)s\)\s*$/d' \\ sed -i -e '/^.*\s%(name)s\(%(suffixes_regex)s\)\s*$/d' \\
-e 'N; /^\s*\\n\s*$/d; P; D' %(virtual_alias)s -e 'N; /^\s*\\n\s*$/d; P; D' %(virtual_alias)s

View File

@ -111,7 +111,7 @@ class Transaction(models.Model):
bill = models.ForeignKey('bills.bill', verbose_name=_("bill"), bill = models.ForeignKey('bills.bill', verbose_name=_("bill"),
related_name='transactions') related_name='transactions')
source = models.ForeignKey(PaymentSource, null=True, blank=True, source = models.ForeignKey(PaymentSource, null=True, blank=True, on_delete=models.SET_NULL,
verbose_name=_("source"), related_name='transactions') verbose_name=_("source"), related_name='transactions')
process = models.ForeignKey('payments.TransactionProcess', null=True, blank=True, process = models.ForeignKey('payments.TransactionProcess', null=True, blank=True,
on_delete=models.SET_NULL, verbose_name=_("process"), related_name='transactions') on_delete=models.SET_NULL, verbose_name=_("process"), related_name='transactions')

View File

@ -63,7 +63,7 @@ class Resource(models.Model):
disable_trigger = models.BooleanField(_("disable trigger"), default=True, disable_trigger = models.BooleanField(_("disable trigger"), default=True,
help_text=_("Disables monitors exeeded and recovery triggers")) help_text=_("Disables monitors exeeded and recovery triggers"))
crontab = models.ForeignKey('djcelery.CrontabSchedule', verbose_name=_("crontab"), crontab = models.ForeignKey('djcelery.CrontabSchedule', verbose_name=_("crontab"),
null=True, blank=True, null=True, blank=True, on_delete=models.SET_NULL,
help_text=_("Crontab for periodic execution. " help_text=_("Crontab for periodic execution. "
"Leave it empty to disable periodic monitoring")) "Leave it empty to disable periodic monitoring"))
monitors = fields.MultiSelectField(_("monitors"), max_length=256, blank=True, monitors = fields.MultiSelectField(_("monitors"), max_length=256, blank=True,

View File

@ -156,7 +156,7 @@ class PHPController(WebAppServiceMixin, ServiceController):
fi fi
counter=$(($counter+1)) counter=$(($counter+1))
done done
state="$(grep -v "$BACKEND" /dev/shm/reload.apache2.locked)" || is_last=1 state="$(grep -v -E "^$BACKEND($|\s)" /dev/shm/reload.apache2.locked)" || is_last=1
[[ $is_last -eq 0 ]] && { [[ $is_last -eq 0 ]] && {
echo "$state" | grep -v ' RELOAD$' || is_last=1 echo "$state" | grep -v ' RELOAD$' || is_last=1
} }
@ -171,7 +171,7 @@ class PHPController(WebAppServiceMixin, ServiceController):
fi fi
rm /dev/shm/reload.apache2.locked rm /dev/shm/reload.apache2.locked
else else
echo -n "$state" > /dev/shm/reload.apache2.locked echo "$state" > /dev/shm/reload.apache2.locked
if [[ $UPDATED_APACHE -eq 1 ]]; then if [[ $UPDATED_APACHE -eq 1 ]]; then
echo -e "[DEBUG]: Apache will be reloaded by another backend:\\n${state}" echo -e "[DEBUG]: Apache will be reloaded by another backend:\\n${state}"
echo "$BACKEND RELOAD" >> /dev/shm/reload.apache2.locked echo "$BACKEND RELOAD" >> /dev/shm/reload.apache2.locked

View File

@ -160,7 +160,7 @@ class Apache2Controller(ServiceController):
counter=$(($counter+1)) counter=$(($counter+1))
sleep 0.1; sleep 0.1;
done done
state="$(grep -v "$BACKEND" /dev/shm/reload.apache2.locked)" || is_last=1 state="$(grep -v -E "^$BACKEND($|\s)" /dev/shm/reload.apache2.locked)" || is_last=1
[[ $is_last -eq 0 ]] && { [[ $is_last -eq 0 ]] && {
echo "$state" | grep -v ' RELOAD$' || is_last=1 echo "$state" | grep -v ' RELOAD$' || is_last=1
} }
@ -175,7 +175,7 @@ class Apache2Controller(ServiceController):
fi fi
rm /dev/shm/reload.apache2.locked rm /dev/shm/reload.apache2.locked
else else
echo -n "$state" > /dev/shm/reload.apache2.locked echo "$state" > /dev/shm/reload.apache2.locked
if [[ $UPDATED_APACHE -eq 1 ]]; then if [[ $UPDATED_APACHE -eq 1 ]]; then
echo -e "[DEBUG]: Apache will be reloaded by another backend:\\n${state}" echo -e "[DEBUG]: Apache will be reloaded by another backend:\\n${state}"
echo "$BACKEND RELOAD" >> /dev/shm/reload.apache2.locked echo "$BACKEND RELOAD" >> /dev/shm/reload.apache2.locked