# 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
class SessionTop(models.Model):
    session = models.ForeignKey(ParliamentSession)
    ordernr = models.IntegerField()
    title = models.TextField(blank=True)
    about = models.TextField(blank=True)
    
    objects = SessionTopManager()
    
    def __unicode__(self):
        return u"%s: %s" % (self.session, self.title)
    
class TopSpeaker(models.Model):
    top = models.ForeignKey(SessionTop)
    speaker = models.ForeignKey(Politician)

    def __unicode__(self):
        return u"%s: %s(%s) - %s" % (self.speaker, self.top, self.top_id, self.id)
    
class Attachment(models.Model):
    session = models.ForeignKey(ParliamentSession)
    attachmentnr = models.IntegerField(blank=True, null=True)
    about = models.TextField(blank=True)
    text = models.TextField(blank=True)

    def __unicode__(self):
        return u"%s: %s" % (self.session, self.about)
    
class Poll(models.Model):
    session = models.ForeignKey(ParliamentSession)
    about = models.TextField(blank=True)

# 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

class SessionTop(models.Model):
    session = models.ForeignKey(ParliamentSession)
    ordernr = models.IntegerField()
    title = models.TextField(blank=True)
    about = models.TextField(blank=True)
    
    objects = SessionTopManager()
    
    def __unicode__(self):
        return u"%s: %s" % (self.session, self.title)
    
class TopSpeaker(models.Model):
    top = models.ForeignKey(SessionTop)
    speaker = models.ForeignKey(Politician)

    def __unicode__(self):
        return u"%s: %s(%s) - %s" % (self.speaker, self.top, self.top_id, self.id)
    
class Attachment(models.Model):
    session = models.ForeignKey(ParliamentSession)
    attachmentnr = models.IntegerField(blank=True, null=True)
    about = models.TextField(blank=True)
    text = models.TextField(blank=True)

    def __unicode__(self):
        return u"%s: %s" % (self.session, self.about)
    
class Poll(models.Model):
    session = models.ForeignKey(ParliamentSession)
    about = models.TextField(blank=True)

    infavor = models.IntegerField(blank=True, null=True)