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


Python Utils.saturday方法代码示例

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


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

示例1: get

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import saturday [as 别名]
    def get(self):
        futurenights = Gamenight.future(10)

        if futurenights and futurenights[0].this_week():
            # we have a gamenight scheduled for this week
            gamenight = futurenights[0]
            if len(futurenights) > 1:
                futurenights = futurenights[1:]
            else:
                futurenights = []
        else:
            gamenight = Gamenight(status='Probably',
                             date=Utils.saturday(),
                             lastupdate=Utils.now())
            futurenights = []

        updated = gamenight.lastupdate.strftime('%A, %B %d, %I:%M %p')

        invites = Invitation.summary()

        upcoming = {g.date: { 'type': 'gamenight',
                              'date': g.date,
                              'location': g.location }
                            for g in futurenights}
        for week in range(0,5):
            day = (Utils.saturday() + timedelta(week*7)).date()

            # skip days we already have a confirmed GN
            if upcoming.get(day, False):
                continue

            summary = invites.get(day, False)
            if summary:
                upcoming[day] = { 'type': 'invites',
                                  'date': day,
                                  'invitations': summary }
                continue

            upcoming[day] = { 'date': day }

        template_values = {
          'future': sorted(upcoming.values(), key=lambda x: x['date']),
          'status': gamenight.status,
          'updated': updated,
        }

        if gamenight.date and gamenight.time:
            template_values['when'] = datetime.combine(gamenight.date, gamenight.time).strftime('%A, %I:%M %p')

        if gamenight.location:
            template_values['where'] =  gamenight.location

        if gamenight.notes:
            template_values['notes'] =  gamenight.notes

        template = JINJA_ENVIRONMNT.get_template('index.html')
        # Write the submission form and the footer of the page
        self.response.write(template.render(template_values))
开发者ID:zigdon,项目名称:gamenight,代码行数:60,代码来源:gamenight.py

示例2: schedule

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import saturday [as 别名]
    def schedule(cls, date=None, status=None, fallback='Probably', priority=None):
        # If no date is specified, look for the next invitation that is no
        # later than saturday
        if date is None:
            upcoming = Invitation.query(Invitation.date >= Utils.now().date()).\
                           order(Invitation.date).get()
            if upcoming is None or upcoming.date > Utils.saturday().date():
                logging.info('No future invitation found.')
                return None
            else:
                date = upcoming.date


        schedule = cls.query(cls.date==date).filter(cls.status=='Yes').get() or \
                   Invitation.resolve(when=date, priority=priority) or \
                   cls.query(cls.date==date).get() or \
                   Gamenight(status=fallback,
                             date=date,
                             lastupdate=Utils.now())
        if status is not None and schedule.status != 'Yes':
            schedule.status = status

        schedule.put()
        logging.info('Scheduling new gamenight: %r', schedule)

        return schedule
开发者ID:zigdon,项目名称:gamenight,代码行数:28,代码来源:schema.py

示例3: resolve

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import saturday [as 别名]
    def resolve(cls, when=Utils.saturday(), history=4, priority=None):
        """Figure out where GN should be at the given date.

        By default, consider the last 4 to give preference to people who
        haven't been hosting."""

        if type(when) != datetime.date:
            when = when.date()

        logging.info('Resolving gamenight for %s', when)

        invitations = cls.query(cls.date == when)
        logging.debug('Query: %r' % invitations)

        if priority is not None:
            priorities = (priority,)
        else:
            priorities = ('Insist', 'Want', 'Can')
        candidates = []
        # check each level separately
        for pri in priorities:
            candidates = dict([(x.owner.id(), x) for x in
                    invitations.filter(cls.priority == pri).fetch()])

            # no matches at this priority
            if not candidates:
                logging.debug('none at priority %s' % pri)
                continue

            # no need to look at lower levels
            logging.debug('Candidates(%s): %r' % (pri, candidates))
            break

        # no one wants to host :(
        if not candidates:
            logging.debug('none found.')
            return None

        # more than one option, filter out the recent hosts until we run out of
        # recent hosts, or have just one option left.
        logging.debug('Candidates: %r' % candidates.keys())
        if len(candidates) > 1:
            if history:
                old_nights = Gamenight.query(Gamenight.date < Utils.now()).\
                                 order(Gamenight.date).fetch(history)
                while old_nights and len(candidates) > 1:
                    owner = old_nights.pop().owner.id()
                    if owner in candidates:
                        logging.debug('removing previous host %s' % owner)
                        del candidates[owner]

        logging.debug('Not recent candidates: %r' % candidates.keys())

        # pick one at random, return the invitation object
        selected = random.choice(candidates.keys())
        logging.debug('Selected invitation: %s\n%r' %
                      (selected, candidates[selected]))

        return candidates[selected].make_gamenight()
开发者ID:zigdon,项目名称:gamenight,代码行数:61,代码来源:schema.py

示例4: reset

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import saturday [as 别名]
    def reset(cls, date=None):
        if date is None:
            date = Utils.saturday()


        schedule = Invitation.resolve(when=date, priority='Insist') or \
                   cls.query(cls.date==date).get() or \
                   Gamenight(status='Probably',
                             date=date,
                             lastupdate=Utils.now())
        schedule.put()
        logging.info('Resetting gamenight page: %r', schedule)

        return schedule
开发者ID:zigdon,项目名称:gamenight,代码行数:16,代码来源:schema.py


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