#-*- coding: utf-8 -*-

from django.http import Http404
from django.shortcuts import render, get_object_or_404

from forum.models import *

def index(request):
    return render(request, 'forum/index.html', {'forums': Forum.objects.all()})

def forum(request, id_forum):
    forum = get_object_or_404(Forum, id=id_forum)
    return render(request, 'forum/forum.html', {'forum': forum})

def topic(request, id_forum, id_topic, page = 1):
    if page != 'last':
        page = int(page)

    topic = get_object_or_404(Topic, id=id_topic)

    text = "Vous êtes sur la page {} du topic {} du forum {}.".format(page, id_topic, id_forum)
    return HttpResponse(text)