]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blob - wradmin/wradmin/model/__init__.py
2cf9f5f0758d3ebec9d2a04f2db880744799b5fa
[philipp/winterrodeln/wradmin.git] / wradmin / wradmin / model / __init__.py
1 "Model of wradmin"
2 import sqlalchemy as sa
3 from sqlalchemy import orm, schema, types
4 from wradmin.model import meta
5 import datetime
6
7 def init_model(engine):
8     """Call me before using any of the tables or classes in the model"""
9     meta.Session.configure(bind=engine)
10     meta.engine = engine
11
12
13 # Current table definition
14 # - version 1.2
15 # - version 1.3 (no changes)
16 # - version 1.4 (no changes)
17 wrreport_table = sa.Table("wrreport", meta.metadata,
18     sa.Column("id", types.Integer, primary_key=True),
19     sa.Column("page_id", types.Integer, schema.ForeignKey('wrsleddingcache.page_id')),
20     sa.Column("page_title", types.Unicode(255), nullable=False),
21     sa.Column("date_report", types.Date),
22     sa.Column("date_entry", types.DateTime, nullable=False),
23     sa.Column("date_invalid", types.DateTime),
24     sa.Column("condition", types.Integer),
25     sa.Column("description", types.Unicode),
26     sa.Column("author_name", types.Unicode(30)),
27     sa.Column("author_ip", types.Unicode(15)),
28     sa.Column("author_userid", types.Integer),
29     sa.Column("author_username", types.Unicode(30)),
30     sa.Column("delete_date", types.DateTime),
31     sa.Column("delete_person_name", types.Unicode(30)),
32     sa.Column("delete_person_ip", types.Unicode(15)),
33     sa.Column("delete_person_userid", types.Integer),
34     sa.Column("delete_person_username", types.Unicode(30)),
35     sa.Column("delete_reason_public", types.Unicode),
36     )
37
38
39 # Old table definition
40 # - version 1.2
41 wrsleddingcache_table1_2 =  sa.Table("wrsleddingcache1_2", meta.metadata,
42     sa.Column("page_id", types.Integer, primary_key=True),
43     sa.Column("page_title", types.Unicode(255)),
44     sa.Column("length", types.Integer),
45     sa.Column("walktime", types.Integer),
46     sa.Column("height_top", types.Integer),
47     sa.Column("height_bottom", types.Integer),
48     sa.Column("walkup_separate", types.Boolean),
49     sa.Column("lift", types.Boolean),
50     sa.Column("night_light", types.Boolean),
51     sa.Column("sledge_rental", types.Boolean),
52     sa.Column("public_transport", types.Boolean),
53     sa.Column("image", types.Unicode(255)),
54     sa.Column("position_latitude", types.Float),
55     sa.Column("position_longitude", types.Float),
56     sa.Column("information", types.Unicode(255)),
57     sa.Column("forum_id", types.Integer),
58     sa.Column("under_construction", types.Boolean),
59     sa.Column("show_in_overview", types.Boolean),
60     )
61
62
63 # Old table definition
64 # - version 1.3 (changes made from version 1.2)
65 # wrsleddingcache_table1_3 =  sa.Table("wrsleddingcache1_3", meta.metadata,
66 wrsleddingcache_table1_3 =  sa.Table("wrsleddingcache", meta.metadata,
67     sa.Column("page_id", types.Integer, primary_key=True),
68     sa.Column("page_title", types.Unicode(255)),
69     sa.Column("position_latitude", types.Float),
70     sa.Column("position_longitude", types.Float),
71     sa.Column("top_latitude", types.Float),
72     sa.Column("top_longitude", types.Float),
73     sa.Column("top_elevation", types.Integer),
74     sa.Column("bottom_latitude", types.Float),
75     sa.Column("bottom_longitude", types.Float),
76     sa.Column("bottom_elevation", types.Integer),
77     sa.Column("length", types.Integer),
78     sa.Column("difficulty", types.Integer),
79     sa.Column("avalanches", types.Integer),
80     sa.Column("operator", types.Unicode(255)),
81     sa.Column("public_transport", types.Integer),
82     sa.Column("walkup_time", types.Integer),
83     sa.Column("walkup_separate", types.Float),
84     sa.Column("walkup_separate_comment", types.Unicode(255)),
85     sa.Column("lift", types.Boolean),
86     sa.Column("lift_details", types.Unicode(255)),
87     sa.Column("night_light", types.Float),
88     sa.Column("night_light_comment", types.Unicode(255)),
89     sa.Column("night_light_days", types.Integer),
90     sa.Column("night_light_days_comment", types.Unicode(255)),
91     sa.Column("sled_rental", types.Boolean),
92     sa.Column("sled_rental_comment", types.Unicode(255)),
93     sa.Column("cachet", types.Unicode(255)),
94     sa.Column("information_web", types.Unicode(255)),
95     sa.Column("information_phone", types.Unicode(255)),
96     sa.Column("image", types.Unicode(255)),
97     sa.Column("show_in_overview", types.Boolean),
98     sa.Column("forum_id", types.Integer),
99     sa.Column("under_construction", types.Boolean),
100     )
101
102
103 # Current table definition
104 # - version 1.4 (renamed table and added column walkup_possible)
105 wrsledruncache_table =  sa.Table("wrsledruncache", meta.metadata,
106     sa.Column("page_id", types.Integer, primary_key=True),
107     sa.Column("page_title", types.Unicode(255)),
108     sa.Column("position_latitude", types.Float),
109     sa.Column("position_longitude", types.Float),
110     sa.Column("top_latitude", types.Float),
111     sa.Column("top_longitude", types.Float),
112     sa.Column("top_elevation", types.Integer),
113     sa.Column("bottom_latitude", types.Float),
114     sa.Column("bottom_longitude", types.Float),
115     sa.Column("bottom_elevation", types.Integer),
116     sa.Column("length", types.Integer),
117     sa.Column("difficulty", types.Integer),
118     sa.Column("avalanches", types.Integer),
119     sa.Column("operator", types.Unicode(255)),
120     sa.Column("public_transport", types.Integer),
121     sa.Column("walkup_possible", types.Boolean),
122     sa.Column("walkup_time", types.Integer),
123     sa.Column("walkup_separate", types.Float),
124     sa.Column("walkup_separate_comment", types.Unicode(255)),
125     sa.Column("lift", types.Boolean),
126     sa.Column("lift_details", types.Unicode(255)),
127     sa.Column("night_light", types.Float),
128     sa.Column("night_light_comment", types.Unicode(255)),
129     sa.Column("night_light_days", types.Integer),
130     sa.Column("night_light_days_comment", types.Unicode(255)),
131     sa.Column("sled_rental", types.Boolean),
132     sa.Column("sled_rental_comment", types.Unicode(255)),
133     sa.Column("cachet", types.Unicode(255)),
134     sa.Column("information_web", types.Unicode(255)),
135     sa.Column("information_phone", types.Unicode(255)),
136     sa.Column("image", types.Unicode(255)),
137     sa.Column("show_in_overview", types.Boolean),
138     sa.Column("forum_id", types.Integer),
139     sa.Column("under_construction", types.Boolean),
140     )
141
142
143 # Old table definition
144 # - version 1.2
145 wrinncache_table1_2 =  sa.Table("wrinncache1_2", meta.metadata,
146     sa.Column("page_id", types.Integer, primary_key=True),
147     sa.Column("page_title", types.Unicode(255)),
148     sa.Column("height", types.Integer),
149     sa.Column("phone", types.Unicode(30)),
150     sa.Column("mobile_phone", types.Unicode(30)),
151     sa.Column("email", types.Unicode(255)),
152     sa.Column("homepage", types.Unicode(255)),
153     sa.Column("smoker_area", types.Boolean),
154     sa.Column("nonsmoker_area", types.Boolean),
155     sa.Column("image", types.Unicode(255)),
156     sa.Column("position_latitude", types.Float),
157     sa.Column("position_longitude", types.Float),
158     sa.Column("under_construction", types.Boolean),
159     )
160
161
162 # Current table definition
163 # - version 1.3 (changes made from version 1.2)
164 # - version 1.4 (no changes)
165 wrinncache_table =  sa.Table("wrinncache", meta.metadata,
166     sa.Column("page_id", types.Integer, primary_key=True),
167     sa.Column("page_title", types.Unicode(255)),
168     sa.Column("position_latitude", types.Float),
169     sa.Column("position_longitude", types.Float),
170     sa.Column("position_elevation", types.Integer),
171     sa.Column("seats", types.Integer),
172     sa.Column("overnight", types.Boolean),
173     sa.Column("overnight_comment", types.Unicode(255)),
174     sa.Column("smoker_area", types.Boolean),
175     sa.Column("nonsmoker_area", types.Boolean),
176     sa.Column("sled_rental", types.Boolean),
177     sa.Column("sled_rental_comment", types.Unicode(255)),
178     sa.Column("mobile_provider", types.Unicode),
179     sa.Column("homepage", types.Unicode(255)),
180     sa.Column("email_list", types.Unicode),
181     sa.Column("phone_list", types.Unicode),
182     sa.Column("image", types.Unicode(255)),
183     sa.Column("sledding_list", types.Unicode),
184     sa.Column("under_construction", types.Boolean),
185     )
186
187
188 page_table = sa.Table("page", meta.metadata,
189     sa.Column("page_id", types.Integer, primary_key=True),
190     sa.Column("page_namespace", types.Integer, nullable=False),
191     sa.Column("page_title", types.Unicode(255), nullable=False),
192     sa.Column("page_restrictions", types.Unicode, nullable=False),
193     sa.Column("page_counter", types.Integer, nullable=False),
194     sa.Column("page_is_redirect", types.Integer, nullable=False),
195     sa.Column("page_is_new", types.Integer, nullable=False),
196     sa.Column("page_random", types.Float, nullable=False),
197     sa.Column("page_touched", types.Unicode(14), nullable=False),
198     sa.Column("page_latest", types.Integer, nullable=False),
199     sa.Column("page_len", types.Integer, nullable=False),
200     )
201
202
203 revision_table = sa.Table("revision", meta.metadata,
204     sa.Column("rev_id", types.Integer, nullable=False, primary_key=True),
205     sa.Column("rev_page", types.Integer, nullable=False, primary_key=True),
206     sa.Column("rev_text_id", types.Integer, nullable=False),
207     sa.Column("rev_comment", types.Unicode),
208     sa.Column("rev_user", types.Integer, nullable=False),
209     sa.Column("rev_user_text", types.Unicode(255), nullable=False),
210     sa.Column("rev_timestamp", types.Unicode(14), nullable=False),
211     sa.Column("rev_minor_edit", types.Integer, nullable=False),
212     sa.Column("rev_deleted", types.Integer, nullable=False),
213     sa.Column("rev_len", types.Integer, nullable=False),
214     sa.Column("rev_parent_id", types.Integer, nullable=False),
215     )
216
217
218 text_table = sa.Table("text", meta.metadata,
219     sa.Column("old_id", types.Integer, primary_key=True),
220     sa.Column("old_text", types.Unicode),
221     sa.Column("old_flags", types.Unicode),
222     )
223
224
225 categorylinks_table = sa.Table("categorylinks", meta.metadata,
226     sa.Column("cl_from", types.Integer, nullable=False, primary_key=True),
227     sa.Column("cl_to", types.Unicode(255), nullable=False, primary_key=True),
228     sa.Column("cl_sortkey", types.Unicode, nullable=False),
229     sa.Column("cl_timestamp", types.DateTime, nullable=False),
230     )
231
232
233 class WrReport(object):
234     pass
235
236
237 # Old version (not mapped)
238 class WrSleddingCache1_2(object):
239     pass
240
241
242 class WrSledrunCache(object):
243     pass
244
245
246 # Old version (not mapped)
247 class WrInnCache1_2(object):
248     pass
249
250
251 class WrInnCache(object):
252     pass
253
254
255 # Page (not mapped)
256 class Page(object):
257     pass
258
259
260 orm.mapper(WrReport, wrreport_table)
261 # We could add a relation but we don't need it yet:
262 # orm.mapper(WrSledrunCache, wrsledruncache_table, properties = {'reports': orm.relation(WrReport, backref='sledding')})
263 orm.mapper(WrSledrunCache, wrsleddingcache_table1_3) # TODO: Change to wrsledruncache_table
264 orm.mapper(WrInnCache, wrinncache_table)
265