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


Python Topic.create方法代码示例

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


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

示例1: POST

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import create [as 别名]
    def POST(self):
        if not session.user or session.user.id is None:
            return bad_request('请先登录!')

        data = web.data()
        data = json.loads(data)

        tags = [tag for tag in data.get('tags', '').split(' ') if tag]
        topic_data = {
            "title": data.get('title'),
            "tags": tags,
            "owner_id": session.user.id,
            "created_time": datetime.now(),
        }

        try:
            topic_id = Topic.create(**topic_data)
        except sqlite3.IntegrityError:
            return bad_request('你已创建过该名称!')

        topic_data.update({
            "id": topic_id,
            "owner_name": session.user.username,
            "created_time": display_time(topic_data.get('created_time')),
        })
        return json.dumps(topic_data)
开发者ID:bb-js,项目名称:bb-js.org,代码行数:28,代码来源:topic.py

示例2: store

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import create [as 别名]
    def store(self, topic_name, article_entry_list):
        """Stores the article entries in the database.

        :param topic_name The name of the topic
        :param article_entry_list The list of entries of this topic
        """

        try:
            # Try to retrieve the topic to see if it exists already
            topic = Topic.get(Topic.name == topic_name)
        except Topic.DoesNotExist:
            # If not, create it
            topic = Topic.create(name=topic_name)

        # Go through all the articles in this topic
        for article_entry in article_entry_list:
            article_name = article_entry.subject

            # If there is no subject, it means the article is corrupted
            # therefore we skip it
            if not article_name:
                continue

            # Create the files with the content
            # Overwrite existing files
            try:
                Article.create(topic=topic, subject=article_name,
                               body=article_entry.body)
            except Article.DoesNotExist:
                pass
开发者ID:QFAPP,项目名称:QF,代码行数:32,代码来源:__init__.py

示例3: POST

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import create [as 别名]
    def POST(self):
        if not session.user or not session.user.id:
            return bad_request('请先登录!')
        if session.user.username != 'ff':
            return bad_request('sorry,你没有创建权限')

        data = web.data()
        data = json.loads(data)

        topic_data = {
            "title": data.get('title'),
            "owner_id": session.user.id,
            "created_time": datetime.now(),
        }

        try:
            topic_id = Topic.create(**topic_data)
        except sqlite3.IntegrityError:
            return bad_request('你已创建过该名称!')

        result = {
            "id": topic_id,
            "title": topic_data.get('title'),
            "owner_id": session.user.id,
            "owner_name": session.user.username,
            "created_time": str(topic_data.get('created_time')),
        }
        return json.dumps(result)
开发者ID:fatfan,项目名称:mychat,代码行数:30,代码来源:handlers.py

示例4: seed_sources

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import create [as 别名]
def seed_sources():
    crawler = GenericSourceCrawler(Scraper([GenericSourceParser]), Scraper([RSSParser]))
    with open('resources/sources.dat') as f:
        for source_url in f:
            source = crawler.crawl(source_url.strip())

            db_subscription = Subscription.update_or_create(Subscription.url == source.url,
                                                            url=source.url,
                                                            name=source.name,
                                                            image=source.image_url)

            for topic in source.topics:
                kwargs = {'source': db_subscription, 'name': topic.name, 'url': topic.url}
                try:
                    Topic.get(**kwargs)
                except Topic.DoesNotExist:
                    Topic.create(**kwargs)
开发者ID:johnliu,项目名称:journal-server,代码行数:19,代码来源:seed.py


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