extensions-website/extensions/fields.py
Anna Sirota 8124bc62ae Log deleted extension data (#84)
When an extension or a version is deleted, create a `LogEntry` for each record linked to that extension or version.
Each `LogEntry` has action flag `DELETION` and contains a blob with the last known field values of the records.
These `LogEntry` can be viewed by admins in `/admin/admin/logentry/`, same as any other `LogEntry` created by Django admin, so this should be sufficient for archival purposes.

Part of #82

Reviewed-on: #84
2024-04-19 16:25:49 +02:00

33 lines
923 B
Python

from semantic_version.django_fields import VersionField as SemanticVersionField
from semantic_version import Version
import json
class VersionStringField(SemanticVersionField):
description = "A field to store serializable semantic versions"
def to_python(self, value):
if isinstance(value, Version):
return value
if value is None:
return value
return str(Version(value))
def from_db_value(self, value, expression, connection):
return self.to_python(value)
def get_prep_value(self, value):
if value is None:
return value
return str(value)
def value_to_string(self, obj):
value = self.value_from_object(obj)
return self.get_prep_value(value)
def from_json(self, json_str):
return self.to_python(json.loads(json_str))
def to_json(self, value):
return json.dumps(str(value))