PaferaPy Async 0.1
ASGI framework focused on simplicity and efficiency
Loading...
Searching...
No Matches
initsite.py
Go to the documentation of this file.
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4import os
5import json
6
7from pafera.db import DB
8
9from apps.system.user import *
10from apps.system.group import *
11from apps.system.page import *
12from apps.system.session import *
13
14# =====================================================================
16 """Creates all default settings and saves them to the configuration file.
17 """
18
19 g.siteconfig = {
20 "dbtype": "sqlite",
21 "dbhost": "localhost",
22 "dbname": "private/system/default.db",
23 "dbflags": 0,
24 "dbuser": "",
25 "dbpassword": "",
26 "cssfiles": [
27 "/system/normalize.css",
28 "/system/colors.css",
29 "/system/common.css",
30 "/system/paferalib.css",
31 "/system/pafera.css",
32 ],
33 "jsfiles": [
34 "/system/loader.min.js",
35 "/system/minified.min.js",
36 "/system/stacktrace.min.js",
37 "/system/hammer.min.js",
38 "/system/paferalib.js",
39 "/system/paferadbobj.js",
40 "/system/paferapage.js",
41 "/system/pafera.js",
42 ],
43 "languages": [
44 "en",
45 "zh",
46 ],
47 'sessiontimeout': 604800,
48 'urltracking': 1,
49 'production': 0,
50 'htmlcachetime': 10,
51 }
52
53 os.makedirs('private/system', exist_ok = True)
54
55 with open('private/system/pafera.cfg', 'w') as f:
56 f.write(json.dumps(g.siteconfig, sort_keys = True, indent = 2))
57
58# =====================================================================
59def InitDB(g):
60 """Setups the initial database users, groups, and pages.
61 """
62 db = g.db
63
64 if db.HasTable('system_user'):
65 return
66
67 db.RegisterModel(system_session)
68
69 u = system_user()
70 u.Set(
71 phonenumber = 'admin',
72 place = 'pafera',
73 displayname = {'en': 'admin'}
74 )
75 u.SetPassword('password', 'pafera')
76 db.Insert(u)
77
78 admins = system_group()
79 admins.Set(
80 groupname = 'admins',
81 displayname = {'en': 'Administrators'}
82 )
83 db.Insert(admins)
84
85 db.Link(u, admins)
86
87 siteheader = system_pagefragment()
88 siteheader.Set(
89 path = 'site.header',
90 size = 'auto',
91 content = {
92 'en': """
93 <div class="SiteHeader Flex FlexCenter white">
94 <div class="SiteHeader Flex FlexCenter white">
95 <a href="/">
96 <img src="/favicon.ico" style="height: 2em; float: left;">
97 <span style="display: block; padding: 0.3em; float: left;">Pafera</span>
98 </a>
99 <a href="/system/controlpanel.html">Control Panel</a>
100 <a href="/system/translations.html">Translations</a>
101 <a class="LoginLink" href="/system/login.html">Login</a>
102 </div>
103""",
104 },
105 contentfunc = "",
106 )
107
108 db.Insert(siteheader)
109
110 sitefooter = system_pagefragment()
111 sitefooter.Set(
112 path = 'site.footer',
113 size = 'auto',
114 content = {
115 'en': """
116 <div class="SiteFooter Center white Pad50">
117 This site is powered by the Pafera WSGI Framework available at <a href="https://pafera.com/pafera">pafera.com/pafera</a>.
118 </div>
119""",
120 },
121 contentfunc = "",
122 )
123
124 db.Insert(sitefooter)
125
126 p = system_page()
127 p.Set(
128 path = '/system/index.html',
129 title = {
130 'en': 'Welcome to Pafera!',
131 },
132 content = {
133 'en': """
134 <div class="Grid GridCenter MinHeight80P">
135 <div class="Center Margin25">
136 <h1 class="Center">Welcome to Pafera!</h1>
137
138 <div class="whiteb Rounded Raised MaxWidth2400 Pad100 Left">
139 If you can see this page, then your install was successful. Please head to the <a href="/system/controlpanel">control panel</a> to start configuring your site.
140 </div>
141 </div>
142 </div>
143""",
144 },
145 contentfunc = "",
146 topbarid = siteheader.rid,
147 bottombarid = sitefooter.rid,
148 })
149
150 db.Insert(p)
151
152 p = system_page()
153 p.Set(
154 path = '/system/controlpanel.html',
155 title = {
156 'en': 'Welcome to Your New Pafera Install',
157 },
158 content = {
159 'en': """
160<div class="Pad50 white">
161 <h1>Welcome to Your New Pafera Install</h1>
162
163 <p>
164 If you are seeing this screen, then your installation of the Pafera Framework was successful. Let's configure your site and get you on your way.
165 </p>
166
167 <p>
168 Remember to set a new administrator password before doing anything else. The last thing that you want is to have your website start leaking every username and password to the whole world and have a nasty pile of angry lawsuits sitting on your desk.
169 </p>
170</div>
171
172 <div class="ConfigTiles FlexGrid30 Gap50" ></div>
173""",
174 },
175 contentfunc = "",
176 )
177
178 db.Insert(p)
179
180 p = system_page()
181 p.Set(
182 path = '/system/db.html',
183 title = {
184 'en': 'Database Management',
185 },
186 content = {
187 'en': """
188<div class="PageLoadContent"></div>
189""",
190 },
191 contentfunc = "",
192 )
193
194 db.Insert(p)
195
196 p = system_page()
197 p.Set(
198 path = '/system/translations.html',
199 title = {
200 'en': 'Translations',
201 },
202 content = {
203 'en': """
204<h1>Translations</h1>
205
206<div class="ButtonBar TranslationActions"></div>
207
208<div class="Translations"></div>
209
210""",
211 },
212 contentfunc = "",
213 )
214
215 db.Insert(p)
216
217 p = system_page()
218 p.Set(
219 path = '/system/apps.html',
220 title = {
221 'en': 'Apps',
222 },
223 content = {
224 'en': """
225<h1>Apps</h1>
226
227<div class="ButtonBar AppActions"></div>
228
229<div class="AppTiles"></div>
230
231""",
232 },
233 contentfunc = "",
234 )
235
236 db.Insert(p)
237
238 p = system_page()
239 p.Set({
240 path = '/system/login.html',
241 title = {
242 'en': g.T.login,
243 },
244 content = {
245 'en': f"""
246 <div class="Grid GridCenter MinHeight80P">
247 <div class="Center Margin25">
248 <h1 class="Center">{g.T.login}</h1>
249
250 <div class="LoginForm whiteb Rounded Raised MaxWidth2400 Left"></div>
251 </div>
252 </div>
253""",
254 },
255 contentfunc = "",
256 topbarid = siteheader.rid,
257 bottombarid = sitefooter.rid,
258 )
259
260 db.Insert(p)
261
262 p = system_page()
263 p.Set({
264 path = '/system/logout.html',
265 title = {
266 'en': g.T.logout,
267 },
268 content = {
269 'en': f"""
270 <div class="Grid GridCenter MinHeight80P">
271 <div class="Center Margin25">
272 <h1 class="Center">{g.T.logout}</h1>
273
274 <div class="whiteb Rounded Raised Pad100 MaxWidth2400 Left">{g.T.loggedout}</div>
275 </div>
276 </div>
277""",
278 },
279 contentfunc = "g.session.New(g)",
280 topbarid = siteheader.rid,
281 bottombarid = sitefooter.rid,
282 )
283
284 db.Insert(p)
285
286 p = system_page()
287 p.Set({
288 path = '/404.html',
289 title = {
290 'en': g.T.nothingfound,
291 },
292 content = {
293 'en': f"""
294 <div class="Grid GridCenter MinHeight80P">
295 <div class="Center Margin25">
296 <h1>We couldn't find your page.</h1>
297 <p>Please check your URL and try again.</p>
298 </div>
299 </div>
300""",
301 },
302 contentfunc = "",
303 topbarid = siteheader.rid,
304 bottombarid = sitefooter.rid,
305 )
306
307 db.Insert(p)
308
309 db.Commit()
310
Definition: db.py:1
def InitConfig(g)
Creates all default settings and saves them to the configuration file.
Definition: initsite.py:15
def InitDB(g)
Setups the initial database users, groups, and pages.
Definition: initsite.py:59