pvl/verkko/web.py
author Tero Marttila <terom@paivola.fi>
Sat, 26 Jan 2013 17:52:40 +0200
changeset 178 f9f5e669bace
parent 158 3ff66d4f401c
permissions -rw-r--r--
pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
3
5990b188c54b web.Handler
Tero Marttila <terom@paivola.fi>
parents: 1
diff changeset
     1
# encoding: utf-8
178
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
     2
import pvl.web
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
     3
from pvl.web import html, urls
7
7baf4cccb4a9 move Index to urls; fix self.url(sort=...)
Tero Marttila <terom@paivola.fi>
parents: 6
diff changeset
     4
178
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
     5
import logging; log = logging.getLogger('pvl.verkko.web')
4
Tero Marttila <terom@paivola.fi>
parents: 3
diff changeset
     6
178
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
     7
class DatabaseHandler (pvl.web.Handler) :
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
     8
    """
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
     9
        Request handler with pvl.verkko.Database session
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
    10
    """
0
91c739202f06 initial code for dhcp hosts
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    11
7
7baf4cccb4a9 move Index to urls; fix self.url(sort=...)
Tero Marttila <terom@paivola.fi>
parents: 6
diff changeset
    12
    def __init__ (self, app, request, urls, params) :
178
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
    13
        super(DatabaseHandler, self).__init__(app, request, urls, params)
3
5990b188c54b web.Handler
Tero Marttila <terom@paivola.fi>
parents: 1
diff changeset
    14
16
51509b5ce1c0 request per session, move to postgres, rename columns, fixup state/name/error handling in updates
Tero Marttila <terom@paivola.fi>
parents: 7
diff changeset
    15
        # new ORM session per request
51509b5ce1c0 request per session, move to postgres, rename columns, fixup state/name/error handling in updates
Tero Marttila <terom@paivola.fi>
parents: 7
diff changeset
    16
        self.db = app.db.session() 
6
0f243c59d5d1 build urls
Tero Marttila <terom@paivola.fi>
parents: 5
diff changeset
    17
26
589249097230 hosts: convert realtime list into table; breaks animations :(
Tero Marttila <terom@paivola.fi>
parents: 24
diff changeset
    18
    def cleanup (self) :
589249097230 hosts: convert realtime list into table; breaks animations :(
Tero Marttila <terom@paivola.fi>
parents: 24
diff changeset
    19
        """
151
8a9f01036091 split pvl.web from pvl.verkko, rename test.py -> pvl.verkko-dhcp
Tero Marttila <terom@paivola.fi>
parents: 26
diff changeset
    20
            After request processing.
26
589249097230 hosts: convert realtime list into table; breaks animations :(
Tero Marttila <terom@paivola.fi>
parents: 24
diff changeset
    21
        """
589249097230 hosts: convert realtime list into table; breaks animations :(
Tero Marttila <terom@paivola.fi>
parents: 24
diff changeset
    22
        
589249097230 hosts: convert realtime list into table; breaks animations :(
Tero Marttila <terom@paivola.fi>
parents: 24
diff changeset
    23
        # XXX: SQLAlchemy doesn't automatically close these...?
589249097230 hosts: convert realtime list into table; breaks animations :(
Tero Marttila <terom@paivola.fi>
parents: 24
diff changeset
    24
        self.db.close()
178
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
    25
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
    26
class Application (pvl.web.Application) :
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
    27
    """
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
    28
        Application with pvl.verkko.Database
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
    29
    """
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
    30
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
    31
    def __init__ (self, db, **opts) :
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
    32
        """
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
    33
            db      - pvl.verkko.Database
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
    34
        """
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
    35
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
    36
        super(Application, self).__init__(**opts)
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
    37
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
    38
        self.db = db
f9f5e669bace pvl.verkko: refactor into dhcp -> hosts -> web+db modules, reworking index page
Tero Marttila <terom@paivola.fi>
parents: 158
diff changeset
    39