From 84a83cab07853b83e91c40c440f65b911e3296a5 Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Mon, 29 Apr 2013 07:37:38 -0500 Subject: Reports: Add support for Django 1.5 Signed-off-by: Sol Jerome --- doc/reports/dynamic.txt | 2 +- src/lib/Bcfg2/Reporting/templates/base.html | 29 +++++++++-------- .../Bcfg2/Reporting/templates/clients/detail.html | 28 ++++++++--------- .../Reporting/templates/clients/detailed-list.html | 2 +- .../Bcfg2/Reporting/templates/clients/index.html | 4 +-- .../Bcfg2/Reporting/templates/clients/manage.html | 4 +-- .../Reporting/templates/config_items/common.html | 4 +-- .../templates/config_items/entry_status.html | 10 ++++-- .../Reporting/templates/config_items/item.html | 16 +++++----- .../Reporting/templates/config_items/listing.html | 4 +-- .../Reporting/templates/displays/summary.html | 2 +- .../Bcfg2/Reporting/templates/displays/timing.html | 10 +++--- src/lib/Bcfg2/Reporting/templatetags/bcfg2_tags.py | 36 ++++++++++++---------- .../Reporting/templatetags/syntax_coloring.py | 16 +++++----- src/lib/Bcfg2/settings.py | 3 ++ 15 files changed, 92 insertions(+), 78 deletions(-) diff --git a/doc/reports/dynamic.txt b/doc/reports/dynamic.txt index 9de3f868f..6b8a1f467 100644 --- a/doc/reports/dynamic.txt +++ b/doc/reports/dynamic.txt @@ -39,7 +39,7 @@ Prerequisites * sqlite3 * pysqlite2 (if using python 2.4) -* `Django `_ >= 1.2 +* `Django `_ >= 1.3 * mod-wsgi .. warning:: diff --git a/src/lib/Bcfg2/Reporting/templates/base.html b/src/lib/Bcfg2/Reporting/templates/base.html index c73339911..7f1fcba3b 100644 --- a/src/lib/Bcfg2/Reporting/templates/base.html +++ b/src/lib/Bcfg2/Reporting/templates/base.html @@ -1,4 +1,8 @@ {% load bcfg2_tags %} +{% comment %} +This is needed for Django versions less than 1.5 +{% endcomment %} +{% load url from future %} @@ -25,8 +29,9 @@ + height='115' width='300' alt='Bcfg2' + style='float:left; height: 115px' /> +
@@ -46,26 +51,26 @@
  • Overview
  • {% comment %} TODO diff --git a/src/lib/Bcfg2/Reporting/templates/clients/detail.html b/src/lib/Bcfg2/Reporting/templates/clients/detail.html index 4608ce6f1..9c0299121 100644 --- a/src/lib/Bcfg2/Reporting/templates/clients/detail.html +++ b/src/lib/Bcfg2/Reporting/templates/clients/detail.html @@ -6,19 +6,19 @@ {% block extra_header_info %} {% endblock %} @@ -30,12 +30,12 @@ span.history_links a { {% block content %}

    {{client.name}}

    - [manage] - View History | Jump to  + [manage] + View History | Jump to 
    @@ -110,7 +110,7 @@ span.history_links a { {% for entry in entry_list %} {{entry.entry_type}} - + {{entry.name}} {% endfor %} @@ -129,7 +129,7 @@ span.history_links a { {% for failure in interaction.failures.all %} {{failure.entry_type}} - + {{failure.name}} {% endfor %} @@ -140,11 +140,11 @@ span.history_links a { {% if entry_list %}
    -

    Recent Interactions

    +

    Recent Interactions

    {% include "widgets/interaction_list.inc" %} - +
    {% endif %} diff --git a/src/lib/Bcfg2/Reporting/templates/clients/detailed-list.html b/src/lib/Bcfg2/Reporting/templates/clients/detailed-list.html index fd9a545ce..2a03eede1 100644 --- a/src/lib/Bcfg2/Reporting/templates/clients/detailed-list.html +++ b/src/lib/Bcfg2/Reporting/templates/clients/detailed-list.html @@ -21,7 +21,7 @@ {% for entry in entry_list %} - {{ entry.client.name }} + {{ entry.client.name }} {{ entry.state }} {{ entry.good_count }} diff --git a/src/lib/Bcfg2/Reporting/templates/clients/index.html b/src/lib/Bcfg2/Reporting/templates/clients/index.html index d9c415c20..957cbffd2 100644 --- a/src/lib/Bcfg2/Reporting/templates/clients/index.html +++ b/src/lib/Bcfg2/Reporting/templates/clients/index.html @@ -17,9 +17,9 @@ {{ inter.client.name }} diff --git a/src/lib/Bcfg2/Reporting/templates/clients/manage.html b/src/lib/Bcfg2/Reporting/templates/clients/manage.html index 443ec8ccb..5ba3393b2 100644 --- a/src/lib/Bcfg2/Reporting/templates/clients/manage.html +++ b/src/lib/Bcfg2/Reporting/templates/clients/manage.html @@ -24,10 +24,10 @@ - {{ client.name }} + {{ client.name }} {% firstof client.expiration 'Active' %} -
    +
    {# here for no reason other then to validate #} diff --git a/src/lib/Bcfg2/Reporting/templates/config_items/common.html b/src/lib/Bcfg2/Reporting/templates/config_items/common.html index 57191ec39..0dbd52156 100644 --- a/src/lib/Bcfg2/Reporting/templates/config_items/common.html +++ b/src/lib/Bcfg2/Reporting/templates/config_items/common.html @@ -29,9 +29,9 @@ {% for item in type_list %} {{ item.ENTRY_TYPE }} - {{ item.name }} + {{ item.name }} {{ item.num_entries }} - {{ item.short_list|join:"," }} + {{ item.short_list|join:"," }} {% endfor %} diff --git a/src/lib/Bcfg2/Reporting/templates/config_items/entry_status.html b/src/lib/Bcfg2/Reporting/templates/config_items/entry_status.html index e940889ab..e3befb0eb 100644 --- a/src/lib/Bcfg2/Reporting/templates/config_items/entry_status.html +++ b/src/lib/Bcfg2/Reporting/templates/config_items/entry_status.html @@ -1,5 +1,9 @@ {% extends "base-timeview.html" %} {% load bcfg2_tags %} +{% comment %} +This is needed for Django versions less than 1.5 +{% endcomment %} +{% load url from future %} {% block title %}Bcfg2 - Entry Status{% endblock %} @@ -17,10 +21,10 @@ {% for item, inters in items %} {% for inter in inters %} - {{inter.client.name}} - {{inter.timestamp|date:"Y-m-d\&\n\b\s\p\;H:i"|safe}} + {{inter.client.name}} + {{inter.timestamp|date:"Y-m-d\&\n\b\s\p\;H:i"|safe}} {{ item.get_state_display }} - ({{item.pk}}) {{item.short_list|join:","}} + ({{item.pk}}) {{item.short_list|join:","}} {% endfor %} {% endfor %} diff --git a/src/lib/Bcfg2/Reporting/templates/config_items/item.html b/src/lib/Bcfg2/Reporting/templates/config_items/item.html index 259414399..c15a85e0a 100644 --- a/src/lib/Bcfg2/Reporting/templates/config_items/item.html +++ b/src/lib/Bcfg2/Reporting/templates/config_items/item.html @@ -9,20 +9,20 @@ {% block extra_header_info %} {% endblock%} @@ -131,9 +131,9 @@ div.entry_list h3 { {% if associated_list %} {% for inter in associated_list %} - - {% endfor %} diff --git a/src/lib/Bcfg2/Reporting/templates/config_items/listing.html b/src/lib/Bcfg2/Reporting/templates/config_items/listing.html index 864392754..fb10bb020 100644 --- a/src/lib/Bcfg2/Reporting/templates/config_items/listing.html +++ b/src/lib/Bcfg2/Reporting/templates/config_items/listing.html @@ -21,9 +21,9 @@ {% for entry in type_data %} - + - + {% endfor %}
    {{inter.client.name}}{{inter.timestamp}}
    NameCountReason
    {{entry.name}}{{entry.name}} {{entry.num_entries}}{{entry.short_list|join:","}}{{entry.short_list|join:","}}
    diff --git a/src/lib/Bcfg2/Reporting/templates/displays/summary.html b/src/lib/Bcfg2/Reporting/templates/displays/summary.html index b9847cf96..c432da95d 100644 --- a/src/lib/Bcfg2/Reporting/templates/displays/summary.html +++ b/src/lib/Bcfg2/Reporting/templates/displays/summary.html @@ -30,7 +30,7 @@ hide_tables[{{ forloop.counter0 }}] = "table_{{ summary.name }}"; {% for node in summary.nodes|sort_interactions_by_name %} - + {% endfor %}
    {{ node.client.name }}{{ node.client.name }}
    diff --git a/src/lib/Bcfg2/Reporting/templates/displays/timing.html b/src/lib/Bcfg2/Reporting/templates/displays/timing.html index ff775ded5..57806b63a 100644 --- a/src/lib/Bcfg2/Reporting/templates/displays/timing.html +++ b/src/lib/Bcfg2/Reporting/templates/displays/timing.html @@ -12,7 +12,7 @@
    {% if metrics %} - + @@ -21,15 +21,15 @@ - {% for metric in metrics|dictsort:"name" %} + {% for metric in metrics|dictsort:"name" %} + href='{% url "reports_client_detail" hostname=metric.name %}'>{{ metric.name }} {% for mitem in metric|build_metric_list %} {% endfor %} - - {% endfor %} + + {% endfor %}
    Name Parse ProbeConfig Total
    {{ metric.name }}{{ mitem }}
    {% else %}

    No metric data available

    diff --git a/src/lib/Bcfg2/Reporting/templatetags/bcfg2_tags.py b/src/lib/Bcfg2/Reporting/templatetags/bcfg2_tags.py index f5f2e7528..489682f30 100644 --- a/src/lib/Bcfg2/Reporting/templatetags/bcfg2_tags.py +++ b/src/lib/Bcfg2/Reporting/templatetags/bcfg2_tags.py @@ -5,9 +5,8 @@ from django import template from django.conf import settings from django.core.urlresolvers import resolve, reverse, \ Resolver404, NoReverseMatch -from django.template.loader import get_template, \ - get_template_from_string,TemplateDoesNotExist -from django.utils.encoding import smart_unicode, smart_str +from django.template.loader import get_template_from_string +from django.utils.encoding import smart_str from django.utils.safestring import mark_safe from datetime import datetime, timedelta from Bcfg2.Reporting.utils import filter_list @@ -133,19 +132,22 @@ def filter_navigator(context): del myargs[filter] filters.append((filter, reverse(view, args=args, kwargs=myargs) + qs)) - filters.sort(lambda x, y: cmp(x[0], y[0])) + filters.sort(key=lambda x: x[0]) myargs = kwargs.copy() - selected=True + selected = True if 'group' in myargs: del myargs['group'] - selected=False - groups = [('---', reverse(view, args=args, kwargs=myargs) + qs, selected)] + selected = False + groups = [('---', + reverse(view, args=args, kwargs=myargs) + qs, + selected)] for group in Group.objects.values('name'): myargs['group'] = group['name'] - groups.append((group['name'], reverse(view, args=args, kwargs=myargs) + qs, - group['name'] == kwargs.get('group', ''))) - + groups.append((group['name'], + reverse(view, args=args, kwargs=myargs) + qs, + group['name'] == kwargs.get('group', ''))) + return {'filters': filters, 'groups': groups} except (Resolver404, NoReverseMatch, ValueError, KeyError): pass @@ -205,7 +207,7 @@ def sort_interactions_by_name(value): Sort an interaction list by client name """ inters = list(value) - inters.sort(lambda a, b: cmp(a.client.name, b.client.name)) + inters.sort(key=lambda a: a.client.name) return inters @@ -223,7 +225,7 @@ class AddUrlFilter(template.Node): filter_value = self.filter_value.resolve(context, True) if filter_value: filter_name = smart_str(self.filter_name) - filter_value = smart_unicode(filter_value) + filter_value = smart_str(filter_value) kwargs[filter_name] = filter_value # These two don't make sense if filter_name == 'server' and 'hostname' in kwargs: @@ -306,6 +308,7 @@ def to_media_url(parser, token): return MediaTag(filter_value) + @register.filter def determine_client_state(entry): """ @@ -338,10 +341,11 @@ def do_qs(parser, token): try: tag, name, value = token.split_contents() except ValueError: - raise template.TemplateSyntaxError, "%r tag requires exactly two arguments" \ - % token.contents.split()[0] + raise template.TemplateSyntaxError("%r tag requires exactly two arguments" + % token.contents.split()[0]) return QsNode(name, value) + class QsNode(template.Node): def __init__(self, name, value): self.name = template.Variable(name) @@ -359,7 +363,7 @@ class QsNode(template.Node): return '' except KeyError: if settings.TEMPLATE_DEBUG: - raise Exception, "'qs' tag requires context['request']" + raise Exception("'qs' tag requires context['request']") return '' except: return '' @@ -380,6 +384,7 @@ def sort_link(parser, token): return SortLinkNode(sort_key, text) + class SortLinkNode(template.Node): __TMPL__ = "{% load bcfg2_tags %}{{ text }}" @@ -420,4 +425,3 @@ class SortLinkNode(template.Node): raise raise return '' - diff --git a/src/lib/Bcfg2/Reporting/templatetags/syntax_coloring.py b/src/lib/Bcfg2/Reporting/templatetags/syntax_coloring.py index 2712d6395..22700689f 100644 --- a/src/lib/Bcfg2/Reporting/templatetags/syntax_coloring.py +++ b/src/lib/Bcfg2/Reporting/templatetags/syntax_coloring.py @@ -1,11 +1,8 @@ -import sys from django import template -from django.utils.encoding import smart_unicode +from django.utils.encoding import smart_str from django.utils.html import conditional_escape from django.utils.safestring import mark_safe -from Bcfg2.Compat import u_str - register = template.Library() # pylint: disable=E0611 @@ -33,9 +30,9 @@ def syntaxhilight(value, arg="diff", autoescape=None): if colorize: try: - output = u_str('') + output = smart_str('') lexer = get_lexer_by_name(arg) output += highlight(value, lexer, HtmlFormatter()) @@ -43,6 +40,7 @@ def syntaxhilight(value, arg="diff", autoescape=None): except: return value else: - return mark_safe(u_str('
    Tip: Install pygments ' - 'for highlighting
    %s
    ') % value) + return mark_safe(smart_str( + '
    Tip: Install pygments ' + 'for highlighting
    %s
    ') % value) syntaxhilight.needs_autoescape = True diff --git a/src/lib/Bcfg2/settings.py b/src/lib/Bcfg2/settings.py index 9393830a8..b736eb9a5 100644 --- a/src/lib/Bcfg2/settings.py +++ b/src/lib/Bcfg2/settings.py @@ -32,6 +32,8 @@ TIME_ZONE = None DEBUG = False TEMPLATE_DEBUG = DEBUG +ALLOWED_HOSTS = ['*'] + MEDIA_URL = '/site_media/' @@ -130,6 +132,7 @@ INSTALLED_APPS = ( 'django.contrib.sites', 'django.contrib.admin', 'Bcfg2.Server', + 'Bcfg2.Reporting', ) if HAS_SOUTH: INSTALLED_APPS = INSTALLED_APPS + ( -- cgit v1.2.3-1-g7c22 From b380b0d1b9c135069d91a19a618f617b75d7f80c Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Wed, 1 May 2013 15:28:52 -0500 Subject: Remove extra import Signed-off-by: Sol Jerome --- src/lib/Bcfg2/settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/Bcfg2/settings.py b/src/lib/Bcfg2/settings.py index b736eb9a5..9adfd66bf 100644 --- a/src/lib/Bcfg2/settings.py +++ b/src/lib/Bcfg2/settings.py @@ -132,7 +132,6 @@ INSTALLED_APPS = ( 'django.contrib.sites', 'django.contrib.admin', 'Bcfg2.Server', - 'Bcfg2.Reporting', ) if HAS_SOUTH: INSTALLED_APPS = INSTALLED_APPS + ( -- cgit v1.2.3-1-g7c22 From fd993228d36c166593285a8ebbd2e6fb45c36d4d Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Mon, 6 May 2013 15:16:34 -0500 Subject: Add url loads for all templates Signed-off-by: Sol Jerome --- src/lib/Bcfg2/Reporting/templates/clients/detail.html | 4 ++++ src/lib/Bcfg2/Reporting/templates/clients/detailed-list.html | 4 ++++ src/lib/Bcfg2/Reporting/templates/clients/index.html | 4 ++++ src/lib/Bcfg2/Reporting/templates/clients/manage.html | 4 ++++ src/lib/Bcfg2/Reporting/templates/config_items/common.html | 1 + src/lib/Bcfg2/Reporting/templates/config_items/item.html | 4 ++++ src/lib/Bcfg2/Reporting/templates/config_items/listing.html | 4 ++++ src/lib/Bcfg2/Reporting/templates/displays/summary.html | 4 ++++ src/lib/Bcfg2/Reporting/templates/displays/timing.html | 4 ++++ 9 files changed, 33 insertions(+) diff --git a/src/lib/Bcfg2/Reporting/templates/clients/detail.html b/src/lib/Bcfg2/Reporting/templates/clients/detail.html index 9c0299121..e890589a7 100644 --- a/src/lib/Bcfg2/Reporting/templates/clients/detail.html +++ b/src/lib/Bcfg2/Reporting/templates/clients/detail.html @@ -1,5 +1,9 @@ {% extends "base.html" %} {% load bcfg2_tags %} +{% comment %} +This is needed for Django versions less than 1.5 +{% endcomment %} +{% load url from future %} {% block title %}Bcfg2 - Client {{client.name}}{% endblock %} diff --git a/src/lib/Bcfg2/Reporting/templates/clients/detailed-list.html b/src/lib/Bcfg2/Reporting/templates/clients/detailed-list.html index 2a03eede1..33c78a5f0 100644 --- a/src/lib/Bcfg2/Reporting/templates/clients/detailed-list.html +++ b/src/lib/Bcfg2/Reporting/templates/clients/detailed-list.html @@ -1,5 +1,9 @@ {% extends "base-timeview.html" %} {% load bcfg2_tags %} +{% comment %} +This is needed for Django versions less than 1.5 +{% endcomment %} +{% load url from future %} {% block title %}Bcfg2 - Detailed Client Listing{% endblock %} {% block pagebanner %}Clients - Detailed View{% endblock %} diff --git a/src/lib/Bcfg2/Reporting/templates/clients/index.html b/src/lib/Bcfg2/Reporting/templates/clients/index.html index 957cbffd2..eba83670b 100644 --- a/src/lib/Bcfg2/Reporting/templates/clients/index.html +++ b/src/lib/Bcfg2/Reporting/templates/clients/index.html @@ -1,5 +1,9 @@ {% extends "base-timeview.html" %} {% load bcfg2_tags %} +{% comment %} +This is needed for Django versions less than 1.5 +{% endcomment %} +{% load url from future %} {% block extra_header_info %} {% endblock%} diff --git a/src/lib/Bcfg2/Reporting/templates/clients/manage.html b/src/lib/Bcfg2/Reporting/templates/clients/manage.html index 5ba3393b2..03918aad7 100644 --- a/src/lib/Bcfg2/Reporting/templates/clients/manage.html +++ b/src/lib/Bcfg2/Reporting/templates/clients/manage.html @@ -1,4 +1,8 @@ {% extends "base.html" %} +{% comment %} +This is needed for Django versions less than 1.5 +{% endcomment %} +{% load url from future %} {% block extra_header_info %} {% endblock%} diff --git a/src/lib/Bcfg2/Reporting/templates/config_items/common.html b/src/lib/Bcfg2/Reporting/templates/config_items/common.html index 0dbd52156..91f37d7dc 100644 --- a/src/lib/Bcfg2/Reporting/templates/config_items/common.html +++ b/src/lib/Bcfg2/Reporting/templates/config_items/common.html @@ -1,5 +1,6 @@ {% extends "base-timeview.html" %} {% load bcfg2_tags %} +{% load url from future %} {% block title %}Bcfg2 - Common Problems{% endblock %} diff --git a/src/lib/Bcfg2/Reporting/templates/config_items/item.html b/src/lib/Bcfg2/Reporting/templates/config_items/item.html index c15a85e0a..b03d48045 100644 --- a/src/lib/Bcfg2/Reporting/templates/config_items/item.html +++ b/src/lib/Bcfg2/Reporting/templates/config_items/item.html @@ -1,6 +1,10 @@ {% extends "base.html" %} {% load split %} {% load syntax_coloring %} +{% comment %} +This is needed for Django versions less than 1.5 +{% endcomment %} +{% load url from future %} {% block title %}Bcfg2 - Element Details{% endblock %} diff --git a/src/lib/Bcfg2/Reporting/templates/config_items/listing.html b/src/lib/Bcfg2/Reporting/templates/config_items/listing.html index fb10bb020..0e4812e85 100644 --- a/src/lib/Bcfg2/Reporting/templates/config_items/listing.html +++ b/src/lib/Bcfg2/Reporting/templates/config_items/listing.html @@ -1,5 +1,9 @@ {% extends "base-timeview.html" %} {% load bcfg2_tags %} +{% comment %} +This is needed for Django versions less than 1.5 +{% endcomment %} +{% load url from future %} {% block title %}Bcfg2 - Element Listing{% endblock %} diff --git a/src/lib/Bcfg2/Reporting/templates/displays/summary.html b/src/lib/Bcfg2/Reporting/templates/displays/summary.html index c432da95d..ffafd52e0 100644 --- a/src/lib/Bcfg2/Reporting/templates/displays/summary.html +++ b/src/lib/Bcfg2/Reporting/templates/displays/summary.html @@ -1,5 +1,9 @@ {% extends "base-timeview.html" %} {% load bcfg2_tags %} +{% comment %} +This is needed for Django versions less than 1.5 +{% endcomment %} +{% load url from future %} {% block title %}Bcfg2 - Client Summary{% endblock %} {% block pagebanner %}Clients - Summary{% endblock %} diff --git a/src/lib/Bcfg2/Reporting/templates/displays/timing.html b/src/lib/Bcfg2/Reporting/templates/displays/timing.html index 57806b63a..8ac5e49bb 100644 --- a/src/lib/Bcfg2/Reporting/templates/displays/timing.html +++ b/src/lib/Bcfg2/Reporting/templates/displays/timing.html @@ -1,5 +1,9 @@ {% extends "base-timeview.html" %} {% load bcfg2_tags %} +{% comment %} +This is needed for Django versions less than 1.5 +{% endcomment %} +{% load url from future %} {% block title %}Bcfg2 - Performance Metrics{% endblock %} {% block pagebanner %}Performance Metrics{% endblock %} -- cgit v1.2.3-1-g7c22