def pre_delete_handler(sender, **kwargs): instance = kwargs["instance"] profile = instance.user.get_profile() profile.posts -= 1 profile.save() depublish("forum-post-%d" % instance.id) depublish_where(type="commented", target=instance)
def refresh(problem, user): # TODO: 언젠가.. 최적화한다. -_- # PUBLISHED 가 아니면 Solver 인스턴스는 존재하지 않는다. if problem.state != Problem.PUBLISHED: return # Solver 인스턴스를 찾음. 없으면 만듬. instance = get_or_none(Solver, problem=problem, user=user) if not instance: instance = Solver(problem=problem, user=user) instance.save() # 이 사람의 서브미션 목록을 찾는다 submissions = Submission.objects.filter(problem=problem, is_public=True, user=user).order_by("id") accepted = submissions.filter(state=Submission.ACCEPTED) # 풀었나? 못 풀었나? prev_solved = instance.solved if accepted.count() == 0: instance.solved = False instance.incorrect_tries = submissions.count() instance.fastest_submission = instance.shortest_submission = None else: instance.solved = True first = accepted[0] instance.when = first.submitted_on incorrect = submissions.filter(id__lt=first.id) instance.incorrect_tries = incorrect.count() instance.fastest_submission = accepted.order_by("time")[0] instance.shortest_submission = accepted.order_by("length")[0] instance.save() if instance.solved != prev_solved: # 유저 프로필에 푼 문제 수 업데이트 profile = user.get_profile() profile.solved_problems = Solver.objects.filter( user=user, solved=True).count() profile.save() # 처음으로 풀었을 경우 알림을 보낸다 id = "solved-%d-%d" % (problem.id, user.id) if instance.solved: # 풀었다! publish(id, "solved", "judge", target=problem, actor=user, timestamp=instance.fastest_submission.submitted_on, verb=u"%d번의 시도만에 문제 {target}를 해결했습니다." % (instance.incorrect_tries + 1)) else: # 리저지 등 관계로 풀었던 문제를 못푼게 됨. depublish(id) # TODO: 가장 빠른 솔루션, 가장 짧은 솔루션이 등장했을 경우 # newsfeed entry를 보낸다 return instance
def refresh(problem, user): # TODO: 언젠가.. 최적화한다. -_- # PUBLISHED 가 아니면 Solver 인스턴스는 존재하지 않는다. if problem.state != Problem.PUBLISHED: return # Solver 인스턴스를 찾음. 없으면 만듬. instance = get_or_none(Solver, problem=problem, user=user) if not instance: instance = Solver(problem=problem, user=user) instance.save() # 이 사람의 서브미션 목록을 찾는다 submissions = Submission.objects.filter(problem=problem, is_public=True, user=user).order_by("id") accepted = submissions.filter(state=Submission.ACCEPTED) # 풀었나? 못 풀었나? prev_solved = instance.solved if accepted.count() == 0: instance.solved = False instance.incorrect_tries = submissions.count() instance.fastest_submission = instance.shortest_submission = None else: instance.solved = True first = accepted[0] instance.when = first.submitted_on incorrect = submissions.filter(id__lt=first.id) instance.incorrect_tries = incorrect.count() instance.fastest_submission = accepted.order_by("time")[0] instance.shortest_submission = accepted.order_by("length")[0] instance.save() if instance.solved != prev_solved: # 유저 프로필에 푼 문제 수 업데이트 profile = user.get_profile() profile.solved_problems = Solver.objects.filter(user=user, solved=True).count() profile.save() # 처음으로 풀었을 경우 알림을 보낸다 id = "solved-%d-%d" % (problem.id, user.id) if instance.solved: # 풀었다! publish(id, "solved", "judge", target=problem, actor=user, timestamp=instance.fastest_submission.submitted_on, verb=u"%d번의 시도만에 문제 {target}를 해결했습니다." % (instance.incorrect_tries + 1)) else: # 리저지 등 관계로 풀었던 문제를 못푼게 됨. depublish(id) # TODO: 가장 빠른 솔루션, 가장 짧은 솔루션이 등장했을 경우 # newsfeed entry를 보낸다 return instance
def comment_handler(sender, **kwargs): instance, created = kwargs["instance"], kwargs["created"] profile = instance.user.get_profile() target = instance.content_object if created: publish("comment-%d" % instance.id, "posts", "commented", actor=instance.user, action_object=instance, target=target, timestamp=instance.submit_date, verb=u"{target}에 새 댓글을 달았습니다: " u"{action_object}") profile.posts += 1 elif instance.is_removed: depublish("comment-%d" % instance.id) profile.posts -= 1 profile.save()
def comment_handler(sender, **kwargs): instance, created = kwargs["instance"], kwargs["created"] profile = instance.user.get_profile() target = instance.content_object ctype = ContentType.objects.get_for_model(target) visible_users = None visible_groups = None if ctype.name == 'post': print 'post' print target.category visible_users = get_users_with_perms(target.category, with_group_users=False) visible_groups = get_groups_with_perms(target.category) if ctype.name == 'problem' and target.state != Problem.PUBLISHED: visible_users = get_users_with_perms(target, with_group_users=False) visible_groups = get_groups_with_perms(target) print visible_users print visible_groups if created: publish("comment-%d" % instance.id, "posts", "commented", actor=instance.user, action_object=instance, target=target, timestamp=instance.submit_date, visible_users=visible_users, visible_groups=visible_groups, verb=u"{target}에 새 댓글을 달았습니다: " u"{action_object}") profile.posts += 1 elif instance.is_removed: depublish("comment-%d" % instance.id) profile.posts -= 1 profile.save()