-
Notifications
You must be signed in to change notification settings - Fork 138
/
demo.py
84 lines (64 loc) · 2.04 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/env python
# coding=utf-8
"""
Demo script. Run:
python.exe demo.py
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import logging
import os
logging.basicConfig(level=logging.DEBUG)
from django.conf import settings
from django.conf.urls import url
from django.core.wsgi import get_wsgi_application
from django.utils.timezone import now as tznow
basename = os.path.splitext(os.path.basename(__file__))[0]
def rel(*path):
return os.path.abspath(
os.path.join(os.path.dirname(__file__), *path)
).replace('\\', '/')
if not settings.configured:
settings.configure(
DEBUG=os.environ.get('DEBUG', True),
TIMEZONE='UTC',
INSTALLED_APPS=['easy_pdf'],
TEMPLATES=[
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [rel('tests', 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
],
},
},
],
STATIC_ROOT=os.path.abspath(rel('tests', 'static')),
STATIC_URL='/static/',
ROOT_URLCONF=basename,
WSGI_APPLICATION='{}.application'.format(basename),
ALLOWED_HOSTS=[
'127.0.0.1',
'localhost',
'easy-pdf.herokuapp.com'
]
)
from easy_pdf.views import PDFTemplateView
class DemoPDFView(PDFTemplateView):
template_name = 'hello.html'
def get_context_data(self, **kwargs):
return super(DemoPDFView, self).get_context_data(
pagesize='A4',
title='Hi there!',
today=tznow(),
**kwargs
)
urlpatterns = [
url(r'^$', DemoPDFView.as_view())
]
application = get_wsgi_application()
if __name__ == '__main__':
from django.core.management import call_command
call_command('runserver', '0.0.0.0:8000')