class FeedDetailView(TemplateView):
    '''This view redirects to a template describing RSS feeds.'''
    
    template_name = "feed_details.html"   
    
    def get_context_data(self, **kwargs):
        '''This function adds the google_calendar_id to the context.'''
        context = super(FeedDetailView, self).get_context_data(**kwargs)
        context['google_calendar_id'] = settings.GOOGLE_CALENDAR_ID
        context['wikipedia_username'] = settings.WIKIPEDIA_USERNAME
        return context  class LabLocationView(ListView):
    '''This view provides location information.
    
    Its passes the location_list parameter when the /location view is requested.
    '''
    
    template_name = "location.html"
    model = LabLocation   class LabPersonnelSitemap(Sitemap):
    '''This sitemap lists all personnel to be indexed.
    
    It only includes current laboratory members (current_lab_member=True)'''

    changefreq = 'yearly'
    priority = '0.5'
    
    def items(self):
        '''Filters Person to show only laboratory papers.'''
        return Person.objects.filter(current_lab_member=True)
        
    def lastmod(self, person):
        '''lastmod uses the last modification of the paper (not the comments).'''
        return person.updated class LabPublicationsSitemap(Sitemap):
    '''This sitemap lists all :class:`~papers.models.Publication` objects to be indexed.
    
    It only includes papers from this laboratory (laboratory_papers=True)'''

    changefreq = 'yearly'
    priority = '0.7'
    
    def items(self):
        '''Filters :class:`~papers.models.Publication` to show only laboratory papers.'''
        return Publication.objects.filter(laboratory_paper=True)
        
    def lastmod(self, paper):
        '''lastmod uses the last modification of the paper (not the comments).'''
        return paper.date_last_modified class CommentarySitemap(Sitemap):
    '''This sitemap lists all :class:`~papers.modelsCommentary` objects.'''

    changefreq = 'yearly'
    priority = '0.6'

    def items(self):
        '''All Commentaries are shown.'''
        return Commentary.objects.all()

    def lastmod(self, commentary):
        return commentary.modified class ProjectsSitemap(Sitemap):
    '''This sitemap lists all :class:`~projects.models.Project` objects to be indexed.
    
    It includes all projects.'''

    changefreq = 'monthly'
    priority = '0.7'
    
    def items(self):
        '''Filters :class:`~papers.models.Publication` to show only laboratory papers.'''
        return Project.objects.all()
        
    def lastmod(self, project):
        '''lastmod uses the last modification of the paper (not the comments).'''
        return project.date_last_modified class FundingSitemap(Sitemap):
    '''This sitemap lists all :class:`~projects.models.Funding` objects to be indexed.
    
    It includes all funding.'''

    changefreq = 'monthly'
    priority = '0.6'
    
    def items(self):
        '''Filters :class:`~papers.models.Publication` to show only laboratory papers.'''
        return Funding.objects.all()
        
    def lastmod(self, project):
        '''lastmod uses the last modification of the paper (not the comments).'''
        return project.date_last_modified         class PostsSitemap(Sitemap):
    '''This sitemap lists all :class:`~communication.models.Post` objects to be indexed.
    
    '''

    changefreq = 'monthly'
    priority = '0.9'
    
    def items(self):
        '''Shows all :class:`~communication.models.Post` objects.'''
        return Post.objects.all()
        
    def lastmod(self, post):
        '''lastmod uses the last modification of the post or the creation date.'''
        if post.modified:
            return post.modified
        else:
            return post.created class LabPapersFeed(PapersFeed):
    '''This generates a feed for papers from this group.'''

    title = "Papers From the %s" % settings.LAB_NAME
    link = "/feeds/lab-papers"
    description = "This feed contains papers published by members of the %s." % settings.LAB_NAME

    def items(self):
        '''The items returned by this feed are papers set as laboratory papers.'''
        return Publication.objects.filter(laboratory_paper=True) class InterestingPapersFeed(PapersFeed):
    '''This generates a feed for papers marked as interesting.'''

    title = "Papers of Interest"
    link = "/feeds/interesting-papers"
    description = "This feed contains papers that the %s is particularly interested in." % settings.LAB_NAME

    def items(self):
        '''The items returned by this feed are papers set as interesting.'''
        return Publication.objects.filter(interesting_paper=True) class CommentaryFeed(Feed):
    '''This class defines the feed for commentaries.'''

    title = "Commentaries by the %s" % settings.LAB_NAME
    link = "/feeds/commentaries"
    description = "Comments, written by members of the %s on papers.  These are typically the results of our internal journal club discussions."

    def items(self):
        '''The items returned by this feed are all Commentary objects.'''
        return Commentary.objects.all()

    def item_title(self, item):
        '''The title of each item will be "Commentary on XXX" or the unicode representation''' 
        return item.__unicode__()

    def item_description(self,item):
        '''The content of the feed is the actual comments.'''
        return item.comments + item.citation

    def item_author_name(self, item):
        '''The author of the item.'''
        return item.author

    def item_author_link(self, item):
        '''The link to the author's page.'''
        return item.author.get_absolute_url()

    def item_pubdate(self, item):
        '''The date of publication of this commentary, not the modification date.'''
        return datetime.combine(item.created, time())

    def item_updateddate(self, item):
        '''The date when this commentary was updated.'''
        return datetime.combine(item.modified, time()) class ProjectsFeed(Feed):
    '''This is the main class for all feeds related to :class:`~papers.models.Publication`.'''
    
    title = "Projects In the %s" % settings.LAB_NAME
    link = "/feeds/projects"
    description = "This feed contains projects being worked on by members of the %s." % settings.LAB_NAME    
    
    def items(self):
        return Project.objects.all()

    def item_title(self, item):
        '''The feed item title is the title of the paper.'''
        return item.title

    def item_description(self, item):
        '''The feed description is the abstract of the paper.'''
        return item.summary class PostsFeed(Feed):
    '''This class defines the feed for posts.'''

    title = "Posts by the %s" % settings.LAB_NAME
    link = "/feeds/posts"
    description = "Blog posts, about papers or interesting topics to our group."

    def items(self):
        '''The items returned by this feed are all Post objects.'''
        return Post.objects.all()

    def item_title(self, item):
        '''The title of each item will be the unicode representation''' 
        return item.__unicode__()

    def item_author_name(self, item):
        '''The author of the item.'''
        return item.author

    def item_author_link(self, item):
        '''The link to the author's page.'''
        return item.author.get_absolute_url()

    def item_pubdate(self, item):
        '''The date of publication of this commentary, not the modification date.'''
        return datetime.combine(item.created, time())

    def item_updateddate(self, item):
        '''The date when this commentary was updated.'''
        return datetime.combine(item.modified, time())

    def item_copyright(self, item):
        '''The copyright is always CC-BY for posts.'''
        return "%s by %s is licensed under a Creative Commons Attribution 4.0 Unported License." %(item, item.author)
from django.conf.urls import include, url
from django.core.urlresolvers import reverse
from django.contrib import admin
from django.contrib.sitemaps import views as sitemap_views
from django.contrib.sitemaps import Sitemap
from django.conf.urls.static import static
from django.conf import settings
from communication.views import FeedDetailView, LabLocationView
from personnel.sitemap import LabPersonnelSitemap
from papers.sitemap import LabPublicationsSitemap, CommentarySitemap
from projects.sitemap import ProjectsSitemap, FundingSitemap
from communication.sitemap import PostsSitemap
from papers.feeds import LabPapersFeed, InterestingPapersFeed, CommentaryFeed
from projects.feeds import ProjectsFeed
from communication.feeds import PostsFeed
from views import IndexView
import communication
'''This package has the url encodings for the main app.'''

#from tastypie.api import Api



#from papers.api import PublicationResource
#from projects.api import ProjectResource
#from personnel.api import PersonnelResource



class StaticViewSitemap(Sitemap):
    '''This sitemap is for all static pages, including list views home and feeds.'''   
 
    priority = 0.4
    changefreq = 'weekly'

    def items(self):
        return ['location','feed-details','laboratory-papers','interesting-papers','commentary-list','laboratory-personnel','laboratory-alumni','project-list', 'post-list', 'twitter','google-calendar','wikipedia','lab-rules','publication-policy','data-resource-policy','lab-news','contact-info','funding-list']

    def location(self, item):
        return reverse(item)

#v1_api = Api(api_name='v1')
#v1_api.register(PublicationResource())
#v1_api.register(ProjectResource())
#v1_api.register(PersonnelResource())

#this dictionary lists sitemap files which will be generated.
sitemaps = {
    'personnel': LabPersonnelSitemap,
    'papers': LabPublicationsSitemap,

    'commentary': CommentarySitemap,