feat: task
This commit is contained in:
@@ -1 +1,2 @@
|
||||
from .comment import Comment # noqa: F401
|
||||
from .task import Task # noqa: F401
|
||||
|
||||
+2
-2
@@ -4,8 +4,8 @@ import tortoise.models
|
||||
|
||||
class AbstractModel(tortoise.models.Model):
|
||||
id = tortoise.fields.UUIDField(primary_key=True)
|
||||
created_at = tortoise.fields.DatetimeField(auto_now_add=True)
|
||||
updated_at = tortoise.fields.DatetimeField(auto_now=True)
|
||||
created_at = tortoise.fields.DatetimeField(auto_now_add=True, null=False)
|
||||
updated_at = tortoise.fields.DatetimeField(auto_now=True, null=False)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
@@ -4,4 +4,4 @@ from app.models.base import AbstractModel
|
||||
|
||||
|
||||
class Comment(AbstractModel):
|
||||
content = tortoise.fields.TextField()
|
||||
content = tortoise.fields.TextField(null=False)
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import typing
|
||||
|
||||
import tortoise
|
||||
|
||||
from app.models.base import AbstractModel
|
||||
|
||||
# https://stackoverflow.com/a/57639657
|
||||
CRONTAB_REGEX = r"/(@(annually|yearly|monthly|weekly|daily|hourly|reboot))|(@every (\d+(ns|us|µs|ms|s|m|h))+)|((((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|\*) ?){5,7})/"
|
||||
|
||||
|
||||
class Task(AbstractModel):
|
||||
list = tortoise.fields.CharField(max_length=32, db_index=True, null=False)
|
||||
name = tortoise.fields.TextField(null=False)
|
||||
reset_cron = tortoise.fields.CharField(max_length=64, null=True)
|
||||
check_date = tortoise.fields.DatetimeField(null=True)
|
||||
previous_check_date = tortoise.fields.DatetimeField(null=True)
|
||||
|
||||
@classmethod
|
||||
def validate_create(cls, data: dict[str, typing.Any]) -> dict | None:
|
||||
out_data = {}
|
||||
try:
|
||||
for field in [
|
||||
"list",
|
||||
"name",
|
||||
"reset_cron",
|
||||
"check_date",
|
||||
"previous_check_date",
|
||||
]:
|
||||
getattr(cls, field).validate(data.get(field))
|
||||
out_data[field] = data.get(field)
|
||||
except tortoise.exceptions.ValidationError:
|
||||
return None
|
||||
return out_data
|
||||
|
||||
@classmethod
|
||||
def validate_update(cls, data: dict[str, typing.Any]) -> dict | None:
|
||||
out_data = {}
|
||||
try:
|
||||
for field in [
|
||||
"list",
|
||||
"name",
|
||||
"reset_cron",
|
||||
"check_date",
|
||||
"previous_check_date",
|
||||
]:
|
||||
if field in data:
|
||||
getattr(cls, field).validate(data["field"])
|
||||
out_data[field] = data["field"]
|
||||
except tortoise.exceptions.ValidationError:
|
||||
return None
|
||||
return out_data
|
||||
Reference in New Issue
Block a user