# Path: cronos/accounts/resources.py
# class UserResource(ModelResource):
#     profile = fields.ForeignKey(UserProfileResource, 'userprofile', full=True)
# 
#     class Meta:
#         queryset = User.objects.filter(is_active = True)
#         resource_name = 'user'
#         excludes = ['email', 'date_joined', 'id', 'is_active', 'is_staff', 'is_superuser', 'last_login', 'password']
#         allowed_methods = ['get', 'post']
#         include_resource_uri = False
#         include_absolute_uri = False
#         authentication = ApiKeyAuthentication()
#         authorization = ReadOnlyAuthorization()
# 
#     def apply_authorization_limits(self, request, object_list):
#         return object_list.filter(username=request.user.username)
# 
#     def override_urls(self):
#         return [url(r"^(?P<resource_name>%s)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_detail"),]
# 
# Path: cronos/posts/feeds.py
# class PostsFeed(Feed):
#     link = 'http://cronos.teilar.gr'
# 
#     def get_object(self, request, username, page):
#         if page == u'announcements':
#             user = get_object_or_404(User, username=username)
#         else:
#             user = None
#         return [user, page]
# 
#     def title(self, obj):
#         page = obj[1]
#         if page == u'announcements':
#             return 'Ανακοινώσεις TEI Λάρισας από το cronos.teilar.gr'
#         elif page == u'blog':
#             return 'Blog cronos.teilar.gr'
# 
#     def description(self, obj):
#         page = obj[1]
#         if page == u'announcements':
#             return 'Ανακοινώσεις επιλεγμένων ιστοσελίδων του ΤΕΙ Λάρισας. Παρέχονται από το http://cronos.teilar.gr'
#         elif page == u'blog':
#             return 'Blog posts του http://cronos.teilar.gr'
# 
#     def items(self, obj):
#         user = obj[0]
#         page = obj[1]
#         posts = get_posts(user, None, page)
#         title = posts.pop()
#         return posts
# 
#     def item_title(self, item):
#         return item.title
# 
#     def item_link(self, item):
#         return u'http://cronos.teilar.gr/posts/' + str(item.id)
# 
#     def item_author_name(self, item):
#         return item.creator
# 
#     def item_author_link(self, item):
#         return item.creator_url
# 
#     def item_author_email(self, item):
#         try:
#             return item.creator.content_object.email
#         except:
#             pass
# 
#     def item_pubdate(self, item):
#         return item.pubdate
# 
#     def item_description(self, item):
#         return item.summary
# 
#     def item_enclosure_url(self, item):
#         return item.enclosure
# 
#     def item_enclosure_mime_type(self, item):
#         try:
#             mimetypes.init()
#             extension = '.' + item.enclosure.split('.')[-1]
#             enclosure_mimetype = mimetypes.types_map[extension]
#         except:
#             enclosure_mimetype = None
#         return enclosure_mimetype
# 
#     def item_enclosure_length(self):
#         return


from cronos.accounts.resources import UserResource
from cronos.posts.feeds import PostsFeed
from django.conf.urls.defaults import patterns, include, url
from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from tastypie.api import Api
# -*- coding: utf-8 -*-


handler500 = 'cronos.common.views.server_error'

urlpatterns = patterns('',
    (r'^$', 'cronos.accounts.views.accounts_index'),
    (r'^about/', 'cronos.common.views.about'),
    (r'^announcements/$', 'cronos.posts.views.posts', {'page': u'announcements', 'id': None}),
    (r'^api/', include(UserResource().urls)),
    (r'^blog/$', 'cronos.posts.views.posts', {'page': u'blog', 'id': None}),
    (r'^blog/feed/$', PostsFeed(), {'page': u'blog', 'username': None}),
    (r'^departments/(\d+)/$', 'cronos.posts.views.posts', {'page': u'department'}),
    (r'^dionysos/', 'cronos.teilar.views.dionysos'),
    (r'^eclass/', 'cronos.teilar.views.eclass'),

# Path: cronos/accounts/resources.py
# class UserResource(ModelResource):
#     profile = fields.ForeignKey(UserProfileResource, 'userprofile', full=True)
# 
#     class Meta:
#         queryset = User.objects.filter(is_active = True)
#         resource_name = 'user'
#         excludes = ['email', 'date_joined', 'id', 'is_active', 'is_staff', 'is_superuser', 'last_login', 'password']
#         allowed_methods = ['get', 'post']
#         include_resource_uri = False
#         include_absolute_uri = False
#         authentication = ApiKeyAuthentication()
#         authorization = ReadOnlyAuthorization()
# 
#     def apply_authorization_limits(self, request, object_list):
#         return object_list.filter(username=request.user.username)
# 
#     def override_urls(self):
#         return [url(r"^(?P<resource_name>%s)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_detail"),]
# 
# Path: cronos/posts/feeds.py
# class PostsFeed(Feed):
#     link = 'http://cronos.teilar.gr'
# 
#     def get_object(self, request, username, page):
#         if page == u'announcements':
#             user = get_object_or_404(User, username=username)
#         else:
#             user = None
#         return [user, page]
# 
#     def title(self, obj):
#         page = obj[1]
#         if page == u'announcements':
#             return 'Ανακοινώσεις TEI Λάρισας από το cronos.teilar.gr'
#         elif page == u'blog':
#             return 'Blog cronos.teilar.gr'
# 
#     def description(self, obj):
#         page = obj[1]
#         if page == u'announcements':
#             return 'Ανακοινώσεις επιλεγμένων ιστοσελίδων του ΤΕΙ Λάρισας. Παρέχονται από το http://cronos.teilar.gr'
#         elif page == u'blog':
#             return 'Blog posts του http://cronos.teilar.gr'
# 
#     def items(self, obj):
#         user = obj[0]
#         page = obj[1]
#         posts = get_posts(user, None, page)
#         title = posts.pop()
#         return posts
# 
#     def item_title(self, item):
#         return item.title
# 
#     def item_link(self, item):
#         return u'http://cronos.teilar.gr/posts/' + str(item.id)
# 
#     def item_author_name(self, item):
#         return item.creator
# 
#     def item_author_link(self, item):
#         return item.creator_url
# 
#     def item_author_email(self, item):
#         try:
#             return item.creator.content_object.email
#         except:
#             pass
# 
#     def item_pubdate(self, item):
#         return item.pubdate
# 
#     def item_description(self, item):
#         return item.summary
# 
#     def item_enclosure_url(self, item):
#         return item.enclosure
# 
#     def item_enclosure_mime_type(self, item):
#         try:
#             mimetypes.init()
#             extension = '.' + item.enclosure.split('.')[-1]
#             enclosure_mimetype = mimetypes.types_map[extension]
#         except:
#             enclosure_mimetype = None
#         return enclosure_mimetype
# 
#     def item_enclosure_length(self):
#         return


# Path: cronos/urls.py
from cronos.accounts.resources import UserResource
from cronos.posts.feeds import PostsFeed
from django.conf.urls.defaults import patterns, include, url
from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from tastypie.api import Api

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


handler500 = 'cronos.common.views.server_error'

urlpatterns = patterns('',
    (r'^$', 'cronos.accounts.views.accounts_index'),
    (r'^about/', 'cronos.common.views.about'),
    (r'^announcements/$', 'cronos.posts.views.posts', {'page': u'announcements', 'id': None}),
    (r'^api/', include(UserResource().urls)),
    (r'^blog/$', 'cronos.posts.views.posts', {'page': u'blog', 'id': None}),
    (r'^blog/feed/$', PostsFeed(), {'page': u'blog', 'username': None}),
    (r'^departments/(\d+)/$', 'cronos.posts.views.posts', {'page': u'department'}),
    (r'^dionysos/', 'cronos.teilar.views.dionysos'),
    (r'^eclass/', 'cronos.teilar.views.eclass'),

    (r'^announcements/(?P<username>\w+)/feed/$', PostsFeed(), {'page': u'announcements'}),