round 5
This commit is contained in:
4
db/db.py
4
db/db.py
@@ -6,6 +6,7 @@ from tinydb import TinyDB
|
||||
DB_ENV = os.environ.get('DB_ENV', 'prod')
|
||||
base_dir = os.path.dirname(__file__)
|
||||
|
||||
|
||||
class LockedTable:
|
||||
"""
|
||||
Thread-safe wrapper around a TinyDB table. All callable attribute access
|
||||
@@ -98,4 +99,5 @@ if DB_ENV == 'test':
|
||||
task_db.truncate()
|
||||
reward_db.truncate()
|
||||
image_db.truncate()
|
||||
pending_reward_db.truncate()
|
||||
pending_reward_db.truncate()
|
||||
|
||||
|
||||
@@ -82,5 +82,28 @@ def populate_default_data():
|
||||
"rewards": rewards
|
||||
}
|
||||
|
||||
def initializeImages():
|
||||
"""Initialize the image database with default images if empty."""
|
||||
if len(image_db.all()) == 0:
|
||||
image_defs = [
|
||||
('computer-game', IMAGE_TYPE_ICON, '.png', True),
|
||||
('ice-cream', IMAGE_TYPE_ICON, '.png', True),
|
||||
('meal', IMAGE_TYPE_ICON, '.png', True),
|
||||
('playground', IMAGE_TYPE_ICON, '.png', True),
|
||||
('tablet', IMAGE_TYPE_ICON, '.png', True),
|
||||
('boy01', IMAGE_TYPE_PROFILE, '.png', True),
|
||||
('girl01', IMAGE_TYPE_PROFILE, '.png', True),
|
||||
('girl02', IMAGE_TYPE_PROFILE, '.png', True),
|
||||
('boy02', IMAGE_TYPE_PROFILE, '.png', True),
|
||||
('boy03', IMAGE_TYPE_PROFILE, '.png', True),
|
||||
('girl03', IMAGE_TYPE_PROFILE, '.png', True),
|
||||
('boy04', IMAGE_TYPE_PROFILE, '.png', True),
|
||||
('girl04', IMAGE_TYPE_PROFILE, '.png', True),
|
||||
]
|
||||
for _id, _type, ext, perm in image_defs:
|
||||
img = Image(type=_type, extension=ext, permanent=perm)
|
||||
img.id = _id
|
||||
image_db.insert(img.to_dict())
|
||||
|
||||
if __name__ == "__main__":
|
||||
result = populate_default_data()
|
||||
|
||||
Reference in New Issue
Block a user