app/soc/logic/models/notification.py
changeset 757 b11cee4ab535
parent 726 ba3d399ec9be
child 819 08a79c3e8817
equal deleted inserted replaced
756:a0c0b48563cb 757:b11cee4ab535
    20 __authors__ = [
    20 __authors__ = [
    21   '"Lennard de Rijk" <ljvderijk@gmail.com>',
    21   '"Lennard de Rijk" <ljvderijk@gmail.com>',
    22   ]
    22   ]
    23 
    23 
    24 
    24 
       
    25 from google.appengine.ext import db
       
    26 
       
    27 from soc.logic.helper import notifications
    25 from soc.logic.models import base
    28 from soc.logic.models import base
    26 from soc.logic.models import user as user_logic
    29 from soc.logic.models import user as user_logic
    27 
    30 
    28 import soc.models.notification
    31 import soc.models.notification
    29 
    32 
    35   def __init__(self):
    38   def __init__(self):
    36     """Defines the name, key_name and model for this entity.
    39     """Defines the name, key_name and model for this entity.
    37     """
    40     """
    38     super(Logic, self).__init__(model=soc.models.notification.Notification,
    41     super(Logic, self).__init__(model=soc.models.notification.Notification,
    39          base_model=None, scope_logic=user_logic)
    42          base_model=None, scope_logic=user_logic)
       
    43     
       
    44   def _onCreate(self, entity):
       
    45     """Sends out a message if there is only one unread notification.
       
    46     """
       
    47     
       
    48     # create a special query on which we can call count
       
    49     query = db.Query(self._model)
       
    50     query.filter('scope =', entity.scope)
       
    51     query.filter('unread = ', True)
       
    52     
       
    53     # count the number of results with a maximum of two
       
    54     unread_count = query.count(2)
       
    55     
       
    56     if unread_count == 1:
       
    57       # there is only one unread notification so send out an email
       
    58       notifications.sendNewNotificationMessage(entity)
    40 
    59 
    41 
    60 
    42 logic = Logic()
    61 logic = Logic()