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


Python Suggestion.author方法代码示例

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


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

示例1: createOffseasonEventSuggestion

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import author [as 别名]
    def createOffseasonEventSuggestion(cls, author_account_key, name, start_date, end_date, website, venue_name, address, city, state, country, first_code=None, suggestion_id=None):
        """
        Create a suggestion for offseason event. Returns (status, failures):
        ('success', None)
        ('validation_failure', failures)
        """
        failures = {}
        if not name:
            failures['name'] = "Missing event name"
        if not start_date:
            failures['start_date'] = "Missing start date"
        if not end_date:
            failures['end_date'] = "Missing end date"
        if not website:
            failures['website'] = "Missing website"
        if not address:
            failures['venue_address'] = "Missing address"
        if not venue_name:
            failures['venue_name'] = "Missing venue name"
        if not city:
            failures['venue_city'] = "Missing city"
        if not state:
            failures['venue_state'] = "Missing state"
        if not country:
            failures['venue_country'] = "Missing country"

        start_datetime = None
        end_datetime = None
        if start_date:
            try:
                start_datetime = datetime.strptime(start_date, "%Y-%m-%d")
            except ValueError:
                failures['start_date'] = "Invalid start date format (year-month-date)"

        if end_date:
            try:
                end_datetime = datetime.strptime(end_date, "%Y-%m-%d")
            except ValueError:
                failures['end_date'] = "Invalid end date format (year-month-date)"

        if start_datetime and end_datetime and end_datetime < start_datetime:
            failures['end_date'] = "End date must not be before the start date"

        if failures and not suggestion_id:
            # Be more lenient with auto-added suggestions
            return 'validation_failure', failures

        # Note that we don't typically specify an explicit key for event suggestions
        # We don't trust users to input correct event keys (that's for the moderator to do)
        suggestion = Suggestion(id=suggestion_id) if suggestion_id else Suggestion()
        suggestion.author=author_account_key
        suggestion.target_model="offseason-event"
        suggestion.contents = {
            'name': name,
            'start_date': start_date,
            'end_date': end_date,
            'website': website,
            'venue_name': venue_name,
            'address': address,
            'city': city,
            'state': state,
            'country': country,
            'first_code': first_code,
        }
        suggestion.put()
        return 'success', None
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:68,代码来源:suggestion_creator.py


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