mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 03:36:48 +00:00
Nothing removed the Logs page's rows, which every action and every failed login adds, or the database sessions past their expiry. The job worker's housekeeping now deletes the rows older than Log Retention Days, a new setting under Lists and pages (1-3650, 365 by default), and the expired sessions.
30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
from django.core.management.color import no_style
|
|
from django.db import migrations
|
|
from django.utils.translation import gettext_noop as _
|
|
|
|
|
|
SETTING = (_("Log Retention Days"), "LOG_RETENTION_DAYS", "365", _("Days the Logs page keeps its rows (1-3650)"))
|
|
|
|
|
|
def add_setting(apps, schema_editor):
|
|
setting = apps.get_model("appsettings", "AppSettings")
|
|
db_alias = schema_editor.connection.alias
|
|
# see 0014: move a PostgreSQL id sequence past the fixed ids first
|
|
with schema_editor.connection.cursor() as cursor:
|
|
for sql in schema_editor.connection.ops.sequence_reset_sql(no_style(), [setting]):
|
|
cursor.execute(sql)
|
|
name, key, value, description = SETTING
|
|
setting.objects.using(db_alias).get_or_create(
|
|
key=key, defaults={"name": name, "value": value, "choices": "", "description": description}
|
|
)
|
|
|
|
|
|
def del_setting(apps, schema_editor):
|
|
apps.get_model("appsettings", "AppSettings").objects.using(schema_editor.connection.alias).filter(
|
|
key=SETTING[1]).delete()
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [("appsettings", "0023_remove_bottom_bar")]
|
|
|
|
operations = [migrations.RunPython(add_setting, del_setting)]
|