Conversion tool is near from complete. Use Peewee as ORM
This commit is contained in:
parent
451bf1915e
commit
7441a80217
7 changed files with 140 additions and 19 deletions
39
app/services/database.py
Normal file
39
app/services/database.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
import hashlib
|
||||
import config
|
||||
import functools
|
||||
from config import DB_URL
|
||||
from playhouse.db_url import connect
|
||||
|
||||
|
||||
def get_db():
|
||||
return connect(DB_URL)
|
||||
|
||||
|
||||
def provide_db(func):
|
||||
|
||||
@functools.wraps(func)
|
||||
def new_function(*args, **kwargs):
|
||||
return func(get_db(), *args, **kwargs)
|
||||
|
||||
return new_function
|
||||
|
||||
|
||||
def hash(value):
|
||||
string = '%s%s' % (value, config.SALT)
|
||||
dk = hashlib.sha256(string.encode())
|
||||
return dk.hexdigest()
|
||||
|
||||
|
||||
@provide_db
|
||||
def setup(db):
|
||||
from app.models.user import User
|
||||
db.create_tables([User], safe=True)
|
||||
|
||||
# create admin user if user table is empty
|
||||
if User.select().count() == 0:
|
||||
admin_user = User(username='admin', password=hash('admin'),
|
||||
displayname='Admin')
|
||||
admin_user.save()
|
||||
Loading…
Add table
Add a link
Reference in a new issue