예제 #1
0
def tweet(request):
    if request.method == "POST":
        # f = TweetForm(request.POST)
        # t = f.save(commit=False)
        # t.user = request.user
        # t.pub_date = datetime.now()
        # t.save()

        if "last_tweet" not in request.session:
            request.session["last_tweet"] = time.time()
        else:
            c = time.time() - request.session["last_tweet"]
            if c < 10:
                return HttpResponse("Not so fast, body, wait!")

        t = Tweet(user=request.user,
                      pub_date= datetime.now())
        f = TweetForm(request.POST, instance=t)
        f.save()

        # t = Tweet(user=request.user,
        #           txt=request.POST["txt"],
        #           pub_date=datetime.now()
        #           )
        # t.save()
    return HttpResponseRedirect(reverse("feed"))
예제 #2
0
def tweet(request):
    if request.method == "POST":
        # f = TweetForm(request.POST)
        # t = f.save(commit=False)
        # t.user = request.user
        # t.pub_date = datetime.now()
        # t.save()
        if "last_tweet_sec" in request.session:
            seconds = request.session["last_tweet_sec"]
            if time.time() - seconds < 10:
                wait_str = _("wait 10 secs, bro..")
                return HttpResponse(wait_str)

        t = Tweet(user=request.user,
                      pub_date= datetime.now())
        f = TweetForm(request.POST, instance=t)
        f.save()
        request.session["last_tweet_sec"] = time.time()

        # t = Tweet(user=request.user,
        #           txt=request.POST["txt"],
        #           pub_date=datetime.now()
        #           )
        # t.save()
    return HttpResponseRedirect(reverse("feed"))
예제 #3
0
def tweet(request):
    if request.method == "POST":
        # f = TweetForm(request.POST)
        # t = f.save(commit=False)
        # t.user = request.user
        # t.pub_date = datetime.now()
        # t.save()

        t = Tweet(user=request.user, pub_date=datetime.now())
        f = TweetForm(request.POST, instance=t)
        f.save()

        # t = Tweet(user=request.user,
        #           txt=request.POST["txt"],
        #           pub_date=datetime.now()
        #           )
        # t.save()
    return HttpResponseRedirect(reverse("feed"))
예제 #4
0
def tweet(request):
    if request.method == "POST":
        # f = TweetForm(request.POST)
        # t = f.save(commit=False)
        # t.user = request.user
        # t.pub_date = datetime.now()
        # t.save()

        t = Tweet(user=request.user,
                      pub_date= datetime.now())
        f = TweetForm(request.POST, instance=t)
        f.save()

        # t = Tweet(user=request.user,
        #           txt=request.POST["txt"],
        #           pub_date=datetime.now()
        #           )
        # t.save()
    return HttpResponseRedirect(reverse("feed"))
예제 #5
0
def tweet(request):
    if request.method == "POST":
        # f = TweetForm(request.POST)
        # t = f.save(commit=False)
        # t.user = request.user
        # t.pub_date = datetime.now()
        # t.save()
        if "last_tweet_sec" in request.session:
            seconds = request.session["last_tweet_sec"]
            if time.time() - seconds < 10:
                wait_str = _("wait 10 secs, bro..")
                return HttpResponse(wait_str)

        t = Tweet(user=request.user, pub_date=datetime.now())
        f = TweetForm(request.POST, instance=t)
        f.save()
        request.session["last_tweet_sec"] = time.time()

        # t = Tweet(user=request.user,
        #           txt=request.POST["txt"],
        #           pub_date=datetime.now()
        #           )
        # t.save()
    return HttpResponseRedirect(reverse("feed"))
예제 #6
0
def index(request):
    tweets = Tweet.objects.order_by("-pub_date")
    return render(request, "feed/feed.html", {"tweets": tweets,
                                              "f": TweetForm()})