Пример #1
0
def entry_comment(request, entry):
    '''Comment on an entry.

    Authentication is required.

    entry is the entry id.
    An optional parameter, comment, in the GET dict will allow you to edit an
    entry.
    An optional parameter, body, in the GET dict will initialize the form.
    '''
    if not request.session.get('nickname', None):
        return HttpResponseRedirect(reverse('login'))
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            f = friendfeed.FriendFeed(request.session['nickname'],
                request.session['key'])
            if form.data['comment']:
                data = f.edit_comment(form.data['entry'], form.data['comment'], form.data['body'])
            else:
                data = f.add_comment(form.data['entry'], form.data['body'], via=VIA)
            if 'errorCode' in data:
                return error(request, data)
            next = form.data['next']
            comment = data['id']
            args = {
                'entry': form.data['entry'],
                'comment': comment,
                'message': 'edited' if form.data['comment'] else 'commented',
            }
            next += '?%s#%s' % (urllib.urlencode(args), comment)
            return HttpResponseRedirect(next)
    else:
        initial = {
            'body': request.GET.get('body', None),
            'comment': request.GET.get('comment', None),
            'entry': entry,
            'next': reverse('entry', args=[entry]),
        }
        form = CommentForm(initial=initial)
    extra_context = {
        'form': form,
    }
    return render_to_response('comment.html', extra_context, context_instance=RequestContext(request))
Пример #2
0
def entry_comment(request, entry):
    """Comment on an entry.

    Authentication is required.

    entry is the entry id.
    An optional parameter, comment, in the GET dict will allow you to edit an
    entry.
    An optional parameter, body, in the GET dict will initialize the form.
    """
    if not request.session.get("nickname", None):
        return HttpResponseRedirect(reverse("login"))
    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            f = friendfeed.FriendFeed(request.session["nickname"], request.session["key"])
            if form.data["comment"]:
                data = f.edit_comment(form.data["entry"], form.data["comment"], form.data["body"])
            else:
                data = f.add_comment(form.data["entry"], form.data["body"], via=VIA)
            if "errorCode" in data:
                return error(request, data)
            next = form.data["next"]
            comment = data["id"]
            args = {
                "entry": form.data["entry"],
                "comment": comment,
                "message": "edited" if form.data["comment"] else "commented",
            }
            next += "?%s#%s" % (urllib.urlencode(args), comment)
            return HttpResponseRedirect(next)
    else:
        initial = {
            "body": request.GET.get("body", None),
            "comment": request.GET.get("comment", None),
            "entry": entry,
            "next": reverse("entry", args=[entry]),
        }
        form = CommentForm(initial=initial)
    extra_context = {"form": form}
    return render_to_response("comment.html", extra_context, context_instance=RequestContext(request))
Пример #3
0
def entry_comment(request, entry):
    '''Comment on an entry.

    Authentication is required.

    entry is the entry id.
    An optional parameter, comment, in the GET dict will allow you to edit an
    entry.
    An optional parameter, body, in the GET dict will initialize the form.
    '''
    if not request.session.get('nickname', None):
        return HttpResponseRedirect(reverse('login'))
    from fftogo.forms import CommentForm
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            f = friendfeed.FriendFeed(request.session['nickname'],
                request.session['key'])
            try:
                if form.data['comment']:
                    f.edit_comment(form.data['entry'], form.data['comment'], form.data['body'])
                    comment = form.data['comment']
                else:
                    comment = f.add_comment(form.data['entry'], form.data['body'], via=VIA)
            except Exception, e:
                if e[0] == 401:
                    del request.session['nickname']
                    del request.session['key']
                return HttpResponseRedirect(reverse(str(e)))
            next = form.data['next']
            if not form.data['comment']:
                if '?' in next:
                    next = next + '&message=commented&entry=%s&comment=%s' % (entry, comment)
                else:
                    next = next + '?message=commented&entry=%s&comment=%s' % (entry, comment)
            next = next + '#%s' % comment
            return HttpResponseRedirect(next)