def fail(request, message): if message[-1:] not in u".?!": message += u"." ctx = { "message": message, "user": session_user(request.session) } return render_to_response(u"500.html", ctx)
def post(request): """Post to Twitter""" form = PostForm(request.REQUEST) u = session_user(request.session) tw = Twitter(request.session["access_token"]) if request.method == u"POST" and not form.errors: status = form.cleaned_data["status"] in_reply_to = form.cleaned_data.get("in_reply_to", u"") if status.startswith(u"d "): recipient = status.split()[1] if not is_follower(tw, recipient): return cant_dm(request, recipient) try: update(tw, request.session["screen_name"], status, in_reply_to) except: return fail(request, _(u"Couldn't post to Twitter, they are lame." u" Refresh to try again.")) return HttpResponseRedirect(reverse("home")) if request.method == u"GET": status = request.GET.get("status", u"") if status.startswith(u"d "): recipient = status.split()[1] if not is_follower(tw, recipient): return cant_dm(request, recipient) form["status"].field.required = False if "in_reply_to" in form.errors: return fail(request, _(u"%s is not a valid status to reply to." % request.REQUEST["in_reply_to"])) ctx = { "form": form, "user": u, } return render_to_response(u"followize/post.html", ctx)
"""Show the latest update from each followed Twitterer using list_detail""" try: page = int(request.GET.get("page", 1)) except ValueError: return fail(request, u"%s doesn't work as a page number. Go back." % request.GET.get("page", u"")) tw = Twitter(request.session["access_token"]) try: user_following = following(tw, request.session["screen_name"]) except TwitterError, e: return fail(request, e.message) except (DownloadError, TimeoutException): return fail(request, _(u"Failed to get lovely tweets from Twitter." u" Refresh to try again.")) u = session_user(request.session) paginator = Paginator(user_following, settings.FOLLOWIZE_PAGE_LENGTH) try: p = paginator.page(page) except EmptyPage, e: return fail(request, "Oops, you went too far. Go back.") ctx = { "user": u, "following": p.object_list, "page_range": [paginator.page(i) for i in paginator.page_range], "current_page": p, "form": PostForm() } return render_to_response(u"followize/home.html", ctx)