Statistics
| Branch: | Tag: | Revision:

root / cloudcmsblog / feeds.py @ master

History | View | Annotate | Download (2.6 kB)

1 bd2ee623 Kostas Papadimitriou
# Copyright 2012 GRNET S.A. All rights reserved.
2 bd2ee623 Kostas Papadimitriou
#
3 bd2ee623 Kostas Papadimitriou
# Redistribution and use in source and binary forms, with or
4 bd2ee623 Kostas Papadimitriou
# without modification, are permitted provided that the following
5 bd2ee623 Kostas Papadimitriou
# conditions are met:
6 bd2ee623 Kostas Papadimitriou
#
7 bd2ee623 Kostas Papadimitriou
#   1. Redistributions of source code must retain the above
8 bd2ee623 Kostas Papadimitriou
#      copyright notice, this list of conditions and the following
9 bd2ee623 Kostas Papadimitriou
#      disclaimer.
10 bd2ee623 Kostas Papadimitriou
#
11 bd2ee623 Kostas Papadimitriou
#   2. Redistributions in binary form must reproduce the above
12 bd2ee623 Kostas Papadimitriou
#      copyright notice, this list of conditions and the following
13 bd2ee623 Kostas Papadimitriou
#      disclaimer in the documentation and/or other materials
14 bd2ee623 Kostas Papadimitriou
#      provided with the distribution.
15 bd2ee623 Kostas Papadimitriou
#
16 bd2ee623 Kostas Papadimitriou
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 bd2ee623 Kostas Papadimitriou
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 bd2ee623 Kostas Papadimitriou
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 bd2ee623 Kostas Papadimitriou
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 bd2ee623 Kostas Papadimitriou
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 bd2ee623 Kostas Papadimitriou
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 bd2ee623 Kostas Papadimitriou
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 bd2ee623 Kostas Papadimitriou
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 bd2ee623 Kostas Papadimitriou
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 bd2ee623 Kostas Papadimitriou
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 bd2ee623 Kostas Papadimitriou
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 bd2ee623 Kostas Papadimitriou
# POSSIBILITY OF SUCH DAMAGE.
28 bd2ee623 Kostas Papadimitriou
#
29 bd2ee623 Kostas Papadimitriou
# The views and conclusions contained in the software and
30 bd2ee623 Kostas Papadimitriou
# documentation are those of the authors and should not be
31 bd2ee623 Kostas Papadimitriou
# interpreted as representing official policies, either expressed
32 bd2ee623 Kostas Papadimitriou
# or implied, of GRNET S.A.
33 bd2ee623 Kostas Papadimitriou
34 bd2ee623 Kostas Papadimitriou
35 bd2ee623 Kostas Papadimitriou
from django.conf import settings
36 bd2ee623 Kostas Papadimitriou
from django.contrib.syndication.views import Feed
37 bd2ee623 Kostas Papadimitriou
38 bd2ee623 Kostas Papadimitriou
from cloudcmsblog.models import Entry
39 bd2ee623 Kostas Papadimitriou
from cloudcms.models import Application
40 bd2ee623 Kostas Papadimitriou
41 bd2ee623 Kostas Papadimitriou
42 bd2ee623 Kostas Papadimitriou
BLOG_FEED_ENTRIES_LIMIT = getattr(settings, 'CLOUDCMSBLOG_FEED_ENTRIES_LIMIT',
43 bd2ee623 Kostas Papadimitriou
                            10)
44 bd2ee623 Kostas Papadimitriou
BLOG_FEED_TITLE = getattr(settings, 'CLOUDCMSBLOG_FEED_TITLE',
45 bd2ee623 Kostas Papadimitriou
                            "Latest blog posts")
46 bd2ee623 Kostas Papadimitriou
BLOG_FEED_LINK = getattr(settings, 'CLOUDCMSBLOG_FEED_LINK',
47 bd2ee623 Kostas Papadimitriou
                            "/feed/")
48 bd2ee623 Kostas Papadimitriou
BLOG_FEED_DESCRIPTION = getattr(settings, 'CLOUDCMSBLOG_FEED_DESCRIPTION',
49 bd2ee623 Kostas Papadimitriou
                            BLOG_FEED_TITLE)
50 bd2ee623 Kostas Papadimitriou
51 bd2ee623 Kostas Papadimitriou
class BlogFeed(Feed):
52 bd2ee623 Kostas Papadimitriou
    title = BLOG_FEED_TITLE
53 bd2ee623 Kostas Papadimitriou
    link = BLOG_FEED_LINK
54 bd2ee623 Kostas Papadimitriou
    description = BLOG_FEED_DESCRIPTION
55 bd2ee623 Kostas Papadimitriou
56 bd2ee623 Kostas Papadimitriou
    def __init__(self, *args, **kwargs):
57 bd2ee623 Kostas Papadimitriou
        pass
58 bd2ee623 Kostas Papadimitriou
59 bd2ee623 Kostas Papadimitriou
    def items(self):
60 bd2ee623 Kostas Papadimitriou
        return Entry.objects.order_by('-published_on')[:BLOG_FEED_ENTRIES_LIMIT]
61 bd2ee623 Kostas Papadimitriou
62 bd2ee623 Kostas Papadimitriou
    def item_title(self, item):
63 bd2ee623 Kostas Papadimitriou
        return item.title
64 bd2ee623 Kostas Papadimitriou
65 bd2ee623 Kostas Papadimitriou
    def item_description(self, item):
66 bd2ee623 Kostas Papadimitriou
        return item.intro_text
67 bd2ee623 Kostas Papadimitriou
68 bd2ee623 Kostas Papadimitriou
    def item_pubdate(self, item):
69 bd2ee623 Kostas Papadimitriou
        return item.published_on