Provides criteria object
Project description
Classic Criteria
Дает объект-критерий.
Нужен для описания критериев объектов, чтобы затем определять, соответствуют ли те или иные объекты критерию, или для формирования запроса, к примеру, в SQL-хранилище.
Пример:
from datetime import datetime
from dataclasses import dataclass
from classic.criteria import Criteria
@dataclass
class Task:
created_at: datetime
finished_at: datetime
@dataclass
class TaskOlderThan(Criteria[Task]):
date: datetime
def is_satisfied_by(self, candidate: Task) -> bool:
return candidate.created_at < self.date
@dataclass
class TaskObsolete(Criteria[Task]):
days_to_work: int
def is_satisfied_by(self, candidate: Task) -> bool:
days_spent = candidate.finished_at - candidate.created_at
return days_spent.days > self.days_to_work
some_task = Task(
created_at=datetime(2024, 1, 1),
finished_at=datetime(2024, 1, 10),
)
criteria = TaskObsolete(3) & TaskOlderThan(datetime(2024, 1, 31))
assert criteria.is_satisfied_by(some_task)
some_task = Task(
created_at=datetime(2024, 1, 1),
finished_at=datetime(2024, 1, 1),
)
criteria = TaskObsolete(3) & TaskOlderThan(datetime(2024, 1, 31))
assert not criteria.is_satisfied_by(some_task)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file classic-criteria-0.0.1.tar.gz
.
File metadata
- Download URL: classic-criteria-0.0.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f44deb91eac6e471a5b4c80dcbbbd1352fdab6b8f9d2fc6fa382202ef884fec5 |
|
MD5 | 45ab0d8351f188e2b905100ad29a9fa9 |
|
BLAKE2b-256 | 04ba05298edd323c5f175edc102e6c30eb5604022545d3b50369301ac52700fc |