Rename some IntEnumColumn related stuff

This commit is contained in:
Patrick Jentsch 2022-02-10 12:01:31 +01:00
parent 86d14f748f
commit 585a6ba796

View File

@ -17,23 +17,23 @@ import xml.etree.ElementTree as ET
import yaml
class IntEnumProxy(db.TypeDecorator):
class IntEnumColumn(db.TypeDecorator):
impl = db.Integer
def __init__(self, enumtype, *args, **kwargs):
def __init__(self, enum_type, *args, **kwargs):
super().__init__(*args, **kwargs)
self._enumtype = enumtype
self.enum_type = enum_type
def process_bind_param(self, value, dialect):
if isinstance(value, self._enumtype):
if isinstance(value, self.enum_type) and isinstance(value.value, int):
return value.value
elif isinstance(value, int):
return value
return self.enum_type(value).value
else:
return TypeError()
def process_result_value(self, value, dialect):
return self._enumtype(value)
return self.enum_type(value)
class Permission(IntEnum):
@ -156,7 +156,7 @@ class User(HashidMixin, UserMixin, db.Model):
username = db.Column(db.String(64), unique=True, index=True)
setting_dark_mode = db.Column(db.Boolean, default=False)
setting_job_status_mail_notification_level = db.Column(
IntEnumProxy(UserSettingJobStatusMailNotificationLevel),
IntEnumColumn(UserSettingJobStatusMailNotificationLevel),
default=UserSettingJobStatusMailNotificationLevel.END
)
# Backrefs: role: Role
@ -567,7 +567,7 @@ class Job(HashidMixin, db.Model):
service_args = db.Column(db.String(255))
service_version = db.Column(db.String(16))
status = db.Column(
IntEnumProxy(JobStatus),
IntEnumColumn(JobStatus),
default=JobStatus.INITIALIZING
)
title = db.Column(db.String(32))
@ -792,7 +792,7 @@ class Corpus(HashidMixin, db.Model):
description = db.Column(db.String(255))
last_edited_date = db.Column(db.DateTime(), default=datetime.utcnow)
status = db.Column(
IntEnumProxy(CorpusStatus),
IntEnumColumn(CorpusStatus),
default=CorpusStatus.UNPREPARED
)
title = db.Column(db.String(32))