当前位置: 首页>>代码示例>>Python>>正文


Python DBSession.add方法代码示例

本文整理汇总了Python中skylines.model.session.DBSession.add方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.add方法的具体用法?Python DBSession.add怎么用?Python DBSession.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在skylines.model.session.DBSession的用法示例。


在下文中一共展示了DBSession.add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_follower_notification

# 需要导入模块: from skylines.model.session import DBSession [as 别名]
# 或者: from skylines.model.session.DBSession import add [as 别名]
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)
开发者ID:dkm,项目名称:skylines,代码行数:11,代码来源:notification.py

示例2: setUp

# 需要导入模块: from skylines.model.session import DBSession [as 别名]
# 或者: from skylines.model.session.DBSession import add [as 别名]
 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
开发者ID:gabor-konrad,项目名称:Skylines,代码行数:15,代码来源:__init__.py

示例3: create_flight_notifications

# 需要导入模块: from skylines.model.session import DBSession [as 别名]
# 或者: from skylines.model.session.DBSession import add [as 别名]
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)
开发者ID:dkm,项目名称:skylines,代码行数:44,代码来源:notification.py

示例4: create_flight_comment_notifications

# 需要导入模块: from skylines.model.session import DBSession [as 别名]
# 或者: from skylines.model.session.DBSession import add [as 别名]
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)
开发者ID:dkm,项目名称:skylines,代码行数:24,代码来源:notification.py

示例5: follow

# 需要导入模块: from skylines.model.session import DBSession [as 别名]
# 或者: from skylines.model.session.DBSession import add [as 别名]
 def follow(cls, source, destination):
     f = cls.query(source, destination).first()
     if not f:
         f = Follower(source=source, destination=destination)
         DBSession.add(f)
开发者ID:dkm,项目名称:skylines,代码行数:7,代码来源:follower.py


注:本文中的skylines.model.session.DBSession.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。