Skip to content

Commit 653794f

Browse files
author
Dairon Medina
committed
Adding report formats
1 parent 27cab7f commit 653794f

File tree

10 files changed

+220
-44
lines changed

10 files changed

+220
-44
lines changed

apps/base/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def __unicode__(self):
218218
return u'%s:%s' % (self.name, self.value or u'Not Set')
219219

220220
@classmethod
221-
def get(cls, name):
221+
def get_val(cls, name):
222222
from base.forms import SettingsForm
223223
form = SettingsForm()
224224
if name not in form.fields.keys():

apps/hauliers/report.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Developer: Dairon Medina Caro <dairon.medina@gmail.com>
44
# Co-Developer Rhys Park <sales@openweigh.co.uk>
55
from django.utils.translation import ugettext_lazy as _
6-
from reporting.reports import ReportCSVFormatter, ReportGenerator, or_empty_char, yes_no
6+
from reporting.reports import ReportCSVFormatter, ReportPDFFormatter, ReportGenerator, or_empty_char, yes_no
77

88
from hauliers.models import Haulier
99

@@ -33,6 +33,18 @@ def generate_csv(self, response, hauliers):
3333

3434
def filename(self):
3535
return self.filename_template
36+
37+
class HauliersPDFFormatter(ReportPDFFormatter):
38+
filename_template = 'hauliers-report.pdf'
39+
40+
def generate_pdf(self, hauliers):
41+
context = {}
42+
context['hauliers'] = hauliers
43+
template = 'reports/hauliers_pdf_report.html'
44+
return self.render_pdf(context, template)
45+
46+
def filename(self):
47+
return self.filename_template
3648

3749

3850
class HauliersReportGenerator(ReportGenerator):
@@ -41,6 +53,7 @@ class HauliersReportGenerator(ReportGenerator):
4153

4254
formatters = {
4355
'CSV_formatter': HauliersCSVFormatter,
56+
'PDF_formatter': HauliersPDFFormatter,
4457
}
4558

4659
def generate(self):

apps/reporting/templatetags/__init__.py

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from django import template
2+
from django.utils.html import format_html
3+
4+
from base.models import Setting
5+
6+
register = template.Library()
7+
8+
9+
@register.inclusion_tag('reports/header.html', takes_context=True)
10+
def render_header(context):
11+
company_name = Setting.get_val('company_name')
12+
13+
street1 = Setting.get_val('street1')
14+
street2 = Setting.get_val('street2')
15+
city = Setting.get_val('city')
16+
state = Setting.get_val('state')
17+
postcode = Setting.get_val('postcode')
18+
19+
company_address = '%s %s, %s, %s %s' %(street1, street2, city, state, postcode)
20+
21+
context.update({'company_name': company_name, 'company_address': company_address})
22+
return context

media/images/logo.png

5.23 KB
Loading
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{% extends "reports/report_layout.html" %}
2+
{% load i18n %}
3+
4+
5+
{% block main %}
6+
7+
<table>
8+
<thead>
9+
<tr>
10+
<th>Haulier Name</th>
11+
<th>Contact Person</th>
12+
<th>Phone</th>
13+
<th>Email</th>
14+
<th>City</th>
15+
</tr>
16+
</thead>
17+
<tbody>
18+
{% for haulier in hauliers %}
19+
<tr>
20+
<td>{{ haulier.name }}</td>
21+
<td>{{ haulier.contact_person }}</td>
22+
<td>{{ haulier.phone_number }}</td>
23+
<td>{{ haulier.email }}</td>
24+
<td>{{ haulier.city }}</td>
25+
</tr>
26+
{% endfor %}
27+
<tbody>
28+
</table>
29+
{% endblock %}

templates/reports/header.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% load static from staticfiles %}
2+
3+
<table id="header">
4+
<tr style="width:100%">
5+
<td><img id="logo" src="{{ MEDIA_URL }}images/logo.png"/></td>
6+
</tr>
7+
<tr style="width:100%;color:#0F207C;font-size=16px;">
8+
<td>
9+
{{ company_name }}
10+
<br/>
11+
{{ company_address }}
12+
</td>
13+
</tr>
14+
</table>
15+
<hr/>
Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,25 @@
1+
{% extends "reports/report_layout.html" %}
12
{% load i18n %}
23

3-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es">
54

6-
<head>
7-
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
8-
<title>{% block meta_title %}{% endblock %}</title>
9-
10-
<style type="text/css">
11-
{% block style %}
12-
{% endblock %}
13-
</style>
14-
</head>
15-
16-
<body>
17-
<div id="wrapper">
18-
<div id="header">
19-
{% block header %}
20-
<h1>Product List</h1>
21-
{% endblock %}
22-
</div>
23-
24-
<hr/>
25-
26-
<div id="content">
27-
<div id="main">
28-
{% block main %}
29-
{% for product in products %}
30-
{{ product.name }}
31-
{% endfor %}
32-
{% endblock %}
33-
</div>
34-
</div>
35-
36-
<hr/>
37-
38-
<div id="footer">
39-
{% block footer %}
40-
{% endblock %}
41-
</div>
42-
</div>
43-
</body>
44-
45-
</html>
5+
{% block main %}
6+
7+
<table>
8+
<thead>
9+
<tr>
10+
<th>Product Code</th>
11+
<th>Product Name</th>
12+
<th>Category</th>
13+
</tr>
14+
</thead>
15+
<tbody>
16+
{% for product in products %}
17+
<tr>
18+
<th>{{ product.code }}</th>
19+
<th>{{ product.name }}</th>
20+
<th>{{ product.category.name }}</th>
21+
</tr>
22+
{% endfor %}
23+
<tbody>
24+
</table>
25+
{% endblock %}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
{% load i18n %}
2+
{% load report_tags %}
3+
4+
5+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
6+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es">
7+
8+
<head>
9+
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
10+
<title>{% block meta_title %}{% endblock %}</title>
11+
12+
<style type="text/css">
13+
#header {
14+
margin-bottom: 20px;
15+
}
16+
17+
18+
#header tr {
19+
font-weight: bold;
20+
border-bottom: 2px solid black;
21+
}
22+
23+
#header td {
24+
vertical-align: middle;
25+
text-align: center;
26+
}
27+
28+
h1 {
29+
font-size: 18pt;
30+
}
31+
32+
#footerContent {
33+
padding-top: 10px;
34+
font-size: 12px;
35+
}
36+
37+
@page {
38+
margin: 1cm;
39+
margin-bottom: 4cm;
40+
{% block page_styles %}{% endblock %}
41+
42+
@frame footer {
43+
-pdf-frame-content: footerContent;
44+
bottom: 1cm;
45+
margin-left: 1cm;
46+
margin-right: 1cm;
47+
height: 2.5cm;
48+
text-align: right;
49+
}
50+
51+
{% block extra_frames %}{% endblock %}
52+
53+
}
54+
55+
#mid {
56+
text-align: left;
57+
border-bottom: 1px solid;
58+
}
59+
60+
61+
#report{
62+
padding: 2px 2px 2px 2px;
63+
font-size: 12px;
64+
text-align: left;
65+
}
66+
67+
#report table {
68+
border: 1px solid #000000;
69+
text-align: center;
70+
71+
}
72+
73+
#report th{
74+
font-weight: bold;
75+
}
76+
77+
{% block style %}
78+
{% endblock %}
79+
</style>
80+
</head>
81+
82+
<body>
83+
<div id="wrapper">
84+
85+
{% block page_header %}
86+
{% render_header %}
87+
{% endblock %}
88+
89+
<div id="report">
90+
{% block main %}
91+
92+
{% endblock %}
93+
</div>
94+
95+
<div id="footerContent">
96+
{% block page_footer %}
97+
<table>
98+
<tr style="border-bottom: 0.5px solid; ">
99+
<td>{% now "d/m/Y" %}</td>
100+
<td style="text-align: right;">
101+
Page
102+
<pdf:pagenumber>
103+
</td>
104+
</tr>
105+
</table>
106+
<p style="font-size: 8pt;color: #E6E6E6;text-align:center;">Weighbridge Software supplied by: OpenWeigh www.openweigh.co.uk</p>
107+
{% endblock %}
108+
</div>
109+
110+
111+
</div>
112+
</body>
113+
114+
</html>

urls.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.conf.urls import patterns, include, url
2+
from django.conf.urls.static import static
23
from django.views.generic.base import TemplateView
34

45
from django.conf import settings
@@ -21,6 +22,8 @@
2122
api.register(ProductResource())
2223

2324
urlpatterns = patterns('',
25+
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
26+
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
2427
url(r'^$', TemplateView.as_view(template_name='base/dashboard.html') , name="index"),
2528
url(r'^accounts/login/$', login, {'template_name': 'login.html'}, name="login"),
2629
url(r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/vehicles/'}, name="logout"),

0 commit comments

Comments
 (0)