1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-10 01:17:59 +03:00

Advancing on basic reports

This commit is contained in:
Adolfo Gómez García 2015-04-24 04:19:43 +02:00
parent 3206390c9c
commit a1bd7274f4
4 changed files with 137 additions and 9 deletions

View File

@ -31,3 +31,4 @@
from __future__ import unicode_literals
from .usage import usage
from .users import users

View File

@ -32,9 +32,10 @@
from __future__ import unicode_literals
from django.conf.urls import patterns
__updated__ = '2015-03-10'
__updated__ = '2015-04-24'
urlpatterns = patterns(
'uds.admin.views.reporting',
(r'', 'usage'),
(r'^usage$', 'usage'),
(r'^users/(?P<idAuth>.+)$', 'users')
)

View File

@ -30,8 +30,9 @@
'''
from __future__ import unicode_literals
__updated__ = '2015-03-10'
__updated__ = '2015-04-24'
from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
@ -41,6 +42,7 @@ from uds.core.util.decorators import denyBrowsers
import io
import six
from geraldo.generators.pdf import PDFGenerator
from geraldo import Report, landscape, ReportBand, ObjectValue, SystemField, BAND_WIDTH, Label
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import cm
@ -55,6 +57,7 @@ class TestReport(Report):
title = 'Test report'
author = 'UDS Enterprise'
print_if_empty = True
page_size = A4
margin_left = 2 * cm
margin_top = 0.5 * cm
@ -64,9 +67,9 @@ class TestReport(Report):
class band_detail(ReportBand):
height = 0.5 * cm
elements = (
ObjectValue(attribute_name='id', left=0.5 * cm),
ObjectValue(attribute_name='date_creation', left=3 * cm,
get_value=lambda instance: six.text_type(instance)),
ObjectValue(attribute_name='name', left=0.5 * cm),
ObjectValue(attribute_name='age', left=3 * cm,
get_value=lambda instance: six.text_type(instance['age'])),
)
class band_page_header(ReportBand):
@ -76,7 +79,7 @@ class TestReport(Report):
style={'fontName': 'Helvetica-Bold', 'fontSize': 14, 'alignment': TA_CENTER}),
Label(text="ID", top=0.8 * cm, left=0.5 * cm),
Label(text=u"Creation Date", top=0.8 * cm, left=3 * cm),
SystemField(expression=u'Page %(page_number)d of %(page_count)d', top=0.1 * cm,
SystemField(expression=_('Page %(page_number)d of %(page_count)d'), top=0.1 * cm,
width=BAND_WIDTH, style={'alignment': TA_RIGHT}),
]
borders = {'bottom': True}
@ -85,7 +88,7 @@ class TestReport(Report):
height = 0.5 * cm
elements = [
Label(text='Geraldo Reports', top=0.1 * cm),
SystemField(expression=u'Printed in %(now:%Y, %b %d)s at %(now:%H:%M)s', top=0.1 * cm,
SystemField(expression=_('Printed in %(now:%Y, %b %d)s at %(now:%H:%M)s'), top=0.1 * cm,
width=BAND_WIDTH, style={'alignment': TA_RIGHT}),
]
borders = {'top': True}
@ -94,5 +97,18 @@ class TestReport(Report):
@denyBrowsers(browsers=['ie<9'])
@webLoginRequired(admin='admin')
def usage(request):
pass
resp = HttpResponse(content_type='application/pdf')
family = [
{'name': 'Leticia', 'age': 29, 'weight': 55.7, 'genre': 'female', 'status': 'parent'},
{'name': 'Marinho', 'age': 28, 'weight': 76, 'genre': 'male', 'status': 'parent'},
{'name': 'Tarsila', 'age': 4, 'weight': 16.2, 'genre': 'female', 'status': 'child'},
{'name': 'Linus', 'age': 0, 'weight': 1.5, 'genre': 'male', 'status': 'child'},
{'name': 'Mychelle', 'age': 19, 'weight': 50, 'genre': 'female', 'status': 'nephew'},
{'name': 'Mychell', 'age': 17, 'weight': 55, 'genre': 'male', 'status': 'niece'},
]
report = TestReport(queryset=family)
report.generate_by(PDFGenerator, filename=resp)
return resp
# return HttpResponse(pdf, content_type='application/pdf')

View File

@ -0,0 +1,110 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2012 Virtual Cable S.L.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''
@author: Adolfo Gómez, dkmaster at dkmon dot com
'''
from __future__ import unicode_literals
__updated__ = '2015-04-24'
from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
from uds.core.auths.auth import webLoginRequired
from uds.core.util.decorators import denyBrowsers
from uds.models import Authenticator
from uds.models.Util import NEVER
import io
import six
from geraldo.generators.pdf import PDFGenerator
from geraldo import Report, landscape, ReportBand, ObjectValue, SystemField, BAND_WIDTH, Label
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import cm
from reportlab.lib.enums import TA_RIGHT, TA_CENTER
import logging
logger = logging.getLogger(__name__)
class TestReport(Report):
title = 'Test report'
author = 'UDS Enterprise'
print_if_empty = True
page_size = A4
margin_left = 2 * cm
margin_top = 0.5 * cm
margin_right = 0.5 * cm
margin_bottom = 0.5 * cm
class band_detail(ReportBand):
height = 0.5 * cm
elements = (
ObjectValue(attribute_name='name', left=0.5 * cm),
ObjectValue(attribute_name='real_name', left=3 * cm),
ObjectValue(attribute_name='last_access', left=7 * cm),
)
class band_page_header(ReportBand):
height = 1.3 * cm
elements = [
SystemField(expression='%(report_title)s', top=0.1 * cm, left=0, width=BAND_WIDTH,
style={'fontName': 'Helvetica-Bold', 'fontSize': 14, 'alignment': TA_CENTER}),
Label(text="User ID", top=0.8 * cm, left=0.5 * cm),
Label(text="Real Name", top=0.8 * cm, left=3 * cm),
Label(text="Last access", top=0.8 * cm, left=7 * cm),
SystemField(expression=_('Page %(page_number)d of %(page_count)d'), top=0.1 * cm,
width=BAND_WIDTH, style={'alignment': TA_RIGHT}),
]
borders = {'bottom': True}
class band_page_footer(ReportBand):
height = 0.5 * cm
elements = [
Label(text='Geraldo Reports', top=0.1 * cm),
SystemField(expression=_('Printed in %(now:%Y, %b %d)s at %(now:%H:%M)s'), top=0.1 * cm,
width=BAND_WIDTH, style={'alignment': TA_RIGHT}),
]
borders = {'top': True}
@denyBrowsers(browsers=['ie<9'])
@webLoginRequired(admin='admin')
def users(request, idAuth):
resp = HttpResponse(content_type='application/pdf')
users = Authenticator.objects.get(uuid=idAuth).users.order_by('name')
report = TestReport(queryset=users)
report.generate_by(PDFGenerator, filename=resp)
return resp
# return HttpResponse(pdf, content_type='application/pdf')