# -*- coding: utf-8 -*-
from django.shortcuts import render_to_response
from django.template import RequestContext

from models import Reservation


def index(request):
    """
    列表页
    :param request:
    :return:
    """
    reservations = Reservation.objects.select_related().all()
    data = {
        'paid_total': 0,
        'paid': [],
        'cancelled': [],
        'suspended': [],
    }
    for r in reservations:
        if r.paid:
            data['paid_total'] += r.amount
            data['paid'].append(r)
        elif r.suspended:
            data['suspended'].append(r)
        elif r.cancelled:
            data['cancelled'].append(r)

    return render_to_response('list.html', {'data': data},
                              context_instance=RequestContext(request))