Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
GeoInt_SIDT
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mario Chirinos Colunga
GeoInt_SIDT
Commits
4184af88
Commit
4184af88
authored
Mar 13, 2019
by
Ulises Morales Ramírez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pdf reportes v2
parent
25608314
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
77 deletions
+93
-77
aside.html
reports/templates/aside.html
+1
-1
views.py
reports/views.py
+92
-76
No files found.
reports/templates/aside.html
View file @
4184af88
...
@@ -136,7 +136,7 @@
...
@@ -136,7 +136,7 @@
</a>
</a>
</li>
</li>
<li>
<li>
<a
class=
"treeview submenu"
href=
"../../static/reports/tmpImages/repsat_test_dev/{{ request.user.email }}/{{ purchaseID }}/{{ zone }}.pdf"
id=
"downloadPdf"
>
<a
class=
"treeview submenu"
href=
"../../static/reports/tmpImages/repsat_test_dev/{{ request.user.email }}/{{ purchaseID }}/{{ zone }}.pdf"
id=
"downloadPdf"
target=
"_blank"
>
<i
class=
"fa fa-file-pdf-o"
></i>
<i
class=
"fa fa-file-pdf-o"
></i>
<span>
Export to PDF v2
</span>
<span>
Export to PDF v2
</span>
<span
class=
"pull-right-container"
>
<span
class=
"pull-right-container"
>
...
...
reports/views.py
View file @
4184af88
...
@@ -7,16 +7,13 @@ import xml.etree.ElementTree as ET
...
@@ -7,16 +7,13 @@ import xml.etree.ElementTree as ET
# Create your views here.
# Create your views here.
from
collections
import
OrderedDict
from
collections
import
OrderedDict
from
d
jango.core.paginator
import
Paginator
from
d
atetime
import
datetime
from
django.http
import
HttpResponse
,
Http404
,
JsonResponse
from
django.http
import
HttpResponse
,
Http404
,
JsonResponse
from
django.shortcuts
import
render
,
render_to_response
from
django.shortcuts
import
render
from
fpdf
import
FPDF
from
reportlab.lib.pagesizes
import
letter
from
reportlab.pdfgen
import
canvas
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.decorators.csrf
import
csrf_exempt
from
GeoInt_SIDT.tasks
import
add
from
catalog.models
import
Purchase
from
catalog.models
import
Purchase
from
GeoInt_SIDT.tasks
import
*
# -------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
...
@@ -37,13 +34,15 @@ def report_L2ASCL(request, report, purchase_id):
...
@@ -37,13 +34,15 @@ def report_L2ASCL(request, report, purchase_id):
reporteDir
=
report
.
replace
(
'_sclData'
,
''
)
reporteDir
=
report
.
replace
(
'_sclData'
,
''
)
path
=
USERS_PATH
+
request
.
user
.
email
+
'/'
+
purchase_id
+
'/'
path
=
USERS_PATH
+
request
.
user
.
email
+
'/'
+
purchase_id
+
'/'
if
os
.
path
.
isfile
(
path
+
reporteDir
+
'.pdf'
):
#PDFGenerator(request, path, reporteDir)
pass
else
:
#if os.path.isfile(path + reporteDir + '.pdf'):
# pass
#else:
##########################################
##########################################
# Generador de pdfs #
# Generador de pdfs #
##########################################
##########################################
PDFGenerator
(
path
,
reporteDir
)
# PDFGenerator(request,
path, reporteDir)
##########################################
##########################################
# Generador de pdfs #
# Generador de pdfs #
##########################################
##########################################
...
@@ -112,8 +111,14 @@ def report_L2ASCL(request, report, purchase_id):
...
@@ -112,8 +111,14 @@ def report_L2ASCL(request, report, purchase_id):
item
[
'backgroundColor'
]
=
colors
[
int
(
l
)]
item
[
'backgroundColor'
]
=
colors
[
int
(
l
)]
data
[
'datasets'
]
.
append
(
item
)
data
[
'datasets'
]
.
append
(
item
)
data
[
'datasets'
]
.
sort
(
key
=
lambda
k
:
max
(
k
[
'data'
]))
data
[
'datasets'
]
.
sort
(
key
=
lambda
k
:
max
(
k
[
'data'
]))
PDFGenerator
(
request
,
path
,
reporteDir
,
data
[
'datasets'
])
graphData
[
'data'
]
=
data
graphData
[
'data'
]
=
data
label
=
graphData
[
'data'
][
'labels'
][
0
]
label
=
graphData
[
'data'
][
'labels'
][
0
]
defaultLabel
=
graphData
[
'data'
][
'labels'
][
0
]
defaultLabel
=
graphData
[
'data'
][
'labels'
][
0
]
...
@@ -330,28 +335,10 @@ def tileinfo(request):
...
@@ -330,28 +335,10 @@ def tileinfo(request):
# ------------------------------------------------------------------------
# ------------------------------------------------------------------------
# def tareas():
def
PDFGenerator
(
request
,
ruta
,
reporteDir
,
datasets
):
# result = add.apply_async((2, 1), countdown=3)
thumbs
=
ruta
+
'out/'
+
reporteDir
+
'/TCI/thumbnails/'
# result.get()
SCL
=
ruta
+
'out/'
+
reporteDir
+
'/SCL/'
# return render_to_response('reports_table.html', {"result": result.get()})
def
PDFGenerator
(
path
,
reporteDir
):
class
PDF
(
FPDF
):
def
header
(
self
):
#self.image('logo.jpg')
# Arial bold 15
self
.
set_font
(
'Arial'
,
'B'
,
15
)
# Move to the right
self
.
cell
(
80
)
# Title
self
.
cell
(
30
,
10
,
'Title'
,
1
,
0
,
'C'
)
# Line break
self
.
ln
(
20
)
def
imagenes
(
self
):
#################################################################################
#################################################################################
# check https://developers.google.com/chart/image/docs/making_charts #
# check https://developers.google.com/chart/image/docs/making_charts #
# check https://developers.google.com/chart/image/docs/chart_params#gcharts_cht #
# check https://developers.google.com/chart/image/docs/chart_params#gcharts_cht #
...
@@ -360,38 +347,67 @@ def PDFGenerator(path, reporteDir):
...
@@ -360,38 +347,67 @@ def PDFGenerator(path, reporteDir):
# chl = labels #
# chl = labels #
#################################################################################
#################################################################################
url
=
"http://chart.apis.google.com/chart"
\
path
,
dirs
,
files
=
next
(
os
.
walk
(
thumbs
))
"?cht=p3"
\
w
,
h
=
letter
"&chd=t:60,40"
\
"&chs=500x200"
\
"&chl=Hello|World"
\
c
=
canvas
.
Canvas
(
ruta
+
reporteDir
+
".pdf"
,
pagesize
=
letter
,)
"&.png"
self
.
image
(
url
)
# Header #
# Arial bold 15
c
.
drawImage
(
USERS_PATH
+
'header.png'
,
170
,
h
-
90
,
width
=
300
,
height
=
70
)
self
.
set_font
(
'Arial'
,
'B'
,
15
)
# Move to the right
self
.
cell
(
80
)
c
.
showPage
()
# Title
self
.
cell
(
30
,
10
,
'Title'
,
1
,
0
,
'C'
)
# aqui estan los datos de todas las lineas #
# Line break
#for data2 in datasets:
self
.
ln
(
20
)
# solo de la linea verde #
#print(data2['data'][0])
# Page footer
def
footer
(
self
):
# Position at 1.5 cm from bottom
self
.
set_y
(
-
15
)
# Arial italic 8
# body #
self
.
set_font
(
'Arial'
,
'I'
,
8
)
for
file
in
files
:
# Page number
self
.
cell
(
0
,
10
,
'Page '
+
str
(
self
.
page_no
())
+
'/{nb}'
,
0
,
0
,
'C'
)
date
=
datetime
.
strptime
(
file
[:
8
],
'
%
Y
%
m
%
d'
)
.
strftime
(
'
%
d/
%
m/
%
Y'
)
# Instantiation of inherited class
pdf
=
PDF
()
c
.
drawString
(
280
,
h
-
125
,
date
)
pdf
.
alias_nb_pages
()
pdf
.
add_page
()
c
.
drawString
(
160
,
h
-
165
,
'TCI'
)
pdf
.
set_font
(
'Times'
,
''
,
12
)
c
.
drawString
(
440
,
h
-
165
,
'SCL'
)
for
i
in
range
(
1
,
5
):
c
.
drawImage
(
USERS_PATH
+
'header.png'
,
170
,
h
-
90
,
width
=
300
,
height
=
70
)
pdf
.
imagenes
()
# Thumb image #
pdf
.
output
(
path
+
reporteDir
+
'.pdf'
,
'F'
)
c
.
drawImage
(
thumbs
+
file
,
70
,
h
-
470
,
height
=
300
,
width
=
200
,
mask
=
'auto'
)
\ No newline at end of file
# SCL image #
path2
,
dirs2
,
files2
=
next
(
os
.
walk
(
SCL
))
for
file2
in
files2
:
if
file2
.
startswith
(
file
[:
8
]):
if
not
file2
.
endswith
(
'.tif'
):
c
.
drawImage
(
SCL
+
file2
,
350
,
h
-
470
,
height
=
300
,
width
=
200
,
mask
=
'auto'
)
# Chart #
# los valores deben ir en chd para cada elemento #
grafica
=
"https://chart.googleapis.com/chart?"
\
"&chs=900x150"
\
"&cht=bvs"
\
"&chd=t:0,0.0216,0,5.1408,29.8728,34.1892,57.0528,142.6788,506.6496,107.8344,0"
\
"&chds=a"
\
"&chco=ff8afa|659acc|99d4d9|696767|98775b|ababab|dddddd|d9f9ff|44ba5d|fff98b|383838"
\
"&chxt=y"
\
"&chm=N,000000,0,-1,11"
c
.
drawImage
(
grafica
,
140
,
h
-
650
,
width
=
900
,
height
=
150
)
c
.
drawImage
(
USERS_PATH
+
'values.png'
,
70
,
h
-
680
,
width
=
500
,
height
=
25
)
c
.
showPage
()
c
.
save
()
pass
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment