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


Python Comment.ip方法代码示例

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


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

示例1: save_comment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import ip [as 别名]
def save_comment(request):
    """保存评论"""
    article_id = request.POST.get("article_id", "").strip()
    try:
        _int_article_id = int(article_id)
    except Exception:
        return HttpResponseRedirect("/")

    username = request.POST.get("username", "").strip()
    content = request.POST.get("content", "").strip()
    if len(username) < 4 or len(content) < 4:
        return HttpResponseRedirect("/")

    comment = Comment()

    comment.blog = Blog.objects.get(id=_int_article_id)
    comment.blog.comment_times += 1
    comment.blog.save()

    comment.submit_name = username
    comment.content = content
    comment.ip = gcommon.get_remote_addr(request)  # request.META['REMOTE_ADDR']
    comment.save()

    return HttpResponseRedirect("/blog/%d.html" % _int_article_id)
开发者ID:xeon2007,项目名称:mycode,代码行数:27,代码来源:views.py

示例2: save

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import ip [as 别名]
 def save(self, blog=None, user=None, ip=None):
     if self.cleaned_data['body'] and blog and user:
         comment = Comment(body=self.cleaned_data['body'], blog=blog,
                                                           user=user)
         if ip:
             comment.ip = ip
         comment.save()
开发者ID:Marx86,项目名称:trambroid,代码行数:9,代码来源:forms.py

示例3: passage

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import ip [as 别名]
def passage(request,pid,commentpage):
    commentinpage=5
    context2={}
    addaccessamount(request,pid)
    passage=Passage.objects.get(id=pid)
    if request.method=="POST":        
        comment=Comment()
        comment.time=timezone.now()
        comment.passage=passage
        comment.ip=getIPFromDJangoRequest(request)
        comment.body=request.POST['body']
        if request.POST.get('ifhideip')=='on':
            comment.ifhideip=True
        else:
            comment.ifhideip=False
        if request.POST.get('ifsafe')=='on':
            comment.ifsafe=True            
        else:
            comment.ifsafe=False
        result = check(request.POST.get('body')) 
        print result                                             
        if result=='ok':
            comment.save()
        elif result=='none':
            context2['error']='none' 
            context2 = dict(context2.items()+request.POST.items()) 
            print context2             
        elif result=='script':
            if comment.ifsafe: 
                context2['error']='script'
                context2 = dict(context2.items()+request.POST.items())
            else:
                comment.save()     
        else:
            pass        
    comments=passage.comment_set.order_by('-time')[(int(commentpage)-1)*commentinpage:int(commentpage)*commentinpage]
    allpassagenum=passage.comment_set.count()
    allpagenum=int(allpassagenum)/commentinpage+1
    if range(1,int(commentpage))[5:]:
        betweenpagesbefore = range(1,int(commentpage))[5:]
    else:
        betweenpagesbefore = range(1,int(commentpage))
    betweenpagesnext = range(int(commentpage)+1,allpagenum+1)[:5]
    context={
        'passage':passage,
        'comments':comments,
        'page':commentpage,
        'allpagenum':allpagenum,
        'betweenpagesbefore':betweenpagesbefore,
        'betweenpagesnext':betweenpagesnext,
    }
    if context2.items():
        context=dict(context.items()+context2.items())
    if int(commentpage)>1:
        context['beforepage']=int(commentpage)-1
    if int(commentpage)<allpagenum:
        context['nextpage']=int(commentpage)+1
    return render(request,'passage.html',context)
开发者ID:lichunown,项目名称:ownblog,代码行数:60,代码来源:views.py

示例4: blog

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import ip [as 别名]
def blog(request, blogid):
    try:
        article = Blog.objects.get(id=blogid)
        article.visit_times += 1
        article.save()
    except Blog.DoesNotExist:
        return HttpResponseRedirect('/')
    
    page = request.GET.get('page', '1')
    try:
        page_num = int(page)
    except:
        page_num = 1
    
    qs = article.comment_set.all().order_by('id')
    
    html_dict = {'article': article,}
    db_tools.get_category_latelyblogs(html_dict)

    #分页
    PAGE_MSG_NUM = 10
    split_dict = gcommon.split_page(request, page_num, PAGE_MSG_NUM, qs)
    html_dict.update(split_dict)

    username = request.POST.get('username', '').strip()
    content = request.POST.get('content', '').strip()
    if not username and not content:
        return render_to_response('blog/article.html', html_dict, context_instance=RequestContext(request))
        
    if len(username) < 4 or len(content) < 4:
        html_dict['remind_msg'] = u'名称和内容不能少于4个字符'
        return render_to_response('blog/article.html', html_dict, context_instance=RequestContext(request))
    
    comment = Comment()
    comment.blog = Blog.objects.get(id=blogid)
    comment.blog.comment_times += 1
    comment.blog.save()
    comment.submit_name = username
    comment.content = content
    comment.ip = gcommon.get_remote_addr(request) #request.META['REMOTE_ADDR']
    comment.save()

    return render_to_response('blog/article.html', html_dict, context_instance=RequestContext(request))
开发者ID:lvshuchengyin,项目名称:mycode,代码行数:45,代码来源:views.py


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