# Path: cronos/posts/models.py
# class Authors(models.Model):
#     content_type = models.ForeignKey(ContentType)
#     object_id = models.PositiveIntegerField()
#     content_object = generic.GenericForeignKey('content_type', 'object_id')
# 
#     def __unicode__(self):
#         return self.content_object.name
# 
# class Posts(models.Model):
#     title = models.CharField(max_length = 500)
#     pubdate = models.DateTimeField()
#     creator = models.ForeignKey(Authors)
#     unique = models.CharField(max_length = 255, unique = True)
#     url = models.URLField()
#     summary = models.TextField(null = True)
#     enclosure = models.CharField("Attachment URL", max_length = 255, null = True)
# 
#     def __unicode__(self):
#         return self.title
# 
# Path: cronos/teilar/models.py
# class Departments(models.Model):
#     url = models.URLField(unique = True)
#     name = models.CharField(max_length = 255)
#     email = models.EmailField(null = True)
#     is_active = models.BooleanField(default = True)
# 
#     def __unicode__(self):
#         return self.name
# 
# Path: cronos/teilar/models.py
# class Teachers(models.Model):
#     url = models.URLField(unique = True)
#     name = models.CharField(max_length = 255)
#     email = models.EmailField(null = True)
#     department = models.ForeignKey(Departments)
#     is_active = models.BooleanField(default = True)
# 
#     def __unicode__(self):
#         return self.name
# 
# Path: cronos/teilar/models.py
# class Websites(models.Model):
#     url = models.URLField(unique = True)
#     name = models.CharField(max_length = 255)
#     rss = models.URLField()
#     email = models.EmailField(null = True)
#     is_active = models.BooleanField(default = True)
# 
#     def __unicode__(self):
#         return self.name
# 
# Path: cronos/teilar/models.py
# class EclassLessons(models.Model):
#     url = models.URLField(unique = True)
#     name = models.CharField(max_length = 500)
#     teacher = models.CharField(max_length = 500)
#     faculty = models.ForeignKey(EclassFaculties)
#     ltype = models.CharField(max_length = 100)
#     is_active = models.BooleanField(default = True)
# 
#     def __unicode__(self):
#         return self.name


from cronos.posts.models import Authors, Posts
from cronos.teilar.models import Departments as departments
from cronos.teilar.models import Teachers as teachers
from cronos.teilar.models import Websites as websites
from cronos.teilar.models import EclassLessons as eclasslessons
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from endless_pagination.decorators import page_template
import mimetypes
        following_meta_authors.append(user.get_profile().students)
        title = u'Blogs Φοιτητών'
    elif page == u'blog':
        following_authors.append(websites.objects.get(url=u'http://cronos.teilar.gr'))
        title = u'Blog'
    elif page == u'department':
        department = departments.objects.get(url__endswith = '=' + id)
        following_authors.append(department)
        title = u'Ανακοινώσεις: %s' % department.name
    elif page == u'teacher':
        teacher = teachers.objects.get(url__endswith = '=' + id)
        following_authors.append(teacher)
        title = u'Ανακοινώσεις: %s' % teacher.name
    '''
    Get authors from the ManyToMany fields
    '''
    for list_of_authors in following_meta_authors:
        for author in list_of_authors.all():
            following_authors.append(author)
    '''
    Find the creators and put them all in a list, so we can retrieve
    all of their posts from a query
    '''
    for author in following_authors:
        author_type = ContentType.objects.get_for_model(author)
        creator = Authors.objects.get(content_type__pk = author_type.id, object_id = author.id)
        creators.append(creator)
    '''
    Get all the posts
    '''

# Path: cronos/posts/models.py
# class Authors(models.Model):
#     content_type = models.ForeignKey(ContentType)
#     object_id = models.PositiveIntegerField()
#     content_object = generic.GenericForeignKey('content_type', 'object_id')
# 
#     def __unicode__(self):
#         return self.content_object.name
# 
# class Posts(models.Model):
#     title = models.CharField(max_length = 500)
#     pubdate = models.DateTimeField()
#     creator = models.ForeignKey(Authors)
#     unique = models.CharField(max_length = 255, unique = True)
#     url = models.URLField()
#     summary = models.TextField(null = True)
#     enclosure = models.CharField("Attachment URL", max_length = 255, null = True)
# 
#     def __unicode__(self):
#         return self.title
# 
# Path: cronos/teilar/models.py
# class Departments(models.Model):
#     url = models.URLField(unique = True)
#     name = models.CharField(max_length = 255)
#     email = models.EmailField(null = True)
#     is_active = models.BooleanField(default = True)
# 
#     def __unicode__(self):
#         return self.name
# 
# Path: cronos/teilar/models.py
# class Teachers(models.Model):
#     url = models.URLField(unique = True)
#     name = models.CharField(max_length = 255)
#     email = models.EmailField(null = True)
#     department = models.ForeignKey(Departments)
#     is_active = models.BooleanField(default = True)
# 
#     def __unicode__(self):
#         return self.name
# 
# Path: cronos/teilar/models.py
# class Websites(models.Model):
#     url = models.URLField(unique = True)
#     name = models.CharField(max_length = 255)
#     rss = models.URLField()
#     email = models.EmailField(null = True)
#     is_active = models.BooleanField(default = True)
# 
#     def __unicode__(self):
#         return self.name
# 
# Path: cronos/teilar/models.py
# class EclassLessons(models.Model):
#     url = models.URLField(unique = True)
#     name = models.CharField(max_length = 500)
#     teacher = models.CharField(max_length = 500)
#     faculty = models.ForeignKey(EclassFaculties)
#     ltype = models.CharField(max_length = 100)
#     is_active = models.BooleanField(default = True)
# 
#     def __unicode__(self):
#         return self.name


# Path: cronos/posts/views.py
from cronos.posts.models import Authors, Posts
from cronos.teilar.models import Departments as departments
from cronos.teilar.models import Teachers as teachers
from cronos.teilar.models import Websites as websites
from cronos.teilar.models import EclassLessons as eclasslessons
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from endless_pagination.decorators import page_template
import mimetypes

        following_meta_authors.append(user.get_profile().students)
        title = u'Blogs Φοιτητών'
    elif page == u'blog':
        following_authors.append(websites.objects.get(url=u'http://cronos.teilar.gr'))
        title = u'Blog'
    elif page == u'department':
        department = departments.objects.get(url__endswith = '=' + id)
        following_authors.append(department)
        title = u'Ανακοινώσεις: %s' % department.name
    elif page == u'teacher':
        teacher = teachers.objects.get(url__endswith = '=' + id)
        following_authors.append(teacher)
        title = u'Ανακοινώσεις: %s' % teacher.name
    '''
    Get authors from the ManyToMany fields
    '''
    for list_of_authors in following_meta_authors:
        for author in list_of_authors.all():
            following_authors.append(author)
    '''
    Find the creators and put them all in a list, so we can retrieve
    all of their posts from a query
    '''
    for author in following_authors:
        author_type = ContentType.objects.get_for_model(author)
        creator = Authors.objects.get(content_type__pk = author_type.id, object_id = author.id)
        creators.append(creator)
    '''
    Get all the posts
    '''

    posts_q = Posts.objects.select_related('creator__content_object').filter(creator__in = creators).order_by('-pubdate')