198c3901c3e62a37e1c3e0baaed0c5bf5f752148
[philipp/winterrodeln/wrpylib.git] / wrpylib / wrmwdb.py
1 #!/usr/bin/python2.6
2 # -*- coding: iso-8859-15 -*-
3 # $Id$
4 # $HeadURL$
5 """This module contains code to make tha access of winterrodeln
6 tables in MediaWiki easy. The module uses sqlalchemy to access the database.
7 """
8 from sqlalchemy import Table, Column, types, schema
9
10
11 def wrreport_table(metadata):
12     """Returns the sqlalchemy Table representing the "wrreport" Winterrodeln table in MediaWiki.
13     Current table definition.
14     * version 1.2
15     * version 1.3 (no changes)
16     * version 1.4 (no changes)
17     * version 1.5 added time_report
18     :param metadata: metadata = sqlalchemy.MetaData()
19     """
20     return Table("wrreport", metadata,
21     Column("id", types.Integer, primary_key=True),
22     Column("page_id", types.Integer, schema.ForeignKey('wrsledruncache.page_id')),
23     Column("page_title", types.Unicode(255), nullable=False),
24     Column("date_report", types.Date),
25     Column("time_report", types.Time),
26     Column("date_entry", types.DateTime, nullable=False),
27     Column("date_invalid", types.DateTime),
28     Column("condition", types.Integer),
29     Column("description", types.Unicode),
30     Column("author_name", types.Unicode(30)),
31     Column("author_ip", types.Unicode(15)),
32     Column("author_userid", types.Integer),
33     Column("author_username", types.Unicode(30)),
34     Column("delete_date", types.DateTime),
35     Column("delete_person_name", types.Unicode(30)),
36     Column("delete_person_ip", types.Unicode(15)),
37     Column("delete_person_userid", types.Integer),
38     Column("delete_person_username", types.Unicode(30)),
39     Column("delete_reason_public", types.Unicode),
40     )
41
42
43 def wrsledruncache_table(metadata):
44     """Returns the sqlalchemy Table representing the "wrsledruncache" Winterrodeln table in MediaWiki.
45     Current table definition
46     * version 1.4 (renamed table and added column walkup_possible)
47     :param metadata: metadata = sqlalchemy.MetaData()
48     """
49     return Table("wrsledruncache", metadata,
50     Column("page_id", types.Integer, primary_key=True),
51     Column("page_title", types.Unicode(255)),
52     Column("position_latitude", types.Float),
53     Column("position_longitude", types.Float),
54     Column("top_latitude", types.Float),
55     Column("top_longitude", types.Float),
56     Column("top_elevation", types.Integer),
57     Column("bottom_latitude", types.Float),
58     Column("bottom_longitude", types.Float),
59     Column("bottom_elevation", types.Integer),
60     Column("length", types.Integer),
61     Column("difficulty", types.Integer),
62     Column("avalanches", types.Integer),
63     Column("operator", types.Unicode(255)),
64     Column("public_transport", types.Integer),
65     Column("walkup_possible", types.Boolean),
66     Column("walkup_time", types.Integer),
67     Column("walkup_separate", types.Float),
68     Column("walkup_separate_comment", types.Unicode(255)),
69     Column("lift", types.Boolean),
70     Column("lift_details", types.Unicode(255)),
71     Column("night_light", types.Float),
72     Column("night_light_comment", types.Unicode(255)),
73     Column("night_light_days", types.Integer),
74     Column("night_light_days_comment", types.Unicode(255)),
75     Column("sled_rental", types.Boolean),
76     Column("sled_rental_comment", types.Unicode(255)),
77     Column("cachet", types.Unicode(255)),
78     Column("information_web", types.Unicode(255)),
79     Column("information_phone", types.Unicode(255)),
80     Column("image", types.Unicode(255)),
81     Column("show_in_overview", types.Boolean),
82     Column("forum_id", types.Integer),
83     Column("under_construction", types.Boolean),
84     )
85
86
87 def wrinncache_table(metadata):
88     """Returns the sqlalchemy Table representing the "wrinncache" Winterrodeln table in MediaWiki.
89     Current table definition
90     * version 1.3 (changes made from version 1.2)
91     * version 1.4 (no changes)
92     :param metadata: metadata = sqlalchemy.MetaData()
93     """
94     return Table("wrinncache", metadata,
95     Column("page_id", types.Integer, primary_key=True),
96     Column("page_title", types.Unicode(255)),
97     Column("position_latitude", types.Float),
98     Column("position_longitude", types.Float),
99     Column("position_elevation", types.Integer),
100     Column("operator", types.Unicode(255)),
101     Column("seats", types.Integer),
102     Column("overnight", types.Boolean),
103     Column("overnight_comment", types.Unicode(255)),
104     Column("smoker_area", types.Boolean),
105     Column("nonsmoker_area", types.Boolean),
106     Column("sled_rental", types.Boolean),
107     Column("sled_rental_comment", types.Unicode(255)),
108     Column("mobile_provider", types.Unicode),
109     Column("homepage", types.Unicode(255)),
110     Column("email_list", types.Unicode),
111     Column("phone_list", types.Unicode),
112     Column("image", types.Unicode(255)),
113     Column("sledding_list", types.Unicode),
114     Column("under_construction", types.Boolean),
115     )
116
117
118 def wrreportcache_table(metadata):
119     """Returns the sqlalchemy Table representing the "wrreportcache" Winterrodeln table in MediaWiki.
120     Current table definition.
121     * version 1.5 (introduction)
122     :param metadata: metadata = sqlalchemy.MetaData()
123     """
124     return Table("wrreportcache", metadata,
125     Column("page_id", types.Integer, primary_key=True),
126     Column("page_title", types.Unicode(255), nullable=False),
127     Column("report_id", types.Integer),
128     Column("date_report", types.Date),
129     Column("condition", types.Integer),
130     Column("description", types.Unicode),
131     Column("author_name", types.Unicode(30)),
132     Column("author_username", types.Unicode(30))
133     )
134
135