Ejemplo n.º 1
0
def init_content(apps, schema_editor):
    Category = apps.get_model("app", "Category")
    c = Category.objects.create(name='默认分类')

    Tag = apps.get_model("app", "Tag")
    t = Tag.objects.create(name='DeerU')

    Album = apps.get_model("app", "Album")
    logo_black = Album.objects.get(name='logo_black.png')
    deeru_green = Album.objects.get(name='deeru_green.png')

    Article = apps.get_model("app", "Article")
    a = Article.objects.create(
        title='欢迎使用DeerU',
        content=
        '<p><img src="%s" data-name="logo_black.png" data-id="2" style="width: 229px;" class="fr-fic fr-dib"></p><p><br></p><hr><p style="text-align: center;"><br></p><p style="text-align: center;"><span style="font-size: 18px;"><strong>感谢你使用DeerU<span class="fr-emoticon fr-deletable">😀</span> </strong> </span></p><p style="text-align: center;"><strong><span style="font-size: 18px;">DeerU是一个免费开源的博客系统</span></strong></p><p style="text-align: center;"><br></p><p style="text-align: center;"><strong><span style="font-size: 18px;">为什么使用DeerU ?</span></strong></p><p style="text-align: center;"><strong><span style="font-size: 18px;">1. <strong><span style="font-size: 18px;">DeerU</span></strong>更适合程序员 </span> </strong></p><p style="text-align: center;"><strong><span style="font-size: 18px;">(它所有的配置均采用json格式进行配置) </span></strong></p><p style="text-align: center;"><strong><span style="font-size: 18px;">2. DeerU对前端开发人员更友好 </span></strong></p><p style="text-align: center;"><strong><span style="font-size: 18px;">(它为每个页面都提供了返回json数据的接口,你可以不依赖Django模板开发主题)</span></strong></p><p style="text-align: center;"><br></p><p style="text-align: center;"><strong><span style="font-size: 18px;">如果你有什么问题或者建议欢迎联系反馈给我</span></strong></p><p style="text-align: center;"><br></p><p style="text-align: center;"><strong><span style="font-size: 18px;">GITHUB: </span></strong><a href="https://github.com/gojuukaze/DeerU" rel="noopener noreferrer" target="_blank"><strong><span style="font-size: 18px;">https://github.com/gojuukaze/DeerU</span></strong></a></p><p style="text-align: center;"><strong><span style="font-size: 18px;">Documentation: <a class="fr-strong" data-fr-linked="true" href="https://deeru.readthedocs.io​​​" rel="noopener noreferrer" target="_blank">https://deeru.readthedocs.io</a></span></strong></p><p style="text-align: center;"><strong><span style="font-size: 18px;">插件主题:  <a class="fr-strong" data-fr-linked="true" href="https://github.com/gojuukaze/deeru_plugin_theme" rel="noopener noreferrer" target="_blank">https://github.com/gojuukaze/deeru_plugin_theme</a></span></strong></p>'
        % logo_black.img.url,
        summary=
        '欢迎你使用DeerU😀<br>DeerU是一个免费开源的博客系统<br>如果你有什么问题或者建议欢迎联系反馈给我<br>...',
        image=deeru_green.img.url)
    ArticleMeta = apps.get_model("app", "ArticleMeta")
    ArticleMeta.objects.create(article_id=a.id)

    ArticleCategory = apps.get_model("app", "ArticleCategory")
    update_one_to_many_relation_model(ArticleCategory, 'article_id', a.id,
                                      'category_id', [c.id], lambda x: x, [])
    ArticleTag = apps.get_model("app", "ArticleTag")
    update_one_to_many_relation_model(ArticleTag, 'article_id', a.id, 'tag_id',
                                      [t.id], lambda x: x, [])
Ejemplo n.º 2
0
def init_content(apps, schema_editor):
    Category = apps.get_model("app", "Category")
    c = Category.objects.create(name='默认分类')

    Tag = apps.get_model("app", "Tag")
    t = Tag.objects.create(name='DeerU')

    Album = apps.get_model("app", "Album")
    logo_black = Album.objects.get(name='logo_black.png')
    deeru_green = Album.objects.get(name='deeru_green.png')

    Article = apps.get_model("app", "Article")
    a = Article.objects.create(
        title='欢迎使用DeerU',
        content=
        '<p><img src="%s" data-name="logo_black.png" data-id="2" style="width: 229px;" class="fr-fic fr-dib"></p><p>	<br></p><hr><p style="text-align: center;">	<br></p><p style="text-align: center;"><span style="font-size: 18px;"><strong>感谢你使用DeerU<span class="fr-emoticon fr-deletable">😀</span>&nbsp;</strong>&nbsp;</span></p><p style="text-align: center;"><strong><span style="font-size: 18px;">DeerU是一个�费开�的�客系统</span></strong></p><p style="text-align: center;">	<br></p><p style="text-align: center;"><strong><span style="font-size: 18px;">如果你有什么问题或者建议欢迎�系�馈给我</span></strong></p><p style="text-align: center;">	<br></p><p style="text-align: center;"><strong><span style="font-size: 18px;">文档:<a class="fr-strong" data-fr-linked="true" href="https://deeru.readthedocs.io​​​" rel="noopener noreferrer" target="_blank">https://deeru.readthedocs.io</a></span></strong></p><p style="text-align: center;"><strong><span style="font-size: 18px;"><strong>GITHUB:&nbsp;</strong><a href="https://github.com/gojuukaze/DeerU" rel="noopener noreferrer" target="_blank"><strong>https://github.com/gojuukaze/DeerU</strong></a></span></strong></p>'
        % logo_black.img.url,
        summary=
        '欢迎你使用DeerU😀<br>DeerU是一个�费开�的�客系统<br>如果你有什么问题或者建议欢迎�系�馈给我<br>...',
        image=deeru_green.img.url)
    ArticleMeta = apps.get_model("app", "ArticleMeta")
    ArticleMeta.objects.create(article_id=a.id)

    ArticleCategory = apps.get_model("app", "ArticleCategory")
    update_one_to_many_relation_model(ArticleCategory, 'article_id', a.id,
                                      'category_id', [c.id], lambda x: x, [])
    ArticleTag = apps.get_model("app", "ArticleTag")
    update_one_to_many_relation_model(ArticleTag, 'article_id', a.id, 'tag_id',
                                      [t.id], lambda x: x, [])
Ejemplo n.º 3
0
    def save_model(self, request, obj, form, change):
        cover_img = form.cleaned_data['cover_img'] if form.cleaned_data[
            'is_use_cover_img'] else None
        cover_summary = form.cleaned_data['cover_summary'] if form.cleaned_data[
            'is_use_cover_summary'] else None
        obj.cover_img = cover_img
        obj.cover_summary = cover_summary
        result = super().save_model(request, obj, form, change)
        new_category = form.cleaned_data['category']
        update_one_to_many_relation_model(ArticleCategory, 'article_id',
                                          obj.id, 'category_id', new_category,
                                          lambda x: [int(c_id) for c_id in x],
                                          [c.id for c in self.old_category])
        new_tag_name = form.cleaned_data['tag']
        add_tag_name = list(
            set(new_tag_name).difference(set(get_tag_for_choice())))
        for add_name in add_tag_name:
            create_tag(add_name)
        update_one_to_many_relation_model(
            ArticleTag, 'article_id', obj.id, 'tag_id', new_tag_name,
            lambda x: list(
                filter_tag_by_name_list(x).values_list('id', flat=True)),
            [t.id for t in self.old_tag])

        return result
Ejemplo n.º 4
0
    def save_article_tag(self):

        for a in self.article:
            id = a.get('id')
            if not id:
                continue
            t_ids = []
            for t in a['tag']:
                t_ids.append(int(self.tag[t].get('id')))

            update_one_to_many_relation_model(ArticleTag, 'article_id', id, 'tag_id', t_ids,
                                              lambda x: x, old_many_ids=None)
Ejemplo n.º 5
0
    def save_article_category(self):

        for a in self.article:
            id = a.get('id')
            if not id:
                continue
            c_ids = []
            for c in a['category']:
                c_id = self.category[c].get('id')
                if c_id:
                    c_ids.append(int(c_id))

            update_one_to_many_relation_model(ArticleCategory, 'article_id', id, 'category_id', c_ids,
                                              lambda x: x, old_many_ids=None)