# 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
            first_name = self.first_name + u" "
        else:
            first_name = u""
        if len(self.last_name_prefix):
            last_name_prefix = self.last_name_prefix + u" "
        else:
            last_name_prefix = u""
        return "%s%s%s%s" % (title, first_name, last_name_prefix,self.last_name)
        
    def all_relations(self):
        relations = [x for x in dir(self) if x.endswith("_set")]
        result = []
        for relation in relations:
            result.extend(getattr(self, relation).all())
        return result
        
    def replace_with(self, real_politician):
        relations = [x for x in dir(self) if x.endswith("_set")]
        for relation in relations:
            relset = getattr(self, relation).all()
            if len(relset) > 0:
                politician_fields = []
                for obj in relset:
                    fields = obj.__class__._meta.fields
                    for field in fields:
                        try:
                            if field.rel.to.__name__ == self.__class__.__name__:
                                politician_fields.append(field.name)
                        except AttributeError:
                            pass

# 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

            first_name = self.first_name + u" "
        else:
            first_name = u""
        if len(self.last_name_prefix):
            last_name_prefix = self.last_name_prefix + u" "
        else:
            last_name_prefix = u""
        return "%s%s%s%s" % (title, first_name, last_name_prefix,self.last_name)
        
    def all_relations(self):
        relations = [x for x in dir(self) if x.endswith("_set")]
        result = []
        for relation in relations:
            result.extend(getattr(self, relation).all())
        return result
        
    def replace_with(self, real_politician):
        relations = [x for x in dir(self) if x.endswith("_set")]
        for relation in relations:
            relset = getattr(self, relation).all()
            if len(relset) > 0:
                politician_fields = []
                for obj in relset:
                    fields = obj.__class__._meta.fields
                    for field in fields:
                        try:
                            if field.rel.to.__name__ == self.__class__.__name__:
                                politician_fields.append(field.name)
                        except AttributeError:
                            pass

                    if len(politician_fields)>0: