예제 #1
0
def create_follower_notification(followed, follower):
    '''
    Create notification for the followed pilot about his new follower
    '''

    item = Notification(type=Notification.NT_FOLLOWER,
                        sender=follower,
                        recipient=followed)
    DBSession.add(item)
예제 #2
0
 def setUp(self):
     """Prepare model test fixture."""
     try:
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         self.obj = self.klass(**new_attrs)
         DBSession.add(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise
예제 #3
0
def create_flight_notifications(flight):
    '''
    Create notifications for the followers of the owner and pilots of the flight
    '''

    # Create list of flight-related users
    senders = [flight.pilot_id, flight.co_pilot_id, flight.igc_file.owner_id]
    senders = OrderedDict([(s, None) for s in senders if s is not None])

    # Request followers/recipients of the flight-related users from the DB
    followers = DBSession.query(Follower.source_id, Follower.destination_id) \
                         .filter(Follower.destination_id.in_(senders.keys())) \
                         .all()

    # Determine the recipients and their most important sender

    recipients = dict()

    # For each flight-related user in decreasing importance ..
    for sender in senders.keys():
        # For each of his followers
        for follower in followers:
            if follower.destination_id != sender:
                continue

            # Don't send notifications to the senders if they follow each other
            if follower.source_id in senders:
                continue

            # If the recipient/follower is not registered
            # yet by a more important sender
            if follower.source_id not in recipients:
                # Register the recipient with the sender's id
                recipients[follower.source_id] = sender

    # Create notifications for the recipients
    for recipient, sender in recipients.iteritems():
        item = Notification(type=Notification.NT_FLIGHT,
                            sender_id=sender,
                            recipient_id=recipient,
                            flight=flight)
        DBSession.add(item)
예제 #4
0
def create_flight_comment_notifications(comment):
    '''
    Create notifications for the owner and pilots of the flight
    '''

    # Create list of potential recipients (using Set to avoid duplicates)
    recipients = Set([comment.flight.igc_file.owner,
                      comment.flight.pilot,
                      comment.flight.co_pilot])

    # Create notifications for the recipients in the Set
    for recipient in recipients:
        # There is no need to notify the user that caused the notification
        if recipient is None or recipient == comment.user:
            continue

        item = Notification(type=Notification.NT_FLIGHT_COMMENT,
                            sender=comment.user,
                            recipient=recipient,
                            flight=comment.flight,
                            flight_comment=comment)
        DBSession.add(item)
예제 #5
0
파일: follower.py 프로젝트: dkm/skylines
 def follow(cls, source, destination):
     f = cls.query(source, destination).first()
     if not f:
         f = Follower(source=source, destination=destination)
         DBSession.add(f)