# Path: bundestagger/helper/utils.py
# def padd_zeros(num, padd_base=3):
#     num = str(num)
#     for k in range(padd_base-len(num)):
#         num = "0"+num
#     return num
# 
# 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 invalidate_cache_all_pages(path, highest, max_per_page):
#     last = get_page(highest,max_per_page)
#     request = FakeRequest(path)
#     cache.delete(get_cache_key(request))
#     for i in range(last-1)+2:
#         request = FakeRequest(path, {"page": last})
#         cache.delete(get_cache_key(request))
# 
# def get_page(index, max_per_page):
#     return int(math.ceil(float(index) / max_per_page))


import datetime
import re
import django.dispatch
from difflib import SequenceMatcher
from django.db import models
from django.db.models import Q
from django.conf import settings
from django.core.urlresolvers import reverse
from django.conf import settings
from django.template.defaultfilters import slugify
from tagging.fields import TagField
from bundestagger.helper.utils import padd_zeros, invalidate_cache, invalidate_cache_all_pages, get_page
    
    def __unicode__(self):
        return u"%s: %s (%s - %d)" % (self.poll, self.politician, self.poll_id, self.vote)

class Event(models.Model):
    # Zwischenruf, Buhruf, Heiterkeit, Beifall
    context = models.ForeignKey(SpeechPart, null=True, blank=True)
    kind = models.CharField(blank=True, max_length=100)
    actor_politician = models.ForeignKey(Politician, null=True, blank=True)
    actor_party = models.ForeignKey(Party, null=True, blank=True)    
    text = models.TextField(blank=True, null=True)

    def __unicode__(self):
        return u"%s: %s (%s - %s @ %s)" % (self.kind, self.actor, self.text, self.id, self.context_id)
    
    @property
    def actor(self):
        if self.actor_politician is not None:
            return self.actor_politician
        else:
             return self.actor_party

    def display(self):
        out = u""
        try:
            if self.kind != "":
                out+=u"[%s] " % self.kind
            if self.actor is not None:
                out+=u"%s" % self.actor
            if self.text is not None and len(self.text)>0:

# Path: bundestagger/helper/utils.py
# def padd_zeros(num, padd_base=3):
#     num = str(num)
#     for k in range(padd_base-len(num)):
#         num = "0"+num
#     return num
# 
# 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 invalidate_cache_all_pages(path, highest, max_per_page):
#     last = get_page(highest,max_per_page)
#     request = FakeRequest(path)
#     cache.delete(get_cache_key(request))
#     for i in range(last-1)+2:
#         request = FakeRequest(path, {"page": last})
#         cache.delete(get_cache_key(request))
# 
# def get_page(index, max_per_page):
#     return int(math.ceil(float(index) / max_per_page))


# Path: bundestagger/bundestag/models.py
import datetime
import re
import django.dispatch
from difflib import SequenceMatcher
from django.db import models
from django.db.models import Q
from django.conf import settings
from django.core.urlresolvers import reverse
from django.conf import settings
from django.template.defaultfilters import slugify
from tagging.fields import TagField
from bundestagger.helper.utils import padd_zeros, invalidate_cache, invalidate_cache_all_pages, get_page

    
    def __unicode__(self):
        return u"%s: %s (%s - %d)" % (self.poll, self.politician, self.poll_id, self.vote)

class Event(models.Model):
    # Zwischenruf, Buhruf, Heiterkeit, Beifall
    context = models.ForeignKey(SpeechPart, null=True, blank=True)
    kind = models.CharField(blank=True, max_length=100)
    actor_politician = models.ForeignKey(Politician, null=True, blank=True)
    actor_party = models.ForeignKey(Party, null=True, blank=True)    
    text = models.TextField(blank=True, null=True)

    def __unicode__(self):
        return u"%s: %s (%s - %s @ %s)" % (self.kind, self.actor, self.text, self.id, self.context_id)
    
    @property
    def actor(self):
        if self.actor_politician is not None:
            return self.actor_politician
        else:
             return self.actor_party

    def display(self):
        out = u""
        try:
            if self.kind != "":
                out+=u"[%s] " % self.kind
            if self.actor is not None:
                out+=u"%s" % self.actor
            if self.text is not None and len(self.text)>0:

                if self.actor is not None or self.kind !="":