Commit 036215ba authored by LammLukas's avatar LammLukas

Implemented room template export using sqlite database

parent 23d7f47a
......@@ -4,6 +4,8 @@ Class for room objects.
Author: L. Lamm (
from src.Exportable import Exportable
from src.Exceptions import *
import sqlite3
class Room(Exportable):
......@@ -24,10 +26,27 @@ class Room(Exportable):
if not hasattr(self, 'AssignedParticipants'):
self.AssignedParticipants = assigned_participants
def save_template(self, file, append=False):
"""Save template for room"""
data = self.data2dict(export_list=['Name', 'Internal_ID', 'NumSeats'])
self.write_json(file, data)
def save_template(self, file='./templates/rooms/room_templates.db'):
"""Save template for room in database"""
connector = sqlite3.connect(file)
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:
cursor.execute("CREATE TABLE rooms (internal_ID text, name text, num_seats text)")
"Check if room with id already exists"
cursor.execute("SELECT name FROM rooms WHERE internal_ID = ?", [self.Internal_ID])
if cursor.fetchone() is not None:
raise TemplateAlreadyExists("Room template already exists in database!")
values = [self.Internal_ID, self.Name, self.NumSeats]
cursor.execute("INSERT INTO rooms VALUES (?, ?, ?)", values)
def load_template(self, file):
"""Load template for room"""
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