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

implemented load template in room.py

parent d66905cc
...@@ -5,6 +5,7 @@ Author: L. Lamm (lamm@ifam.rwth-aachen.de) ...@@ -5,6 +5,7 @@ Author: L. Lamm (lamm@ifam.rwth-aachen.de)
""" """
from src.Exportable import Exportable from src.Exportable import Exportable
from src.Exceptions import * from src.Exceptions import *
from src.Utils import *
import sqlite3 import sqlite3
...@@ -32,8 +33,7 @@ class Room(Exportable): ...@@ -32,8 +33,7 @@ class Room(Exportable):
cursor = connector.cursor() cursor = connector.cursor()
"Check if table exists in database" "Check if table exists in database"
cursor.execute(" SELECT count(name) FROM sqlite_master WHERE type='table' AND name='rooms'") if not db_table_exists(cursor, 'rooms'):
if not cursor.fetchone()[0] == 1:
cursor.execute("CREATE TABLE rooms (internal_ID text, name text, num_seats text)") cursor.execute("CREATE TABLE rooms (internal_ID text, name text, num_seats text)")
connector.commit() connector.commit()
...@@ -45,13 +45,22 @@ class Room(Exportable): ...@@ -45,13 +45,22 @@ class Room(Exportable):
values = [self.Internal_ID, self.Name, self.NumSeats] values = [self.Internal_ID, self.Name, self.NumSeats]
cursor.execute("INSERT INTO rooms VALUES (?, ?, ?)", values) cursor.execute("INSERT INTO rooms VALUES (?, ?, ?)", values)
connector.commit() connector.commit()
connector.close() connector.close()
def load_template(self, file): def load_template(self, identity, file='./templates/rooms/room_templates.db'):
"""Load template for room""" """Load template for room from database"""
data = self.read_json(file) connector = sqlite3.connect(file)
self.Name = data['Name'] cursor = connector.cursor()
self.NumSeats = data['NumSeats']
#self.Internal_ID = data['Internal_ID']
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!")
else:
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