-
Notifications
You must be signed in to change notification settings - Fork 2
/
bottleext.py
38 lines (28 loc) · 1.16 KB
/
bottleext.py
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
import os
import bottle
from bottle import *
class Route(bottle.Route):
"""
Nadomestni razred za poti s privzetimi imeni.
"""
def __init__(self, app, rule, method, callback, name=None, plugins=None, skiplist=None, **config):
if name is None:
name = callback.__name__
def decorator(*largs, **kwargs):
bottle.request.environ['SCRIPT_NAME'] = os.environ.get('BOTTLE_ROOT', '')
return callback(*largs, **kwargs)
super().__init__(app, rule, method, decorator, name, plugins, skiplist, **config)
def template(*largs, **kwargs):
"""
Izpis predloge s podajanjem funkcije url.
"""
return bottle.template(*largs, **kwargs, url=bottle.url)
def template_user(*largs, **kwargs):
"""
Izpis predloge s podajanjem funkcije url in dodanim uporabnikom ter njegovo.
"""
# Dodamo ime uporabnika, ki je prebran iz cookija direktno v vsak html, ki ga uporabimo kot template.
usr_cookie = request.get_cookie("uporabnik")
usr_role = request.get_cookie("rola")
return bottle.template(*largs, **kwargs, uporabnik=usr_cookie, rola=usr_role, url=bottle.url)
bottle.Route = Route