"Model of wradmin"
-import sqlalchemy as sa
-from sqlalchemy import orm, schema, types
-from wradmin.model import meta
import datetime
+from sqlalchemy import orm
+from wradmin.model import meta
+from wrpylib import mwdb, mwwrdb
+
def init_model(engine):
"""Call me before using any of the tables or classes in the model"""
meta.engine = engine
-# Current table definition
-# - version 1.2
-# - version 1.3 (no changes)
-# - version 1.4 (no changes)
-wrreport_table = sa.Table("wrreport", meta.metadata,
- sa.Column("id", types.Integer, primary_key=True),
- sa.Column("page_id", types.Integer, schema.ForeignKey('wrsleddingcache.page_id')),
- sa.Column("page_title", types.Unicode(255), nullable=False),
- sa.Column("date_report", types.Date),
- sa.Column("date_entry", types.DateTime, nullable=False),
- sa.Column("date_invalid", types.DateTime),
- sa.Column("condition", types.Integer),
- sa.Column("description", types.Unicode),
- sa.Column("author_name", types.Unicode(30)),
- sa.Column("author_ip", types.Unicode(15)),
- sa.Column("author_userid", types.Integer),
- sa.Column("author_username", types.Unicode(30)),
- sa.Column("delete_date", types.DateTime),
- sa.Column("delete_person_name", types.Unicode(30)),
- sa.Column("delete_person_ip", types.Unicode(15)),
- sa.Column("delete_person_userid", types.Integer),
- sa.Column("delete_person_username", types.Unicode(30)),
- sa.Column("delete_reason_public", types.Unicode),
- )
-
-
-# Old table definition
-# - version 1.2
-wrsleddingcache_table1_2 = sa.Table("wrsleddingcache1_2", meta.metadata,
- sa.Column("page_id", types.Integer, primary_key=True),
- sa.Column("page_title", types.Unicode(255)),
- sa.Column("length", types.Integer),
- sa.Column("walktime", types.Integer),
- sa.Column("height_top", types.Integer),
- sa.Column("height_bottom", types.Integer),
- sa.Column("walkup_separate", types.Boolean),
- sa.Column("lift", types.Boolean),
- sa.Column("night_light", types.Boolean),
- sa.Column("sledge_rental", types.Boolean),
- sa.Column("public_transport", types.Boolean),
- sa.Column("image", types.Unicode(255)),
- sa.Column("position_latitude", types.Float),
- sa.Column("position_longitude", types.Float),
- sa.Column("information", types.Unicode(255)),
- sa.Column("forum_id", types.Integer),
- sa.Column("under_construction", types.Boolean),
- sa.Column("show_in_overview", types.Boolean),
- )
-
-
-# Old table definition
-# - version 1.3 (changes made from version 1.2)
-wrsleddingcache_table1_3 = sa.Table("wrsleddingcache1_3", meta.metadata,
- sa.Column("page_id", types.Integer, primary_key=True),
- sa.Column("page_title", types.Unicode(255)),
- sa.Column("position_latitude", types.Float),
- sa.Column("position_longitude", types.Float),
- sa.Column("top_latitude", types.Float),
- sa.Column("top_longitude", types.Float),
- sa.Column("top_elevation", types.Integer),
- sa.Column("bottom_latitude", types.Float),
- sa.Column("bottom_longitude", types.Float),
- sa.Column("bottom_elevation", types.Integer),
- sa.Column("length", types.Integer),
- sa.Column("difficulty", types.Integer),
- sa.Column("avalanches", types.Integer),
- sa.Column("operator", types.Unicode(255)),
- sa.Column("public_transport", types.Integer),
- sa.Column("walkup_time", types.Integer),
- sa.Column("walkup_separate", types.Float),
- sa.Column("walkup_separate_comment", types.Unicode(255)),
- sa.Column("lift", types.Boolean),
- sa.Column("lift_details", types.Unicode(255)),
- sa.Column("night_light", types.Float),
- sa.Column("night_light_comment", types.Unicode(255)),
- sa.Column("night_light_days", types.Integer),
- sa.Column("night_light_days_comment", types.Unicode(255)),
- sa.Column("sled_rental", types.Boolean),
- sa.Column("sled_rental_comment", types.Unicode(255)),
- sa.Column("cachet", types.Unicode(255)),
- sa.Column("information_web", types.Unicode(255)),
- sa.Column("information_phone", types.Unicode(255)),
- sa.Column("image", types.Unicode(255)),
- sa.Column("show_in_overview", types.Boolean),
- sa.Column("forum_id", types.Integer),
- sa.Column("under_construction", types.Boolean),
- )
-
-
-# Current table definition
-# - version 1.4 (renamed table and added column walkup_possible)
-wrsledruncache_table = sa.Table("wrsledruncache", meta.metadata,
- sa.Column("page_id", types.Integer, primary_key=True),
- sa.Column("page_title", types.Unicode(255)),
- sa.Column("position_latitude", types.Float),
- sa.Column("position_longitude", types.Float),
- sa.Column("top_latitude", types.Float),
- sa.Column("top_longitude", types.Float),
- sa.Column("top_elevation", types.Integer),
- sa.Column("bottom_latitude", types.Float),
- sa.Column("bottom_longitude", types.Float),
- sa.Column("bottom_elevation", types.Integer),
- sa.Column("length", types.Integer),
- sa.Column("difficulty", types.Integer),
- sa.Column("avalanches", types.Integer),
- sa.Column("operator", types.Unicode(255)),
- sa.Column("public_transport", types.Integer),
- sa.Column("walkup_possible", types.Boolean),
- sa.Column("walkup_time", types.Integer),
- sa.Column("walkup_separate", types.Float),
- sa.Column("walkup_separate_comment", types.Unicode(255)),
- sa.Column("lift", types.Boolean),
- sa.Column("lift_details", types.Unicode(255)),
- sa.Column("night_light", types.Float),
- sa.Column("night_light_comment", types.Unicode(255)),
- sa.Column("night_light_days", types.Integer),
- sa.Column("night_light_days_comment", types.Unicode(255)),
- sa.Column("sled_rental", types.Boolean),
- sa.Column("sled_rental_comment", types.Unicode(255)),
- sa.Column("cachet", types.Unicode(255)),
- sa.Column("information_web", types.Unicode(255)),
- sa.Column("information_phone", types.Unicode(255)),
- sa.Column("image", types.Unicode(255)),
- sa.Column("show_in_overview", types.Boolean),
- sa.Column("forum_id", types.Integer),
- sa.Column("under_construction", types.Boolean),
- )
-
-
-# Old table definition
-# - version 1.2
-wrinncache_table1_2 = sa.Table("wrinncache1_2", meta.metadata,
- sa.Column("page_id", types.Integer, primary_key=True),
- sa.Column("page_title", types.Unicode(255)),
- sa.Column("height", types.Integer),
- sa.Column("phone", types.Unicode(30)),
- sa.Column("mobile_phone", types.Unicode(30)),
- sa.Column("email", types.Unicode(255)),
- sa.Column("homepage", types.Unicode(255)),
- sa.Column("smoker_area", types.Boolean),
- sa.Column("nonsmoker_area", types.Boolean),
- sa.Column("image", types.Unicode(255)),
- sa.Column("position_latitude", types.Float),
- sa.Column("position_longitude", types.Float),
- sa.Column("under_construction", types.Boolean),
- )
-
-
-# Current table definition
-# - version 1.3 (changes made from version 1.2)
-# - version 1.4 (no changes)
-wrinncache_table = sa.Table("wrinncache", meta.metadata,
- sa.Column("page_id", types.Integer, primary_key=True),
- sa.Column("page_title", types.Unicode(255)),
- sa.Column("position_latitude", types.Float),
- sa.Column("position_longitude", types.Float),
- sa.Column("position_elevation", types.Integer),
- sa.Column("seats", types.Integer),
- sa.Column("overnight", types.Boolean),
- sa.Column("overnight_comment", types.Unicode(255)),
- sa.Column("smoker_area", types.Boolean),
- sa.Column("nonsmoker_area", types.Boolean),
- sa.Column("sled_rental", types.Boolean),
- sa.Column("sled_rental_comment", types.Unicode(255)),
- sa.Column("mobile_provider", types.Unicode),
- sa.Column("homepage", types.Unicode(255)),
- sa.Column("email_list", types.Unicode),
- sa.Column("phone_list", types.Unicode),
- sa.Column("image", types.Unicode(255)),
- sa.Column("sledding_list", types.Unicode),
- sa.Column("under_construction", types.Boolean),
- )
-
-
-page_table = sa.Table("page", meta.metadata,
- sa.Column("page_id", types.Integer, primary_key=True),
- sa.Column("page_namespace", types.Integer, nullable=False),
- sa.Column("page_title", types.Unicode(255), nullable=False),
- sa.Column("page_restrictions", types.Unicode, nullable=False),
- sa.Column("page_counter", types.Integer, nullable=False),
- sa.Column("page_is_redirect", types.Integer, nullable=False),
- sa.Column("page_is_new", types.Integer, nullable=False),
- sa.Column("page_random", types.Float, nullable=False),
- sa.Column("page_touched", types.Unicode(14), nullable=False),
- sa.Column("page_latest", types.Integer, nullable=False),
- sa.Column("page_len", types.Integer, nullable=False),
- )
-
-
-revision_table = sa.Table("revision", meta.metadata,
- sa.Column("rev_id", types.Integer, nullable=False, primary_key=True),
- sa.Column("rev_page", types.Integer, nullable=False, primary_key=True),
- sa.Column("rev_text_id", types.Integer, nullable=False),
- sa.Column("rev_comment", types.Unicode),
- sa.Column("rev_user", types.Integer, nullable=False),
- sa.Column("rev_user_text", types.Unicode(255), nullable=False),
- sa.Column("rev_timestamp", types.Unicode(14), nullable=False),
- sa.Column("rev_minor_edit", types.Integer, nullable=False),
- sa.Column("rev_deleted", types.Integer, nullable=False),
- sa.Column("rev_len", types.Integer, nullable=False),
- sa.Column("rev_parent_id", types.Integer, nullable=False),
- )
-
-
-text_table = sa.Table("text", meta.metadata,
- sa.Column("old_id", types.Integer, primary_key=True),
- sa.Column("old_text", types.Unicode),
- sa.Column("old_flags", types.Unicode),
- )
-
+wrreport_table = mwwrdb.wrreport_table(meta.metadata)
+wrsledruncache_table = mwwrdb.wrsledruncache_table(meta.metadata)
+wrinncache_table = mwwrdb.wrinncache_table(meta.metadata)
+page_table = mwdb.page_table(meta.metadata)
+revision_table = mwdb.revision_table(meta.metadata)
+text_table = mwdb.text_table(meta.metadata)
+categorylinks_table = mwdb.categorylinks_table(meta.metadata)
-categorylinks_table = sa.Table("categorylinks", meta.metadata,
- sa.Column("cl_from", types.Integer, nullable=False, primary_key=True),
- sa.Column("cl_to", types.Unicode(255), nullable=False, primary_key=True),
- sa.Column("cl_sortkey", types.Unicode, nullable=False),
- sa.Column("cl_timestamp", types.DateTime, nullable=False),
- )
class WrReport(object):
import wradmin.model
-def test_wikipage_to_wrsleddingcache1_2():
- page_id = 7
- page_title = u"Kemater Alm"
- old_text = u"""
-Text above
-{{Rodelbahnbox
-| Bild = Rodelbahn_Mitterer_Alm_04.jpg
-| Position = 47.203959 N 11.308052 E
-| Länge = 3500
-| Gehzeit = 90
-| Höhe oben = 2000
-| Höhe unten = 1200
-| Aufstieg getrennt = Ja
-| Lift = Nein
-| Beleuchtung = Nein
-| Rodelverleih = Ja
-| Öffentliche Anreise = Nein
-| Lawinengefahr = kaum
-| Auskunft = 0664/5487520 (Mitterer Alm)
-| In Übersichtskarte = Ja
-}}
-Text below"""
- sledding_cache = wradmin.lib.mediawiki.wikipage_to_wrsleddingcache1_2(page_id, page_title, old_text)
- assert sledding_cache.page_id == 7
- assert sledding_cache.page_title == u"Kemater Alm"
- assert sledding_cache.length == 3500
- assert sledding_cache.walktime == 90
- assert sledding_cache.height_top == 2000
- assert sledding_cache.height_bottom == 1200
- assert sledding_cache.walkup_separate == True
- assert sledding_cache.lift == False
- assert sledding_cache.night_light == False
- assert sledding_cache.sledge_rental == True
- assert sledding_cache.public_transport == False
- assert sledding_cache.image == u"Rodelbahn_Mitterer_Alm_04.jpg"
- assert sledding_cache.position_latitude == 47.203959
- assert sledding_cache.position_longitude == 11.308052
- assert sledding_cache.information == u"+43/664/5487520 (Mitterer Alm)"
- # assert sledding_cache.forum_id
- # assert sledding_cache.under_construction
- assert sledding_cache.show_in_overview == True
-
-
-def test_wikipage_to_wrsleddingcache():
- page_id = 7
- page_title = u"Kemater Alm"
- old_text = u"""
-Text above
-{{Rodelbahnbox
-| Position = 47.203959 N 11.308052 E
-| Position oben =
-| Höhe oben = 1700
-| Position unten = 47.200959 N 11.309052 E
-| Höhe unten = 1200
-| Länge = 3500
-| Schwierigkeit = mittel
-| Lawinen = kaum
-| Betreiber = Max Mustermann
-| Öffentliche Anreise = Mittelmäßig
-| Gehzeit = 90
-| Aufstieg getrennt = Ja
-| Aufstiegshilfe = Gondel (unterer Teil)
-| Beleuchtungsanlage = Ja
-| Beleuchtungstage = 3 (Montag, Mittwoch, Freitag)
-| Rodelverleih = Talstation Serlesbahnan
-| Gütesiegel = Tiroler Naturrodelbahn-Gütesiegel 2009 mittel
-| Webauskunft = http://www.nösslachhütte.at/page9.php
-| Telefonauskunft = +43-664-5487520 (Mitterer Alm)
-| Bild = Rodelbahn_Mitterer_Alm_04.jpg
-| In Übersichtskarte = Ja
-| Forumid = 33
-}}
-Text below"""
- sledding_cache = wradmin.lib.mediawiki.wikipage_to_wrsleddingcache(page_id, page_title, old_text)
- assert sledding_cache.page_id == 7
- assert sledding_cache.page_title == u"Kemater Alm"
- assert sledding_cache.position_latitude == 47.203959
- assert sledding_cache.position_longitude == 11.308052
- assert sledding_cache.top_latitude == None
- assert sledding_cache.top_longitude == None
- assert sledding_cache.top_elevation == 1700
- assert sledding_cache.bottom_latitude == 47.200959
- assert sledding_cache.bottom_longitude == 11.309052
- assert sledding_cache.bottom_elevation == 1200
- assert sledding_cache.length == 3500
- assert sledding_cache.difficulty == 2
- assert sledding_cache.avalanches == 1
- assert sledding_cache.operator == u'Max Mustermann'
- assert sledding_cache.public_transport == 3
- assert sledding_cache.walkup_time == 90
- assert sledding_cache.walkup_separate == 1.0
- assert sledding_cache.walkup_separate_comment == None
- assert sledding_cache.lift == True
- assert sledding_cache.lift_details == u'Gondel (unterer Teil)'
- assert sledding_cache.night_light == 1.0
- assert sledding_cache.night_light_comment == None
- assert sledding_cache.night_light_days == 3
- assert sledding_cache.night_light_days_comment == u'Montag, Mittwoch, Freitag'
- assert sledding_cache.sled_rental == True
- assert sledding_cache.sled_rental_comment == u'Talstation Serlesbahnan'
- assert sledding_cache.cachet == u'Tiroler Naturrodelbahn-Gütesiegel 2009 mittel'
- assert sledding_cache.information_web == u'http://www.nösslachhütte.at/page9.php'
- assert sledding_cache.information_phone == u'+43-664-5487520 (Mitterer Alm)'
- assert sledding_cache.image == u"Rodelbahn_Mitterer_Alm_04.jpg"
- assert sledding_cache.show_in_overview == True
- assert sledding_cache.forum_id == 33
- assert sledding_cache.under_construction == None
-
-
-def test_wikipage_to_wrinncache1_2():
- page_id = 10
- page_title = u"Kemater Alm (Gasthaus)"
- old_text = u"""
-Text above
-{{Gasthausbox
-| Bild = Rodelbahn_Birgitzer_Alm_01.jpg
-| Position = 47.123456 N 11.123456 E
-| Höhe = 1808
-| Telefon (Festnetz) =
-| Telefon (Mobil) = +43/664/5487520
-| Homepage = http://www.birgitzeralm.at/
-| E-Mail = office@example.com
-| Rauchfrei = Ja
-}}
-Text below"""
- inn_cache = wradmin.lib.mediawiki.wikipage_to_wrinncache1_2(page_id, page_title, old_text)
-
-
-def test_wikipage_to_wrinncache():
- page_id = 10
- page_title = u"Kemater Alm (Gasthaus)"
- old_text = u"""
-Text above
-{{Gasthausbox
-| Position = 47.123456 N 11.123456 E
-| Höhe = 1808
-| Betreiber = Max Mustermann
-| Sitzplätze = 50
-| Übernachtung = 20 Matrazenlager, 3 Doppelzimmer
-| Rauchfrei = Ja
-| Rodelverleih = 2 Euro (Ausweis erforderlich, Reservierung erwünscht)
-| Handyempfang = A1; T-Mobile A
-| Homepage = http://www.birgitzeralm.at/
-| E-Mail = Nein
-| Telefon = +43-664-5487520 (Birgitzer Alm); +43-512-123456 (wenn geschlossen)
-| Bild = Rodelbahn_Birgitzer_Alm_01.jpg
-| Rodelbahnen = [[Kemater Alm]]; [[Birgitzer Alm]]
-}}
-Text below"""
- inn_cache = wradmin.lib.mediawiki.wikipage_to_wrinncache(page_id, page_title, old_text)
-
def _test_mediawiki_users():
users = wradmin.lib.mediawiki.MediaWikiUsers(True)