@@ -354,8 +354,20 @@ def to_choices(cls: enum.EnumMeta) -> Tuple[Tuple[str, str], ...]:
354354 return tuple ((choice .name , choice .value ) for choice in choices )
355355
356356
357+ class SolutionStatusView (enum .Enum ):
358+ UPLOADED = 'Uploaded'
359+ NOT_CHECKED = 'Not checked'
360+ CHECKED = 'Checked'
361+
362+ @classmethod
363+ def to_choices (cls : enum .EnumMeta ) -> Tuple [Tuple [str , str ], ...]:
364+ choices = cast (Iterable [enum .Enum ], tuple (cls ))
365+ return tuple ((choice .name , choice .value ) for choice in choices )
366+
367+
357368class Solution (BaseModel ):
358369 STATES = SolutionState
370+ STATUS_VIEW = SolutionStatusView
359371 MAX_CHECK_TIME_SECONDS = 60 * 10
360372
361373 exercise = ForeignKeyField (Exercise , backref = 'solutions' )
@@ -371,6 +383,12 @@ class Solution(BaseModel):
371383 )
372384 submission_timestamp = DateTimeField (index = True )
373385 hashed = TextField ()
386+ last_status_view = CharField (
387+ choices = STATUS_VIEW .to_choices (),
388+ default = STATUS_VIEW .UPLOADED .name ,
389+ index = True ,
390+ )
391+ last_time_view = DateTimeField (default = datetime .now , null = True , index = True )
374392
375393 @property
376394 def solution_files (
@@ -412,6 +430,20 @@ def is_duplicate(
412430
413431 return last_submission_hash == hash_
414432
433+ def view_solution (self ) -> None :
434+ self .last_time_view = datetime .now ()
435+ if (
436+ self .last_status_view != self .STATUS_VIEW .NOT_CHECKED .name
437+ and self .state == self .STATES .CREATED .name
438+ ):
439+ self .last_status_view = self .STATUS_VIEW .NOT_CHECKED .name
440+ elif (
441+ self .last_status_view != self .STATUS_VIEW .CHECKED .name
442+ and self .state == self .STATES .DONE .name
443+ ):
444+ self .last_status_view = self .STATUS_VIEW .CHECKED .name
445+ self .save ()
446+
415447 def start_checking (self ) -> bool :
416448 return self .set_state (Solution .STATES .IN_CHECKING )
417449
0 commit comments