diff --git a/db/db.ddl b/db/db.ddl index 3709f66c44c519f7a0bc3ffa1783bfa30c61b6c2..83eda9928c977180f26b7dac61c9441f873f609c 100644 --- a/db/db.ddl +++ b/db/db.ddl @@ -219,11 +219,13 @@ CREATE TABLE papers ( bytes int DEFAULT NULL, -- velikost souboru file_name varchar(255) DEFAULT NULL, -- relativní cesta k souboru orig_file_name varchar(255) DEFAULT NULL, -- původní cesta, pokud PDF bylo poničené - note text NOT NULL DEFAULT '' -- komentář uploadujícího + note text NOT NULL DEFAULT '', -- komentář uploadujícího + fixed_at timestamp with time zone DEFAULT NULL -- Sémantika práce s poničenými soubory: -- - správná PDF mají orig_file_name=NULL -- - pokud někdo odevzdá poničené, vyplní se orig_file_name, ale file_name=NULL - -- - časem se spustí oprava, která vyplní i file_name a přepočítá bytes + -- - časem se spustí oprava, která vyplní i file_name, přepočítá bytes a nastaví fixed_at + -- - pokud oprava selže, nastaví pouze fixed_at ); CREATE INDEX papers_for_task_index ON papers (for_task); diff --git a/db/upgrade-20211130.sql b/db/upgrade-20211130.sql new file mode 100644 index 0000000000000000000000000000000000000000..0ea3b0d25f505a8cd7ca30cbaf91cb187617a4b9 --- /dev/null +++ b/db/upgrade-20211130.sql @@ -0,0 +1,4 @@ +SET ROLE 'mo_osmo'; + +ALTER TABLE papers ADD COLUMN + fixed_at timestamp with time zone DEFAULT NULL; diff --git a/mo/db.py b/mo/db.py index ed3bcd3c872283fffc7faf25d159b1bdd476dd2d..f78500f305fae63aa2be97950b108604054acd71 100644 --- a/mo/db.py +++ b/mo/db.py @@ -629,6 +629,7 @@ class Paper(Base): file_name = Column(String(255)) orig_file_name = Column(String(255)) note = Column(Text, nullable=False, server_default=text("''::text")) + fixed_at = Column(DateTime(True)) task = relationship('Task') for_user_obj = relationship('User', primaryjoin='Paper.for_user == User.user_id') @@ -650,6 +651,9 @@ class Paper(Base): def is_broken(self) -> bool: return self.file_name is None + def is_nonfixable(self) -> bool: + return self.is_broken() and self.fixed_at is not None + def is_fixed(self) -> bool: return self.orig_file_name is not None and self.file_name is not None