get things working like tasks
This commit is contained in:
parent
5de9914341
commit
968ae1d18a
@ -1,4 +1,3 @@
|
||||
from datetime import datetime
|
||||
from peewee import fn
|
||||
from peewee import Case, Value
|
||||
from ..db import db, Thing
|
||||
@ -29,7 +28,9 @@ def update_thing(
|
||||
**kwargs,
|
||||
) -> Thing:
|
||||
with db.atomic():
|
||||
query = Thing.update(data=kwargs).where(Thing.id == item_id)
|
||||
thing = Thing.get_by_id(item_id)
|
||||
new_data = thing.data | kwargs
|
||||
query = Thing.update(data=new_data).where(Thing.id == item_id)
|
||||
query.execute()
|
||||
thing = Thing.get_by_id(item_id)
|
||||
return thing
|
||||
@ -61,7 +62,7 @@ def _parse_sort_string(sort_string):
|
||||
)
|
||||
sort_expressions.append(order_case.desc() if is_desc else order_case.asc())
|
||||
elif field_type == "date":
|
||||
expr = fn.COALESCE(Thing.data[field_name], datetime(3000, 12, 31))
|
||||
expr = fn.COALESCE(Thing.data[field_name], "3000-01-01")
|
||||
sort_expressions.append(expr.desc() if is_desc else expr)
|
||||
else:
|
||||
field_expr = Thing.data[field_name]
|
||||
|
@ -38,7 +38,7 @@ class Thing(BaseModel):
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.updated_at = datetime.now()
|
||||
return super(Task, self).save(*args, **kwargs)
|
||||
return super(Thing, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
|
||||
|
@ -69,7 +69,9 @@ class EnumColumnConfig(TableColumnConfig):
|
||||
class DateColumnConfig(TableColumnConfig):
|
||||
def preprocess(self, val):
|
||||
try:
|
||||
return datetime.datetime.strptime(val, "%Y-%m-%d")
|
||||
# ensure it parses, return as string
|
||||
datetime.datetime.strptime(val, "%Y-%m-%d")
|
||||
return val
|
||||
except ValueError:
|
||||
raise NotifyValidationError("Invalid date format. Use YYYY-MM-DD")
|
||||
|
||||
|
@ -15,7 +15,7 @@ from ..utils import (
|
||||
)
|
||||
from .keymodal import KeyModal
|
||||
from .modals import ConfirmModal
|
||||
from .columns import get_col_cls
|
||||
from .columns import get_col_cls, NotifyValidationError
|
||||
|
||||
|
||||
|
||||
@ -135,7 +135,11 @@ class TableEditor(App):
|
||||
row = []
|
||||
|
||||
for col in self.table_config:
|
||||
# TODO: decide how this should work once things is done
|
||||
try:
|
||||
val = getattr(item, col.field)
|
||||
except AttributeError:
|
||||
val = item.data[col.field]
|
||||
display_val = col.format_for_display(val)
|
||||
row.append(display_val)
|
||||
|
||||
|
@ -39,17 +39,23 @@ def get_color_enum(value: str, enum: dict[str, dict]) -> str:
|
||||
|
||||
|
||||
def get_colored_date(date: datetime.date) -> str:
|
||||
if not isinstance(date, datetime.date):
|
||||
return ""
|
||||
if isinstance(date, datetime.date):
|
||||
as_date = date
|
||||
as_str = date.strftime("%Y-%m-%d")
|
||||
elif isinstance(date, str):
|
||||
as_date = datetime.datetime.strptime(date, "%Y-%m-%d").date()
|
||||
as_str = as_date.strftime("%Y-%m-%d")
|
||||
else:
|
||||
return "~bad~"
|
||||
|
||||
if as_str in SPECIAL_DATES_DISPLAY:
|
||||
return SPECIAL_DATES_DISPLAY[as_str]
|
||||
today = datetime.date.today()
|
||||
if date.date() < today:
|
||||
if as_date < today:
|
||||
return f"[#eeeeee on #dd1111]{as_str}[/]"
|
||||
else:
|
||||
# Calculate weeks into future
|
||||
delta = date.date() - today
|
||||
delta = as_date - today
|
||||
weeks = delta.days // 7
|
||||
|
||||
colors = [
|
||||
|
Loading…
Reference in New Issue
Block a user