]> wagnertech.de Git - SVBaL.git/blob - python/eh_util/eh_app/AWK/config.py
47c7b0ab5a6995a2c745c8ef36294c7e2f9491d2
[SVBaL.git] / python / eh_util / eh_app / AWK / config.py
1 '''
2 Created on 02.08.2024
3
4 @author: sparky2021
5 '''
6 from eh_app.models import ConfigData
7
8 the_instance = None
9
10 class Config:
11     '''
12     Singleton Klasse für Konfiguration
13     '''
14
15     def __init__(self, verein):
16         self.verein = verein
17         
18     def getConfig(self, key, default=None):
19         data = ConfigData.objects.filter(verein=self.verein, key=key)
20         if data:
21             return data[0].value
22         return default
23     
24     def requireConfig(self, key):
25         data = self.getConfig(key)
26         if not data:
27             raise RuntimeError(f"Kein Eintag für: {self.verein}/{key}")
28         return data
29         
30
31 def getInstance(verein=None):
32     global the_instance
33     if not the_instance:
34         if not verein:
35             raise RuntimeError("Bei der ersten Instanzierung muss der Verein mitgegeben werden.")
36         the_instance = Config(verein)
37     return the_instance