# -*- coding: utf-8 -*-
#
# Copyright 2015, Foxugly. All rights reserved.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later veron.


from django.http import HttpResponse
from django.shortcuts import render_to_response, render, redirect
from trimesters.models import Trimester
from utils.models import TemplateTrimesterForm, TemplateTrimester
from companies.models import Company
import json


def favorite_trimester(year):
    t = year.trimesters.filter(active=True, favorite=True)
    if not t:
        t = [year.trimesters.filter(active=True)[0]]
    return t[0]


def list_categories(request, trimester_id):
    if request.is_ajax():
        t = Trimester.objects.get(id=trimester_id)
        result = {}
        nav_list = []
        for c in t.categories.filter(active=True).order_by('cat__priority'):
            nav_list.append(c.as_json())
        result['nav_list'] = nav_list
        result['title_trimester'] = str(t)
        return HttpResponse(json.dumps(result))


def admin_trimesters(request):
    c = {'list': TemplateTrimester.objects.all(), 'form': [TemplateTrimesterForm()], 'url': '/trimesters/template/add/'}
    return render(request, 'list.tpl', c)


def add_templatetrimester(request):
    form = TemplateTrimesterForm(request.POST)
    if form.is_valid():
        tt = form.save()


def apply_templatetrimester(request, tt_id):
    tt = TemplateTrimester.objects.get(id=tt_id)
    for c in Company.objects.filter(active=True):
        t = Trimester()

@@ -584,16 +584,205 @@
  json%0A%0A%0A
+def view_trimester(request, trimester_id):%0A    t = Trimester.objects.get(id=trimester_id)%0A    return view_category(request, t.categories.filter(active=True).order_by('cat__priority')%5B0%5D):%0A%0A
 def favo

Update views.py