mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
Rename some IntEnumColumn related stuff
This commit is contained in:
parent
86d14f748f
commit
585a6ba796
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user