66from .course import Course
77from .user import User
88from .notif import Notif
9- from .utils import doc_required , get_redis_client
9+ from .utils import (
10+ doc_required ,
11+ get_redis_client ,
12+ logger ,
13+ )
1014from .submission import *
1115from .event import (
1216 submission_completed ,
@@ -52,11 +56,6 @@ def __new__(cls, pk, *args, **kwargs):
5256 cls .__initialized = True
5357 return super ().__new__ (cls , pk , * args , ** kwargs )
5458
55- def __init__ (self , _id ):
56- if isinstance (_id , self .engine ):
57- _id = _id .id
58- self .id = _id
59-
6059 @classmethod
6160 def on_submission_completed (cls , submission ):
6261 if submission .comment is None :
@@ -131,7 +130,7 @@ def delete(self):
131130 return self
132131
133132 @doc_required ('user' , 'user' , User )
134- def like (self , user ):
133+ def like (self , user : User ):
135134 '''
136135 Like/Unlike a comment
137136 '''
@@ -155,6 +154,8 @@ def like(self, user):
155154 self .reload ()
156155 user .reload ()
157156 event .send (self , user = user )
157+ logger ().info (
158+ f'User like/unlike comment [user={ user .id } , comment={ self .id } ]' )
158159
159160 def submit (self , code = None ):
160161 '''
@@ -187,6 +188,7 @@ def on_submission_completed_ins(self):
187188 self .update (inc__success = 1 )
188189 # Process OJ problem
189190 if self .problem .is_OJ :
191+ # FIXME: There might exists unfinished submissions, their `result` will be `None`
190192 is_ac = lambda s : s .result .judge_result == Submission .engine .JudgeResult .AC
191193 self .update (acceptance = self .Acceptance .ACCEPTED if any (
192194 map (is_ac , self .submissions )) else self .Acceptance .REJECTED )
@@ -240,6 +242,7 @@ def add_to_problem(
240242 notif = Notif .new (info )
241243 target .author .update (push__notifs = notif .pk )
242244 comment_created .send (comment .reload ())
245+ logger ().info (f'Comment created [comment={ comment .id } ]' )
243246 return comment
244247
245248 def new_submission (self , code : str ):
@@ -271,27 +274,28 @@ def add_to_comment(
271274 if not target :
272275 raise engine .DoesNotExist
273276 # create new comment
274- comment = cls .add (
277+ reply = cls .add (
275278 floor = target .floor ,
276279 depth = 1 ,
277280 problem = target .problem ,
278281 ** ks ,
279282 )
280- target .update (push__replies = comment .obj )
283+ target .update (push__replies = reply .obj )
281284 # notify relevant users
282285 info = Notif .types .NewReply (
283286 comment = target .pk ,
284287 problem = target .problem ,
285288 )
286289 authors = {target .author , target .problem .author } - {
287- comment .author ,
290+ reply .author ,
288291 }
289292 if authors :
290293 notif = Notif .new (info )
291294 for author in authors :
292295 author .update (push__notifs = notif .pk )
293- reply_created .send (comment .reload ())
294- return comment
296+ reply_created .send (reply .reload ())
297+ logger ().info (f'Reply created [comment={ target .id } , reply={ reply .id } ]' )
298+ return reply
295299
296300 @classmethod
297301 @doc_required ('author' , User )
0 commit comments