Giving a sample page

This commit is contained in:
Dita Aji Pratama 2025-03-15 04:14:02 +07:00
parent a16a31f46b
commit 7ad3f98471
4 changed files with 319 additions and 1 deletions

View File

@ -1,7 +1,8 @@
from core import template from core import template
page = { page = {
'public' :'pages/public' 'public' :'pages/public',
'sample' :'pages/sample'
} }
static = [ static = [

View File

@ -9,7 +9,9 @@ from bottle import Bottle, route
from config import directory from config import directory
import templates.plain.main as template_public import templates.plain.main as template_public
import templates.prime.main as template_sample_prime
import modules.public.home as public_home import modules.public.home as public_home
import modules.sample.prime as sample_prime
app = Bottle() app = Bottle()
@ -21,3 +23,13 @@ def index():
} }
} }
return public_home.main().html(params) return public_home.main().html(params)
@app.route('/sample/prime')
def index():
params = {
"mako":{
"website" : template_sample_prime.main(directory.page["sample"], "prime")
}
}
return sample_prime.main().html(params)

125
modules/sample/prime.py Normal file
View File

@ -0,0 +1,125 @@
from mako.template import Template
from config import globalvar
class main:
def __init__(self):
pass
def html(self, params):
title = "CostaPy"
user_roles = [1,2] # A roles that user have
active_page = "Sample" # Current active page name
copyright = "Copyright (C) 2022 Dita Aji Pratama"
greeting = "A prime dashboard based on bootstrap 5"
menu_navbar = [
{
"name":"Home",
"target":"_self",
"href":"#",
"notification":0,
"roles":[1,2]
},
{
"name":"Customize",
"href":"#",
"target":"_self",
"notification":0,
"roles":[1,2]
},
{
"name":"Notification",
"href":"#",
"target":"_self",
"notification":1,
"roles":[1,2]
}
]
menu_profile = {
"picture": "https://ditaajipratama.net/img/no-profile-donut.png",
"name" : "Dita Aji Pratama",
"menu" : [
{
"name" :"Profile",
"href" :"/profile",
"target":"_self",
"roles" :[1,2]
},
{
"name" :"Settings",
"href" :"/settings",
"target":"_self",
"roles" :[1,2]
},
{
"name" :"Logout",
"href" :"/logout",
"target":"_self",
"roles" :[1,2,3]
}
]
}
menu_sidebar = [
{
"icon":"fa-solid fa-gauge",
"name":"Dashboard",
"target":"_self",
"href":"#",
"roles":[1,2]
},
{
"icon":"fa-solid fa-users",
"name":"Users",
"target":"_self",
"href":"#",
"roles":[1,2]
},
{
"icon":"fa-solid fa-book",
"name":"Items",
"target":"_self",
"href":"#",
"roles":[1,2]
},
{
"icon":"fa-solid fa-book",
"name":"Analytic",
"target":"_self",
"href":"#",
"roles":[1,2]
},
{
"icon":"fa-solid fa-book",
"name":"Reports",
"target":"_self",
"href":"#",
"roles":[1,2]
}
]
return Template(params["mako"]["website"]['index']).render(
title = title,
navbar = Template(params["mako"]["website"]['navbar']).render(
title = title,
menu = menu_navbar,
profile = menu_profile,
user_roles = user_roles,
active_page = active_page
),
sidebar = Template(params["mako"]["website"]['sidebar']).render(
menu = menu_sidebar,
user_roles = user_roles,
active_page = active_page
),
footer = Template(params["mako"]["website"]['footer']).render(
copyright = copyright,
),
container = Template(params["mako"]["website"]['container']).render(
greeting = greeting
)
)

180
pages/sample/prime.html Normal file
View File

@ -0,0 +1,180 @@
<div class="container">
<h1>CostaPy Template - Prime</h1>
<p>${greeting}</p>
<h2>Usage</h2>
<ul>
<li><p>Put the folder in your <code>templates</code> directory</p></li>
<li>
<p>Add to handler</p>
<code>
import templates.prime.main as template_dashboard
params["mako"] = {
"website" : template_dashboard.main("pages/dashboard", "users")
}
</code>
</li>
<li>
- Define a necessary variable on your modules
```python
title = "CostaPy"
user_roles = [1,2] # A roles that user have
active_page = "Users" # Current active page name
copyright = "Copyright (C) 2022 Dita Aji Pratama"
greeting = "Hello world"
```
</li>
<li>
- Define a navbar menu on your modules
```python
menu_navbar = [
{
"name":"Home",
"target":"_self",
"href":"#",
"notification":0,
"roles":[1,2]
},
{
"name":"Customize",
"href":"#",
"target":"_self",
"notification":0,
"roles":[1,2]
},
{
"name":"Notification",
"href":"#",
"target":"_self",
"notification":1,
"roles":[1,2]
}
]
```
</li>
<li>
- Define a profile menu on your modules
```python
menu_profile = {
"picture" : "https://ditaajipratama.net/img/no-profile-donut.png",
"name" : "Dita Aji Pratama",
"menu" : [
{
"name" :"Profile",
"href" :"/profile",
"target":"_self",
"roles":[1,2]
},
{
"name" :"Settings",
"href" :"/settings",
"target":"_self",
"roles":[1,2]
},
{
"name" :"Logout",
"href" :"/logout",
"target":"_self",
"roles":[1,2,3]
}
]
}
```
</li>
<li>
- Define a sidebar menu on your modules
```python
menu_sidebar = [
{
"icon":"fa-solid fa-gauge",
"name":"Dashboard",
"target":"_self",
"href":"#",
"roles":[1,2]
},
{
"icon":"fa-solid fa-users",
"name":"Users",
"target":"_self",
"href":"#",
"roles":[1,2]
},
{
"icon":"fa-solid fa-book",
"name":"Items",
"target":"_self",
"href":"#",
"roles":[1,2]
},
{
"icon":"fa-solid fa-book",
"name":"Analytic",
"target":"_self",
"href":"#",
"roles":[1,2]
},
{
"icon":"fa-solid fa-book",
"name":"Reports",
"target":"_self",
"href":"#",
"roles":[1,2]
}
]
```
</li>
<li>
- Set a template on your modules
```python
return Template(params["mako"]["website"]['index']).render(
title = title,
navbar = Template(params["mako"]["website"]['navbar']).render(
title = title,
menu = menu_navbar,
profile = menu_profile,
user_roles = user_roles,
active_page = active_page
),
sidebar = Template(params["mako"]["website"]['sidebar']).render(
menu = menu_sidebar,
user_roles = user_roles,
active_page = active_page
),
footer = Template(params["mako"]["website"]['footer']).render(
copyright = copyright,
),
container = Template(params["mako"]["website"]['container']).render(
greeting = greeting
)
)
```
</li>
</ul>
<h2>License</h2>
<p>MIT License</p>
<p>Copyright (c) 2024 Dita Aji Pratama</p>
<p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p>
<p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>
<p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
</div>