Commit 9b8e33b4 authored by LammLukas's avatar LammLukas
Browse files

implemented load template in

parent d66905cc
......@@ -5,6 +5,7 @@ Author: L. Lamm (
from src.Exportable import Exportable
from src.Exceptions import *
from src.Utils import *
import sqlite3
......@@ -32,8 +33,7 @@ class Room(Exportable):
cursor = connector.cursor()
"Check if table exists in database"
cursor.execute(" SELECT count(name) FROM sqlite_master WHERE type='table' AND name='rooms'")
if not cursor.fetchone()[0] == 1:
if not db_table_exists(cursor, 'rooms'):
cursor.execute("CREATE TABLE rooms (internal_ID text, name text, num_seats text)")
......@@ -45,13 +45,22 @@ class Room(Exportable):
values = [self.Internal_ID, self.Name, self.NumSeats]
cursor.execute("INSERT INTO rooms VALUES (?, ?, ?)", values)
def load_template(self, file):
"""Load template for room"""
data = self.read_json(file)
self.Name = data['Name']
self.NumSeats = data['NumSeats']
#self.Internal_ID = data['Internal_ID']
def load_template(self, identity, file='./templates/rooms/room_templates.db'):
"""Load template for room from database"""
connector = sqlite3.connect(file)
cursor = connector.cursor()
if not db_table_exists(cursor, 'rooms'):
raise TableDoesNotExist("Table does not exist in database")
cursor.execute("SELECT name FROM rooms WHERE internal_ID = ?", [identity])
val = cursor.fetchone()
if val is None:
raise TemplateDoesNotExist("Room template does not exists in database!")
self.Internal_ID = identity
self.Name = val[0]
cursor.execute("SELECT num_seats FROM rooms WHERE internal_ID = ?", [identity])
self.NumSeats = cursor.fetchone()[0]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment