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


Python Article.slug方法代码示例

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


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

示例1: post

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import slug [as 别名]
    def post(self):
        d = json.loads(self.request.body)
        if d['secret'] == '16jutges16':
            if 'key' in d and len(d['key']) > 10: #Keys are looong.
                article = ndb.Key(urlsafe = d['key']).get()
                logging.info('Modifying entry {}'.format(d['key']))
            else:
                article = Article()

            article.slug     = d['slug']
            article.title    = d['title']
            article.text     = d['text']
            if 'when' in d:
                # Matches isoformat into datetime object. Found in stackoverflow
                article.when = datetime.datetime(
                    *map(int, re.split('[^\d]', d['when'])[:-1])
                )
            else:
                article.when = datetime.datetime.now()

            try:
                article.keywords = string.split(d['keywords'])
            except AttributeError:
                article.keywords = d['keywords']
            
            article.put()
开发者ID:guillemborrell,项目名称:guillemborrell,代码行数:28,代码来源:resources.py

示例2: create

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import slug [as 别名]
def create(request, wiki_url):
    
    url_path = get_url_path(wiki_url)

    if url_path != [] and url_path[0].startswith('_'):
            c = RequestContext(request, {'wiki_err_keyword': True,
                                         'wiki_url': '/'.join(url_path) })
            return render_to_response('simplewiki_error.html', c)        

    # Lookup path
    try:
        # Ensure that the path exists...
        root = Article.get_root()
        path = Article.get_url_reverse(url_path[:-1], root)
        if not path:
            c = RequestContext(request, {'wiki_err_noparent': True,
                                         'wiki_url_parent': '/'.join(url_path[:-1]) })
            return render_to_response('simplewiki_error.html', c)
        
        perm_err = check_permissions(request, path[-1], check_locked=False, check_write=True)
        if perm_err:
            return perm_err
        # Ensure doesn't already exist
        article = Article.get_url_reverse(url_path, root)
        if article:
            return HttpResponseRedirect(reverse('wiki_view', args=(article[-1].get_url(),)))
    
        # TODO: Somehow this doesnt work... 
        #except ShouldHaveExactlyOneRootSlug, (e):
    except:
        if Article.objects.filter(parent=None).count() > 0:
            return HttpResponseRedirect(reverse('wiki_view', args=('',)))
        # Root not found...
        path = []
        url_path = [""]

    if request.method == 'POST':
        f = CreateArticleForm(request.POST)
        if f.is_valid():
            article = Article()
            article.slug = url_path[-1]
            if not request.user.is_anonymous():
                article.created_by = request.user
            article.title = f.cleaned_data.get('title')
            if path != []:
                article.parent = path[-1]
            a = article.save()
            new_revision = f.save(commit=False)
            if not request.user.is_anonymous():
                new_revision.revision_user = request.user
            new_revision.article = article
            new_revision.save()
            import django.db as db
            return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),)))
    else:
        f = CreateArticleForm(initial={'title':request.GET.get('wiki_article_name', url_path[-1]),
                                       'contents':_('Headline\n===\n\n')})
        
    c = RequestContext(request, {'wiki_form': f,
                                 'wiki_write': True,
                                 })

    return render_to_response('simplewiki_create.html', c)
开发者ID:JeffAMcGee,项目名称:infolab-site,代码行数:65,代码来源:views.py


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