def add_gist(request): if request.method == "POST": text = request.POST["text"] g = Gist(text=text, user_id = request.user.id, pub_date = datetime.datetime.now()) g.save() return HttpResponseRedirect(reverse('index')) else: return render(request, "gists/new.html")
def test_is_recent_with_future_poll(self): future_gist = Gist(pub_date=timezone.now() + datetime.timedelta(days=1)) self.assertEqual(future_gist.is_recent(), False)
def test_is_recent_with_recent_gist(self): recent_gist = Gist(pub_date=timezone.now() - datetime.timedelta(hours=1)) self.assertEqual(recent_gist.is_recent(), True)
def test_is_recent_with_old_gist(self): old_gist = Gist(pub_date=timezone.now() - datetime.timedelta(days=30)) self.assertEqual(old_gist.is_recent(), False)