-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpolished_backend.py
31 lines (21 loc) · 1003 Bytes
/
polished_backend.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
import subprocess
import tempfile
from polished.backends import DjangoBackend
class ChinupDjangoBackend(DjangoBackend):
TEMP_SCRIPT = None
def __init__(self, *args, **kwargs):
super(ChinupDjangoBackend, self).__init__(*args, **kwargs)
script_data = open("generate_data.py", "r").read()
self.TEMP_SCRIPT = tempfile.NamedTemporaryFile()
self.TEMP_SCRIPT.write(script_data)
def prepare_page(self, *args, **kwargs):
super(ChinupDjangoBackend, self).prepare_page(*args, **kwargs)
print 'PREPARING PAGE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
try:
#subprocess.call(["python", "manage.py", "shell", "<", self.SCRIPT])
subprocess.check_call('python manage.py shell < %s' % self.TEMP_SCRIPT.name, shell=True)
except Exception:
pass
def dispose(self, *args, **kwargs):
self.TEMP_SCRIPT.close()
super(ChinupDjangoBackend, self).dispose(*args, **kwargs)