try to fix insert
This commit is contained in:
Binary file not shown.
39
models.py
39
models.py
@@ -175,20 +175,39 @@ class DocuPulseSettings(db.Model):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_settings(cls):
|
def get_settings(cls):
|
||||||
settings = cls.query.first()
|
try:
|
||||||
if not settings:
|
settings = cls.query.first()
|
||||||
settings = cls(
|
if not settings:
|
||||||
max_rooms=10,
|
settings = cls(
|
||||||
max_conversations=10,
|
max_rooms=10,
|
||||||
max_storage=10737418240 # 10GB in bytes
|
max_conversations=10,
|
||||||
)
|
max_storage=10737418240 # 10GB in bytes
|
||||||
db.session.add(settings)
|
)
|
||||||
db.session.commit()
|
db.session.add(settings)
|
||||||
return settings
|
db.session.commit()
|
||||||
|
return settings
|
||||||
|
except Exception as e:
|
||||||
|
# If there's an error (like integer overflow), rollback and return None
|
||||||
|
db.session.rollback()
|
||||||
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_usage_stats(cls):
|
def get_usage_stats(cls):
|
||||||
settings = cls.get_settings()
|
settings = cls.get_settings()
|
||||||
|
if not settings:
|
||||||
|
# Return default values if settings can't be retrieved
|
||||||
|
return {
|
||||||
|
'max_rooms': 10,
|
||||||
|
'max_conversations': 10,
|
||||||
|
'max_storage': 10737418240,
|
||||||
|
'current_rooms': 0,
|
||||||
|
'current_conversations': 0,
|
||||||
|
'current_storage': 0,
|
||||||
|
'rooms_percentage': 0,
|
||||||
|
'conversations_percentage': 0,
|
||||||
|
'storage_percentage': 0
|
||||||
|
}
|
||||||
|
|
||||||
total_rooms = Room.query.count()
|
total_rooms = Room.query.count()
|
||||||
total_conversations = Conversation.query.count()
|
total_conversations = Conversation.query.count()
|
||||||
total_storage = db.session.query(db.func.sum(RoomFile.size)).filter(RoomFile.deleted == False).scalar() or 0
|
total_storage = db.session.query(db.func.sum(RoomFile.size)).filter(RoomFile.deleted == False).scalar() or 0
|
||||||
|
|||||||
Reference in New Issue
Block a user