# Path: bundestagger/account/auth.py
# def logged_in(func):
#     def loggedin_func(*args, **kwargs):
#         request = args[0]
#         if "bundesuser" in request.session:
#             request.bundesuser = request.session["bundesuser"]
#             return func(*args, **kwargs)
#         raise PermissionDenied
#     return loggedin_func
# 
# Path: bundestagger/helper/utils.py
# def invalidate_cache(path, *args):
#     page = None
#     if len(args)==2:
#         index, max_per_page = args
#         page = get_page(index, max_per_page)
#     if page is not None and page != 1:
#         request = FakeRequest(path, {"page": page})
#     else:
#         request = FakeRequest(path)
#     cache.delete(get_cache_key(request))
# 
# def is_post(func):
#     return is_method("POST", func)
# 
# def is_get(func):
#     return is_method("GET", func)


import re
from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.http import HttpResponse, Http404, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseNotAllowed
from django.template import RequestContext
from django.utils.itercompat import groupby
from django.core.paginator import Paginator, EmptyPage, InvalidPage
from django.conf import settings
from django.db.models import Q
from improvetext.models import Improvement
from models import ParliamentSession, Speech, SpeechPart, Event, Politician
from forms import EditSpeechPartForm
from bundestagger.account.auth import logged_in
from bundestagger.helper.utils import invalidate_cache, is_post, is_get
# -*- coding: utf-8 -*-





@is_get
def list_sessions(request):
    sessions = ParliamentSession.objects.select_related("parliament").order_by("-parliament__number", "-number")
    parliaments = groupby(sessions, lambda s: s.parliament)
    new_parliaments = []
    for parliament, it in parliaments:
        parliament.sessions = list(it)
        new_parliaments.append(parliament)
    return render_to_response("bundestag/list_sessions.html", RequestContext(request, {"parliaments" : new_parliaments}))


# Path: bundestagger/account/auth.py
# def logged_in(func):
#     def loggedin_func(*args, **kwargs):
#         request = args[0]
#         if "bundesuser" in request.session:
#             request.bundesuser = request.session["bundesuser"]
#             return func(*args, **kwargs)
#         raise PermissionDenied
#     return loggedin_func
# 
# Path: bundestagger/helper/utils.py
# def invalidate_cache(path, *args):
#     page = None
#     if len(args)==2:
#         index, max_per_page = args
#         page = get_page(index, max_per_page)
#     if page is not None and page != 1:
#         request = FakeRequest(path, {"page": page})
#     else:
#         request = FakeRequest(path)
#     cache.delete(get_cache_key(request))
# 
# def is_post(func):
#     return is_method("POST", func)
# 
# def is_get(func):
#     return is_method("GET", func)


# Path: bundestagger/bundestag/views.py
import re
from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.http import HttpResponse, Http404, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseNotAllowed
from django.template import RequestContext
from django.utils.itercompat import groupby
from django.core.paginator import Paginator, EmptyPage, InvalidPage
from django.conf import settings
from django.db.models import Q
from improvetext.models import Improvement
from models import ParliamentSession, Speech, SpeechPart, Event, Politician
from forms import EditSpeechPartForm
from bundestagger.account.auth import logged_in
from bundestagger.helper.utils import invalidate_cache, is_post, is_get

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





@is_get
def list_sessions(request):
    sessions = ParliamentSession.objects.select_related("parliament").order_by("-parliament__number", "-number")
    parliaments = groupby(sessions, lambda s: s.parliament)
    new_parliaments = []
    for parliament, it in parliaments:
        parliament.sessions = list(it)
        new_parliaments.append(parliament)
    return render_to_response("bundestag/list_sessions.html", RequestContext(request, {"parliaments" : new_parliaments}))


@is_get