# Conflicts:
#	dashboard/templates/dashboard/common/left_menu.html
#	drought/urls.py
This commit is contained in:
xieshen 2019-01-18 13:18:14 +08:00
parent 870a887b6e
commit c92571417c
15 changed files with 125 additions and 9 deletions

View File

@ -33,7 +33,7 @@
</select><br>
</div>
</div>
<div class="col-md-7">
<div class="col-md-6">
<div class="form-group">
<label for="exampleInputName2">时间</label>
<select name="year_from" class="sel">
@ -56,7 +56,11 @@
<div class="col-md-1">
<button type="submit" class="btn btn-default sel">查找</button>
</div>
</form>
<div class="col-md-1">
<a href="{% url 'export-pdf' %}"><button type="button" class="btn btn-default sel">生成pdf</button></a>
</div>
</div>
<div class="col-md-12" style="margin-top: 30px;">

View File

@ -46,6 +46,7 @@ INSTALLED_APPS = [
'predict',
'disaster',
'users',
'export',
]
MIDDLEWARE = [

View File

@ -17,6 +17,8 @@ from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.urls import path, include
import export
urlpatterns = [
path('', include('portal.urls')),
path('accounts/login/', auth_views.LoginView.as_view(), name='account-login'),
@ -27,5 +29,6 @@ urlpatterns = [
path('admin/', admin.site.urls),
path('predict/', include('predict.urls')),
path('users/',include('users.urls')),
path('disaster/', include('disaster.urls'))
path('disaster/', include('disaster.urls')),
path('export/',include('export.urls')),
]

0
export/__init__.py Normal file
View File

3
export/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
export/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class ExportConfig(AppConfig):
name = 'export'

3
export/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

View File

@ -0,0 +1,31 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>My Title</title>
{# <style type="text/css">#}
{# @page {#}
{# size: {{ pagesize }};#}
{# margin: 1cm;#}
{# @frame footer {#}
{# -pdf-frame-content: footerContent;#}
{# bottom: 0cm;#}
{# margin-left: 9cm;#}
{# margin-right: 9cm;#}
{# height: 1cm;#}
{# }#}
{# }#}
{# </style>#}
</head>
<body>
<div>
{% for item in mylist %}
{{ item }}
{% endfor %}
</div>
<div id="footerContent">
{%block page_foot%}
Page < pdf:pagenumber >
{%endblock%}
</div>
</body>
</html>

3
export/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

10
export/urls.py Normal file
View File

@ -0,0 +1,10 @@
from django.urls import path
from djgeojson.views import GeoJSONLayerView
from graphic.models import Address, Station, Grid
from . import views
urlpatterns = [
path('pdf/',views.myview,name = 'export-pdf')
]

51
export/views.py Normal file
View File

@ -0,0 +1,51 @@
import io
from django.shortcuts import render
import cStringIO as StringIO
from xhtml2pdf import pisa
from django.template.loader import get_template
from django.template import Context, loader
from django.http import HttpResponse
from cgi import escape
from dashboard.models import Spi
def render_to_pdf(template_src, context_dict):
template = get_template(template_src)
# context = Context(context_dict)
html = template.render(context)
result = StringIO.StringIO()
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("utf-8")), result)
if not pdf.err:
return HttpResponse(result.getvalue(), content_type='application/pdf')
return HttpResponse('We had some errors<pre>%s</pre>' % escape(html))
def myview(request):
results = [1,2,3]
return render_to_pdf('export/export_to_pdf.html',{'mylist':results})
# from reportlab.pdfgen import canvas
# from django.http import HttpResponse
#
# from dashboard.models import Spi
#
#
# def myview(request):
# spi = Spi.objects.all()
# for s in spi:
# print(str(s.code))
# response = HttpResponse()
# response['Content-Disposition'] = 'attachment; filename=hello.pdf;'
# p = canvas.Canvas(response)
# p.drawString(100, 100, s.code)
# p.showPage()
# p.save()
#
# return response

View File

@ -19,15 +19,15 @@ L.TileLayer.ChinaProvider = L.TileLayer.extend({
L.TileLayer.ChinaProvider.providers = {
TianDiTu: {
Normal: {
Map: "http://t{s}.tianditu.cn/DataServer?T=vec_w&X={x}&Y={y}&L={z}",
Map: "http://t{s}.tianditu.gov.cn/DataServer?T=vec_w&X={x}&Y={y}&L={z}&tk=c4e739f998041709c836927e4931ece0",
Annotion: "http://t{s}.tianditu.cn/DataServer?T=cva_w&X={x}&Y={y}&L={z}"
},
Satellite: {
Map: "http://t{s}.tianditu.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}",
Map: "http://t{s}.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=c4e739f998041709c836927e4931ece0",
Annotion: "http://t{s}.tianditu.cn/DataServer?T=cia_w&X={x}&Y={y}&L={z}"
},
Terrain: {
Map: "http://t{s}.tianditu.cn/DataServer?T=ter_w&X={x}&Y={y}&L={z}",
Map: "http://t{s}.tianditu.gov.cn/DataServer?T=ter_w&X={x}&Y={y}&L={z}&tk=c4e739f998041709c836927e4931ece0",
Annotion: "http://t{s}.tianditu.cn/DataServer?T=cta_w&X={x}&Y={y}&L={z}"
},
Subdomains: ['0', '1', '2', '3', '4', '5', '6', '7']

4
gs.py
View File

@ -134,9 +134,9 @@ if __name__ == '__main__':
for y in range(1979, 2017):
for m in range(1, 13):
file_name = "%s-%s-spi.tif" % (y, m)
file_name = "%s-%s-temp.tif" % (y, m)
print(file_name)
name = gs.create_and_publish_geotiff('baoji/spi/%s' % (file_name))
name = gs.create_and_publish_geotiff('baoji/temp/%s' % (file_name))
print('coverage storage name :' + name)
print('layer name :' + name)

View File

@ -17,3 +17,5 @@ scipy
matplotlib
pykrige
GDAL
reportlab
xhtml2pdf

View File

@ -3,7 +3,7 @@
{% load bootstrap3 %}
{% block breadcrumb %}{% endblock %}
{% block title %}青海G214国道综合信息管理系统{% endblock %}
{% block title %} 宝鸡地区气象灾害监测、预警与决策支持系统{% endblock %}
{% block content %}
<div class="container" style="min-height: 400px;margin-top: 15%">
<div class="col-md-6 col-md-offset-3">