From e962e5d7b235c0fcbb9740bd6346bcd7bb05e6dc Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Fri, 21 Nov 2014 17:18:59 +0000 Subject: [PATCH] Added account report --- TODO.md | 31 ++--------- orchestra/apps/accounts/actions.py | 20 ++++++- orchestra/apps/accounts/admin.py | 6 +-- .../accounts/account/service_report.html | 54 +++++++++++++++++++ orchestra/apps/contacts/forms.py | 2 + orchestra/bin/orchestra-admin | 1 + orchestra/templatetags/utils.py | 5 ++ 7 files changed, 87 insertions(+), 32 deletions(-) create mode 100644 orchestra/apps/accounts/templates/admin/accounts/account/service_report.html diff --git a/TODO.md b/TODO.md index d53b4e8f..df7df2d0 100644 --- a/TODO.md +++ b/TODO.md @@ -14,35 +14,17 @@ * use Code: https://github.com/django/django/blob/master/django/forms/forms.py#L415 for domain.refresh_serial() * Permissions .filter_queryset() -* git deploy in addition to FTP? * env vars instead of multiple settings files: https://devcenter.heroku.com/articles/config-vars ? -* optional chroot shell? - -* make sure prefetch_related() is used correctly -Remember that, as always with QuerySets, any subsequent chained methods which imply a different database query will ignore previously cached results, and retrieve data using a fresh database query. -* profile select_related vs prefetch_related - * Log changes from rest api (serialized objects) -* passlib; nano /usr/local/lib/python2.7/dist-packages/passlib/ext/django/utils.py SortedDict -> collections.OrderedDict -* pip install pyinotify - -* Timezone awareness on monitoring system (reading server-side logs with different TZ than orchestra) maybe a settings value? (use UTC internally, timezone.localtime() when interacting with servers) * EMAIL backend operations which contain stderr messages (because under certain failures status code is still 0) * Settings dictionary like DRF2 in order to better override large settings like WEBSITES_APPLICATIONS.etc -* DOCUMENT: orchestration.middleware: we need to know when an operation starts and ends in order to perform bulk server updates and also to wait for related objects to be saved (base object is saved first and then related) - orders.signales: we perform changes right away because data model state can change under monitoring and other periodik task, and we should keep orders consistency under any situation. - dependency collector with max_recursion that matches the number of dots on service.match and service.metric - - * backend logs with hal logo -* Use logs for storing monitored values * set_password orchestration method? - * make account_link to autoreplace account on change view. * LAST version of this shit http://wkhtmltopdf.org/downloads.html @@ -50,12 +32,9 @@ Remember that, as always with QuerySets, any subsequent chained methods which im * translations from django.utils import translation with translation.override('en'): -* Plurals! * help_text on readonly_fields specialy Bill.state. (eg. A bill is in OPEN state when bla bla ) -* underescore *every* private function - * create log file at /var/log/orchestra.log and rotate * order.register_at @@ -71,7 +50,7 @@ Remember that, as always with QuerySets, any subsequent chained methods which im * move icons to apps, and use appconfig to cleanup config stuff -* when using modeladmin to store shit like self.account, make sure to have a cleanslate in each request +* when using modeladmin to store shit like self.account, make sure to have a cleanslate in each request? * jabber with mailbox accounts (dovecto mail notification) @@ -114,10 +93,8 @@ Remember that, as always with QuerySets, any subsequent chained methods which im * ignore_fields = () * based on a merge set of save(update_fields) -* textwrap.dedent( \\) * parmiko write to a channel instead of transfering files? http://sysadmin.circularvale.com/programming/paramiko-channel-hangs/ - * proforma without billing contact? * env ORCHESTRA_MASTER_SERVER='test1.orchestra.lan' ORCHESTRA_SECOND_SERVER='test2.orchestra.lan' ORCHESTRA_SLAVE_SERVER='test3.orchestra.lan' python manage.py test orchestra.apps.domains.tests.functional_tests.tests:AdminBind9BackendDomainTest @@ -140,12 +117,8 @@ Remember that, as always with QuerySets, any subsequent chained methods which im * consider removing mailbox support on forward (user@pangea.org instead) -* remove ordering in account admin and others admininlines - * Databases.User add reverse M2M databases widget (like mailbox.addresses) -* Change (correct) permissions periodically on the web server, to ensure security ? - * Root owned logs on user's home ? yes * reconsider binding webapps to systemusers (pangea multiple users wordpress-ftp, moodle-pangea, etc) @@ -191,3 +164,5 @@ Remember that, as always with QuerySets, any subsequent chained methods which im * Fix ftp traffic * Resource graph for each related object + +* contacts filter by email_usage fix exact for contains diff --git a/orchestra/apps/accounts/actions.py b/orchestra/apps/accounts/actions.py index 037e1c66..57d9856a 100644 --- a/orchestra/apps/accounts/actions.py +++ b/orchestra/apps/accounts/actions.py @@ -1,10 +1,12 @@ from django.contrib import messages from django.core.urlresolvers import reverse from django.db import transaction -from django.shortcuts import redirect +from django.shortcuts import redirect, render +from django.utils import timezone from django.utils.translation import ungettext, ugettext_lazy as _ from orchestra.admin.decorators import action_with_confirmation +from orchestra.core import services @transaction.atomic @@ -33,3 +35,19 @@ def list_contacts(modeladmin, request, queryset): url += '?account__in=%s' % ','.join(map(str, ids)) return redirect(url) list_contacts.verbose_name = _("List contacts") + + +def service_report(modeladmin, request, queryset): + accounts = [] + for account in queryset: + items = [] + for service in services.get(): + if service != type(account): + items.append((service._meta, service.objects.filter(account=account))) + sorted(items, key=lambda i: i[0].verbose_name_plural.lower()) + accounts.append((account, items)) + context = { + 'accounts': accounts, + 'date': timezone.now().today() + } + return render(request, 'admin/accounts/account/service_report.html', context) diff --git a/orchestra/apps/accounts/admin.py b/orchestra/apps/accounts/admin.py index b4e7c196..4b126704 100644 --- a/orchestra/apps/accounts/admin.py +++ b/orchestra/apps/accounts/admin.py @@ -18,7 +18,7 @@ from orchestra.core import services, accounts from orchestra.forms import UserChangeForm from . import settings -from .actions import disable, list_contacts +from .actions import disable, list_contacts, service_report from .filters import HasMainUserListFilter from .forms import AccountCreationForm from .models import Account @@ -61,8 +61,8 @@ class AccountAdmin(ChangePasswordAdminMixin, auth.UserAdmin, ExtendedModelAdmin) filter_horizontal = () change_readonly_fields = ('username', 'main_systemuser_link') change_form_template = 'admin/accounts/account/change_form.html' - actions = [disable, list_contacts] - change_view_actions = [disable] + actions = [disable, list_contacts, service_report] + change_view_actions = [disable, service_report] list_select_related = ('billcontact',) ordering = () diff --git a/orchestra/apps/accounts/templates/admin/accounts/account/service_report.html b/orchestra/apps/accounts/templates/admin/accounts/account/service_report.html new file mode 100644 index 00000000..d59fac6a --- /dev/null +++ b/orchestra/apps/accounts/templates/admin/accounts/account/service_report.html @@ -0,0 +1,54 @@ +{% load utils %} + + + {% block title %}Service Report{% endblock %} + + {% block head %}{% endblock %} + + + + +
Service report generated on {{ date | date }}
+{% for account, items in accounts %} +

{{ account.get_full_name }} ({{ account.username }})

+
+
+ {{ account.get_type_display }} account registered on {{ account.date_joined | date }}
+ +
+{% endfor %} + + diff --git a/orchestra/apps/contacts/forms.py b/orchestra/apps/contacts/forms.py index fecf1a1e..591c1b2a 100644 --- a/orchestra/apps/contacts/forms.py +++ b/orchestra/apps/contacts/forms.py @@ -2,6 +2,8 @@ from django import forms from django.core import validators from django.utils.translation import ungettext, ugettext_lazy as _ +from orchestra.forms.widgets import ShowTextWidget + from . import settings diff --git a/orchestra/bin/orchestra-admin b/orchestra/bin/orchestra-admin index eccf6b9e..32230bfa 100755 --- a/orchestra/bin/orchestra-admin +++ b/orchestra/bin/orchestra-admin @@ -174,6 +174,7 @@ function install_requirements () { django-debug-toolbar==1.2.1 \ django-nose==1.2 \ sqlparse \ + pyinotify \ --allow-external orchestra-orm --allow-unverified orchestra-orm" fi diff --git a/orchestra/templatetags/utils.py b/orchestra/templatetags/utils.py index 909b1497..44e3c7dc 100644 --- a/orchestra/templatetags/utils.py +++ b/orchestra/templatetags/utils.py @@ -56,3 +56,8 @@ def is_checkbox(field): @register.filter def admin_url(obj): return change_url(obj) + + +@register.filter +def isactive(obj): + return getattr(obj, 'is_active', True)