Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
Nuovo sito
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
16
Issues
16
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gruppo Web
Nuovo sito
Commits
c47806e8
Commit
c47806e8
authored
Apr 29, 2018
by
Pietro Albini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an SQLite database
parent
45a28f05
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
1 deletion
+81
-1
uitwww/__init__.py
uitwww/__init__.py
+5
-0
uitwww/db.py
uitwww/db.py
+75
-0
uitwww/templates/layout.html
uitwww/templates/layout.html
+1
-1
No files found.
uitwww/__init__.py
View file @
c47806e8
...
...
@@ -18,6 +18,7 @@ import os
import
flask
from
.
import
db
from
.
import
pages
from
.
import
cache
from
.
import
utils
...
...
@@ -42,6 +43,10 @@ def create_app(data_path):
with
open
(
os
.
path
.
join
(
data_path
,
"secret_key"
))
as
f
:
app
.
secret_key
=
f
.
read
().
strip
()
# Initialize the database
app
.
db
=
db
.
Database
(
os
.
path
.
join
(
data_path
,
"database.db"
))
app
.
db
.
init
()
app
.
config
[
"CACHE_PATH"
]
=
os
.
path
.
join
(
data_path
,
"cache"
)
cache
.
install_cache
(
app
)
...
...
uitwww/db.py
0 → 100644
View file @
c47806e8
# Source code of the Ubuntu-it website
# Copyright (C) 2015 Pietro Albini <pietroalbini@ubuntu.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; witout even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
threading
import
sqlite3
import
pkg_resources
_LOCAL
=
threading
.
local
()
class
Database
:
def
__init__
(
self
,
path
):
self
.
_path
=
path
def
init
(
self
):
"""Initialize the database"""
db_version
=
int
(
self
.
query
(
"PRAGMA user_version;"
)[
0
][
0
])
cursor
=
self
.
cursor
()
if
db_version
==
0
:
cursor
.
executescript
(
"""
CREATE TABLE migrations (name TEXT PRIMARY KEY);
PRAGMA user_version = 1;
"""
)
applied
=
[
m
[
0
]
for
m
in
self
.
query
(
"SELECT * FROM migrations;"
)]
for
name
,
sql
in
MIGRATIONS
:
if
name
in
applied
:
continue
cursor
.
executescript
(
sql
)
cursor
.
execute
(
"INSERT INTO migrations (name) VALUES (?)"
,
[
name
])
cursor
.
connection
.
commit
()
def
cursor
(
self
):
"""Get a new cursor"""
if
not
hasattr
(
_LOCAL
,
"db"
):
_LOCAL
.
db
=
sqlite3
.
connect
(
self
.
_path
)
return
_LOCAL
.
db
.
cursor
()
def
query
(
self
,
query
,
*
params
,
update
=
False
):
"""Make a new query against the db"""
cursor
=
self
.
cursor
()
cursor
.
execute
(
query
,
params
)
try
:
if
update
:
cursor
.
connection
.
commit
()
else
:
return
cursor
.
fetchall
()
finally
:
cursor
.
close
()
def
update
(
self
,
query
,
*
params
):
"""Make a new update query against the db"""
self
.
query
(
query
,
*
params
,
update
=
True
)
MIGRATIONS
=
[]
uitwww/templates/layout.html
View file @
c47806e8
...
...
@@ -95,7 +95,7 @@
Sito web realizzato dal Gruppo Web di Ubuntu-it, con
<a
href=
"https://www.python.org/"
>
Python
</a>
,
<a
href=
"https://www.palletsproject.com/p/flask/"
>
Flask
</a>
e
<a
href=
"http
://www.postgresql.org/"
>
PostgreSQL
</a>
.
<a
href=
"http
s://www.sqlite.org/"
>
SQLite
</a>
.
</p>
<ul>
<li><a
href=
"{{ url_for("
pages
.
cookies
")
}}"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment