Example #1
0
def index(request):
    if request.method == "POST":
        p = Posts(name=request.POST['name'], description=request.POST['description'],url=request.POST['url'],  created_at=datetime.now())
        p.save()
    Posts
    posts = Posts.objects.all().order_by('-created_at')[:5]
    t = loader.get_template('./index.html')
    c = RequestContext(request, {
        'posts': posts,
    })

    return HttpResponse(t.render(c))
Example #2
0
    def test_get_recent_data(self):
        for i in range(0, 6):
            p = Posts(name="name{0}".format(i), description="description{0}".format(i),url="url{0}".format(i),  created_at=datetime.now())
            p.save()

        posts = Posts.objects.get_recent_data()

        self.assertEquals(len(posts), 5)
        self.assertEquals(posts[0].name, "name5")
        self.assertEquals(posts[1].name, "name4")
        self.assertEquals(posts[2].name, "name3")
        self.assertEquals(posts[3].name, "name2")
        self.assertEquals(posts[4].name, "name1")
Example #3
0
def index(request):
    if request.method == "POST":
        p = Posts(name=request.POST['name'],
                  description=request.POST['description'],
                  url=request.POST['url'],
                  created_at=datetime.now())
        p.save()
    Posts
    posts = Posts.objects.all().order_by('-created_at')[:5]
    t = loader.get_template('./index.html')
    c = RequestContext(request, {
        'posts': posts,
    })

    return HttpResponse(t.render(c))
Example #4
0
    def test_get_recent_data(self):
        for i in range(0, 6):
            p = Posts(name="name{0}".format(i),
                      description="description{0}".format(i),
                      url="url{0}".format(i),
                      created_at=datetime.now())
            p.save()

        posts = Posts.objects.get_recent_data()

        self.assertEquals(len(posts), 5)
        self.assertEquals(posts[0].name, "name5")
        self.assertEquals(posts[1].name, "name4")
        self.assertEquals(posts[2].name, "name3")
        self.assertEquals(posts[3].name, "name2")
        self.assertEquals(posts[4].name, "name1")