FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
fastapi-admin/fastapi_admin/template.py at dev · zinating/fastapi-admin · GitHub
zinating
fastapi-admin
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
fastapi-admin
/
fastapi_admin
/
template.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
38 lines (27 loc) · 1.12 KB
Breadcrumbs
fastapi-admin
/
fastapi_admin
/
template.py
Copy path
File metadata and controls
38 lines (27 loc) · 1.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
from
datetime
import
date
from
typing
import
Any
from
urllib
.
parse
import
urlencode
from
jinja2
import
pass_context
from
starlette
.
requests
import
Request
from
starlette
.
templating
import
Jinja2Templates
from
fastapi_admin
import
VERSION
from
fastapi_admin
.
constants
import
BASE_DIR
templates
=
Jinja2Templates
(
directory
=
os
.
path
.
join
(
BASE_DIR
,
"templates"
))
templates
.
env
.
globals
[
"VERSION"
]
=
VERSION
templates
.
env
.
globals
[
"NOW_YEAR"
]
=
date
.
today
().
year
templates
.
env
.
add_extension
(
"jinja2.ext.i18n"
)
@
pass_context
def
current_page_with_params
(
context
:
dict
,
params
:
dict
):
request
=
context
.
get
(
"request"
)
# type:Request
full_path
=
request
.
scope
[
"raw_path"
].
decode
()
query_params
=
dict
(
request
.
query_params
)
for
k
,
v
in
params
.
items
():
query_params
[
k
]
=
v
return
full_path
+
"?"
+
urlencode
(
query_params
)
templates
.
env
.
filters
[
"current_page_with_params"
]
=
current_page_with_params
def
set_global_env
(
name
:
str
,
value
:
Any
):
templates
.
env
.
globals
[
name
]
=
value
def
add_template_folder
(
*
folders
:
str
):
for
folder
in
folders
:
templates
.
env
.
loader
.
searchpath
.
insert
(
0
,
folder
)
Back
|
FazBrowse Home
|
New Git URL