<commit_before>from django.shortcuts import render
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.utils import timezone, dateparse
from .models import Reservation, Field
from reservations import rutils


def index(request):
    """
    Index view shows all fields in system for now.
    """
    return render(request, 'reservations/index.html', {'fields': Field.objects.all(), })


class FieldDetailViewModel:
    """
    UI View Model for detail of field.
    """
    def __init__(self, res_date):
        self.res_date = res_date
        self.today = dateparse.parse_date(res_date) if res_date else timezone.now()
        self.res_date_previous = timezone.datetime(self.today.year, self.today.month, self.today.day-1, 0).strftime("%Y-%m-%d")
        self.res_date_next = timezone.datetime(self.today.year, self.today.month, self.today.day+1, 0).strftime("%Y-%m-%d")


def field_detail(request, field_id):
    """
    Detail of field without date (=today).
    """
    return field_detail_date(request, field_id, None)


def field_detail_date(request, field_id, res_date):
    """
    Detail of field with date specified.
    """
    field = Field.objects.get(id=field_id)
    reservations = rutils.get_reservations(field_id, res_date)
    fdvm = FieldDetailViewModel(res_date)
    hours2res = dict.fromkeys(range(24))
    for reservation in reservations:
        hours2res[reservation.time.hour] = reservation
    return render(request, 'reservations/field_detail.html', {'field_id': field_id, 'field': field,
                                                              'hours2res': hours2res, 'fdvm': fdvm })
<commit_msg>fix date at defatulf field page<commit_after>from django.shortcuts import render
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.utils import timezone, dateparse
from .models import Reservation, Field
from reservations import rutils


def index(request):
    """
    Index view shows all fields in system for now.
    """
    return render(request, 'reservations/index.html', {'fields': Field.objects.all(), })


class FieldDetailViewModel:
    """
    UI View Model for detail of field.
    """
    def __init__(self, res_date):
        self.res_date = res_date
        self.today = dateparse.parse_date(res_date) if res_date else timezone.now()
        self.res_date_previous = timezone.datetime(self.today.year, self.today.month, self.today.day-1, 0).strftime("%Y-%m-%d")
        self.res_date_next = timezone.datetime(self.today.year, self.today.month, self.today.day+1, 0).strftime("%Y-%m-%d")


def field_detail(request, field_id):
    """
    Detail of field without date (=today).
    """
    return field_detail_date(request, field_id, None)


def field_detail_date(request, field_id, res_date):
    """
    Detail of field with date specified.
    """
    field = Field.objects.get(id=field_id)
    reservations = rutils.get_reservations(field_id, res_date)
    fdvm = FieldDetailViewModel(res_date if res_date else timezone.now().strftime("%Y-%m-%d"))
    hours2res = dict.fromkeys(range(24))
    for reservation in reservations:
        hours2res[reservation.time.hour] = reservation
    return render(request, 'reservations/field_detail.html', {'field_id': field_id, 'field': field,
                                                              'hours2res': hours2res, 'fdvm': fdvm })

{'fraction_non_alphanumeric': 0.11526300661109515, 'fraction_numerical': 0.0074734118999712565, 'mean_word_length': 3.438775510204082, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4899070', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1031, 'n_words': 255}