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
|
||||
def get_settings(cls):
|
||||
settings = cls.query.first()
|
||||
if not settings:
|
||||
settings = cls(
|
||||
max_rooms=10,
|
||||
max_conversations=10,
|
||||
max_storage=10737418240 # 10GB in bytes
|
||||
)
|
||||
db.session.add(settings)
|
||||
db.session.commit()
|
||||
return settings
|
||||
try:
|
||||
settings = cls.query.first()
|
||||
if not settings:
|
||||
settings = cls(
|
||||
max_rooms=10,
|
||||
max_conversations=10,
|
||||
max_storage=10737418240 # 10GB in bytes
|
||||
)
|
||||
db.session.add(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
|
||||
def get_usage_stats(cls):
|
||||
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_conversations = Conversation.query.count()
|
||||
total_storage = db.session.query(db.func.sum(RoomFile.size)).filter(RoomFile.deleted == False).scalar() or 0
|
||||
|
||||
Reference in New Issue
Block a user