-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathviews.py
More file actions
200 lines (149 loc) · 4.87 KB
/
views.py
File metadata and controls
200 lines (149 loc) · 4.87 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djing.settings")
import codecs
import urlparse
import urllib
from datetime import datetime
from django import template
from django.template.loader import render_to_string
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.utils.encoding import smart_unicode
from djing.natal_render import NatalSvg
from djing.models import ChartInfo, ChartInfoForm
from djing.models import getChartSets
from djing.utils import UserDefTZ
def testshow():
cid = 1
ci = ChartInfo.objects.get(id=1)
natal = NatalSvg()
cs = getChartSets(None)
natal.load_conf(cs)
natal.load_data(ci)
svg_xml = natal.render()
(ptable_data, htable_data, rtable_data) = natal.calc_planet_table_data()
firdaria_result = natal.firdaria()
h = render_to_string("natal.html",{"current":"natal",
"chart_svg":svg_xml,
"ptable_data":ptable_data,
"htable_data":htable_data,
"rtable_data":rtable_data,
"firdaria_result":firdaria_result,
"cid": cid,
"ci":ci})
f = codecs.open('html/natal.html', 'w', 'utf-8')
f.write(h)
f.close()
return "html/natal.html"
def natal(data):
cid = data
ci = ChartInfo.objects.get(id=data)
natal = NatalSvg()
cs = getChartSets(None)
natal.load_conf(cs)
natal.load_data(ci)
svg_xml = natal.render()
(ptable_data, htable_data, rtable_data) = natal.calc_planet_table_data()
firdaria_result = natal.firdaria()
h = render_to_string("natal.html",{"current":"natal",
"chart_svg":svg_xml,
"ptable_data":ptable_data,
"htable_data":htable_data,
"rtable_data":rtable_data,
"firdaria_result":firdaria_result,
"cid": cid,
"ci":ci})
f = codecs.open('html/natal.html', 'w', 'utf-8')
f.write(h)
f.close()
return "html/natal.html"
def delete(data):
ci = ChartInfo.objects.get(id=data)
ci.delete()
def add():
h = render_to_string("add.html",{"current":"add"})
f = codecs.open('html/add.html', 'w', 'utf-8')
f.write(h)
f.close()
return "html/add.html"
def edit(data):
ci = ChartInfo.objects.get(id=data)
cif = ChartInfoForm(instance=ci)
h = render_to_string("edit.html", {"ci":ci,"cif":cif})
f = codecs.open('html/edit.html', 'w', 'utf-8')
f.write(h)
f.close()
return "html/edit.html"
def edit_action(qs):
qd = urlparse.parse_qs(qs.decode("iso-8859-1").encode("utf-8"))
cid = qd["id"][0]
qname = qd["qname"][0]
gender = qd["gender"][0]
location = qd["location"][0]
latitude = float(qd["latitude"][0])
longitude = float(qd["longitude"][0])
n_date = datetime.strptime(qd["n_date"][0], '%Y-%m-%d %H:%M')
n_tz = int(qd["n_tz"][0])
hsys = qd["hsys"][0]
tz = UserDefTZ(n_tz)
n_date_tz = datetime(n_date.year,n_date.month,n_date.day,
n_date.hour, n_date.minute, n_date.second,
n_date.microsecond, tz)
ci = ChartInfo.objects.get(id=cid)
ci.qname = qname
ci.gender = gender
ci.location = location
ci.latitude = latitude
ci.longitude = longitude
ci.n_date = n_date_tz
ci.n_tz = n_tz
ci.hsys = hsys
ci.save()
def add_action(qs):
"""chartinfo insert into db"""
qd = urlparse.parse_qs(qs.decode("iso-8859-1").encode("utf-8"))
qname = qd["qname"][0]
gender = qd["gender"][0]
location = qd["location"][0]
latitude = float(qd["latitude"][0])
longitude = float(qd["longitude"][0])
n_date = datetime.strptime(qd["n_date"][0], '%Y-%m-%d %H:%M')
n_tz = int(qd["n_tz"][0])
hsys = qd["hsys"][0]
is_pub = qd["is_pub"][0]
tz = UserDefTZ(n_tz)
n_date_tz = datetime(n_date.year,n_date.month,n_date.day,
n_date.hour, n_date.minute, n_date.second,
n_date.microsecond, tz)
#save ChartInfo
ci = ChartInfo()
ci.qname = qname
ci.gender = gender
ci.location = location
ci.latitude = latitude
ci.longitude = longitude
ci.n_date = n_date_tz
ci.n_tz = n_tz
ci.hsys = hsys
ci.is_pub = is_pub
ci.save()
def list(page=1):
mycharts = ChartInfo.objects.all()
paginator = Paginator(mycharts, 10) # Show 25 contacts per page
try:
chartinfos = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
chartinfos = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
chartinfos = paginator.page(paginator.num_pages)
h = render_to_string("list.html",{"current":"list",
"chartinfos":chartinfos})
f = codecs.open('html/list.html', 'w', 'utf-8')
f.write(h)
f.close()
return "html/list.html"
if __name__ == '__main__':
testshow()