Add notification
This commit is contained in:
parent
ab59065c0b
commit
de704fc250
17 changed files with 279 additions and 56 deletions
|
@ -1,7 +1,7 @@
|
|||
from reversion import revisions
|
||||
|
||||
from judge.models.choices import ACE_THEMES, EFFECTIVE_MATH_ENGINES, MATH_ENGINES_CHOICES, TIMEZONE
|
||||
from judge.models.comment import Comment, CommentLock, CommentVote
|
||||
from judge.models.comment import Comment, CommentLock, CommentVote, Notification
|
||||
from judge.models.contest import Contest, ContestMoss, ContestParticipation, ContestProblem, ContestSubmission, \
|
||||
ContestTag, Rating
|
||||
from judge.models.interface import BlogPost, MiscConfig, NavigationBar, validate_regex
|
||||
|
|
|
@ -19,7 +19,8 @@ from judge.models.problem import Problem
|
|||
from judge.models.profile import Profile
|
||||
from judge.utils.cachedict import CacheDict
|
||||
|
||||
__all__ = ['Comment', 'CommentLock', 'CommentVote']
|
||||
|
||||
__all__ = ['Comment', 'CommentLock', 'CommentVote', 'Notification']
|
||||
|
||||
comment_validator = RegexValidator(r'^[pcs]:[a-z0-9]+$|^b:\d+$',
|
||||
_(r'Page code must be ^[pcs]:[a-z0-9]+$|^b:\d+$'))
|
||||
|
@ -183,3 +184,11 @@ class CommentLock(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return str(self.page)
|
||||
|
||||
|
||||
class Notification(models.Model):
|
||||
owner = models.ForeignKey(Profile, verbose_name=_('owner'), related_name="notifications", on_delete=CASCADE)
|
||||
time = models.DateTimeField(verbose_name=_('posted time'), auto_now_add=True)
|
||||
comment = models.ForeignKey(Comment, verbose_name=_('comment'), on_delete=CASCADE)
|
||||
read = models.BooleanField(verbose_name=_('read'), default=False)
|
||||
category = models.CharField(verbose_name=_('category'), max_length=10)
|
|
@ -125,6 +125,14 @@ class Profile(models.Model):
|
|||
def username(self):
|
||||
return self.user.username
|
||||
|
||||
@cached_property
|
||||
def count_unseen_notifications(self):
|
||||
query = {
|
||||
'read': False,
|
||||
'comment__hidden': False,
|
||||
}
|
||||
return self.notifications.filter(**query).count()
|
||||
|
||||
_pp_table = [pow(settings.DMOJ_PP_STEP, i) for i in range(settings.DMOJ_PP_ENTRIES)]
|
||||
|
||||
def calculate_points(self, table=_pp_table):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue