예제 #1
0
def post_comment(request, slug, year, month, day):
    story = get_by_date_or_404(Article, year, month, day, slug=slug)
    if not story.comments_allowed:
        raise Http404  # semantically incorrect, but whatever

    logged_in = request.user.is_authenticated()
    staff = logged_in and get_user_profile(request).staff_status()
    form = make_comment_form(data=request.POST,
                             logged_in=logged_in,
                             staff=staff)

    if form.is_valid():
        data = form.cleaned_data
        args = {
            'subject': story,
            'text': escape(data['text']).replace("\n", "<br/>"),
            'ip_address': get_ip(request),
            'user_agent': request.META.get('HTTP_USER_AGENT', '')
        }

        if logged_in:
            args['user'] = get_user_profile(request)
            if data['anonymous']:  # and data['name'] != request.user.get_full_name():
                args['name'] = data['name']
            args['speaking_officially'] = data['speaking_officially']
        else:
            args['name'] = data['name']
            args['email'] = data['email']

        try:
            comment = PublicComment.objects.new(**args)
        except CommentIsSpam, e:
            # put data in the session, because we're silly like that
            url = e.comment.subject.get_absolute_url()
            request.session.set_expiry(0)
            request.session['comment:%s' % url] = e.comment

            # NOTE: coupling with url for comment captchas
            redirect = request.build_absolute_uri(url + 'comment/captcha')
            if request.is_ajax():
                return HttpResponse('redirect: %s' % redirect)
            else:
                return HttpResponseRedirect(redirect)

        if request.is_ajax():
            return HttpResponse('success')
        else:
            return HttpResponseRedirect(comment.get_absolute_url())
예제 #2
0
파일: views.py 프로젝트: ainci/gazjango
def post_comment(request, slug, year, month, day):
    story = get_by_date_or_404(Article, year, month, day, slug=slug)
    if not story.comments_allowed:
        raise Http404 # semantically incorrect, but whatever
    
    logged_in = request.user.is_authenticated()
    staff = logged_in and get_user_profile(request).staff_status()
    form = make_comment_form(data=request.POST, logged_in=logged_in, staff=staff)
    
    if form.is_valid():
        data = form.cleaned_data
        args = {
            'subject': story,
            'text': escape(data['text']).replace("\n", "<br/>"),
            'ip_address': get_ip(request),
            'user_agent': request.META.get('HTTP_USER_AGENT', '')
        }
        
        if logged_in:
            args['user'] = get_user_profile(request)
            if data['anonymous']:# and data['name'] != request.user.get_full_name():
                args['name'] = data['name']
            args['speaking_officially'] = data['speaking_officially']
        else:
            args['name']  = data['name']
            args['email'] = data['email']
        
        try:
            comment = PublicComment.objects.new(**args)    
        except CommentIsSpam, e:
            # put data in the session, because we're silly like that
            url = e.comment.subject.get_absolute_url()
            request.session.set_expiry(0)
            request.session['comment:%s' % url] = e.comment
            
            # NOTE: coupling with url for comment captchas
            redirect = request.build_absolute_uri(url + 'comment/captcha')
            if request.is_ajax():
                return HttpResponse('redirect: %s' % redirect)
            else:
                return HttpResponseRedirect(redirect)
        
        if request.is_ajax():
            return HttpResponse('success')
        else:
            return HttpResponseRedirect(comment.get_absolute_url())
예제 #3
0
파일: views.py 프로젝트: ainci/gazjango
def specific_article(request, story, num=None, form=None, print_view=False):
    "Displays an article without searching the db for it."
    
    logged_in = request.user.is_authenticated()
    if form is None:
        initial = { 'text': 'Have your say.' }
        if logged_in:
            initial['name'] = request.user.get_full_name()
        staff = logged_in and get_user_profile(request).staff_status()
        form = make_comment_form(logged_in=logged_in, initial=initial, staff=staff)

    if story.is_swat_only():
        if not is_from_swat(user=get_user_profile(request), ip=get_ip(request)):
            return show_swat_only(request, story)
    
    try:
        photospread = story.photospread
    except PhotoSpread.DoesNotExist:
        return show_article(request, story, form, print_view)
    else:
        return show_photospread_page(request, photospread, num, form)
예제 #4
0
def specific_article(request, story, num=None, form=None, print_view=False):
    "Displays an article without searching the db for it."

    logged_in = request.user.is_authenticated()
    if form is None:
        initial = {'text': 'Have your say.'}
        if logged_in:
            initial['name'] = request.user.get_full_name()
        staff = logged_in and get_user_profile(request).staff_status()
        form = make_comment_form(logged_in=logged_in,
                                 initial=initial,
                                 staff=staff)

    if story.is_swat_only():
        if not is_from_swat(user=get_user_profile(request),
                            ip=get_ip(request)):
            return show_swat_only(request, story)

    try:
        photospread = story.photospread
    except PhotoSpread.DoesNotExist:
        return show_article(request, story, form, print_view)
    else:
        return show_photospread_page(request, photospread, num, form)