Aufgrund einer Wartung wird GitLab am 26.10. zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 26.10. between 8:00 and 9:00 am.

Room.py 2.62 KB
Newer Older
1
2
3
4
5
6
"""
Class for room objects.

Author: L. Lamm (lamm@ifam.rwth-aachen.de)
"""
from src.Exportable import Exportable
7
from src.Exceptions import *
8
from src.Utils import *
9
import sqlite3
10
11
12
13


class Room(Exportable):
    """Class for objects of type Room"""
14
15
    def __init__(self, template=None, name=None, internal_id=None, num_seats=None,
                 supervisor_in_charge=None, extra_supervisors=None, assigned_participants=None):
16
17
18
19
20
        """Constructor of Room object"""
        if template is not None:
            self.load_template(template)
        else:
            self.Name = name
21
            self.Internal_ID = internal_id
22
23
24
25
26
27
28
29
            self.NumSeats = num_seats
        if not hasattr(self, 'SupervisorInCharge'):
            self.SupervisorInCharge = supervisor_in_charge
        if not hasattr(self, 'ExtraSupervisors'):
            self.ExtraSupervisors = extra_supervisors
        if not hasattr(self, 'AssignedParticipants'):
            self.AssignedParticipants = assigned_participants

30
31
32
33
34
35
    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"
36
        if not db_table_exists(cursor, 'rooms'):
37
38
39
40
41
42
43
44
45
46
47
48
            cursor.execute("CREATE TABLE rooms (internal_ID text, name text, num_seats text)")
            connector.commit()

        "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!")
        else:
            values = [self.Internal_ID, self.Name, self.NumSeats]
            cursor.execute("INSERT INTO rooms VALUES (?, ?, ?)", values)
            connector.commit()
        connector.close()
49

50
51
52
53
    def load_template(self, identity, file='./templates/rooms/room_templates.db'):
        """Load template for room from database"""
        connector = sqlite3.connect(file)
        cursor = connector.cursor()
54

55
56
57
58
59
60
61
62
63
64
65
66
        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]