Example #1
0
def feed_latest(request):
    entry = EntryDetail()
    entries = entry.get_queryset().filter(
        status=PUBLISHED).order_by('-creation_date')[:50]
    for entry in entries:
        if entry.entry_type == TYPE_ANNOUNCEMENT:
            url = entry.get_absolute_url().replace('/blog/', '/announcement/')
            entry.urls = url
        else:
            entry.urls = entry.get_absolute_url()
    items = []
    for entry in entries:
        link = "%s%s" % (settings.BASE_URL, entry.urls)
        enclosure = None
        if entry.image:
            enclosure = PyRSS2Gen.Enclosure(entry.image.url, 1024,
                                            'image/jpeg')
        item = PyRSS2Gen.RSSItem(title=entry.title,
                                 link=link,
                                 guid=PyRSS2Gen.Guid(link),
                                 enclosure=enclosure,
                                 pubDate=entry.creation_date)
        items.append(item)
    rss = PyRSS2Gen.RSS2(title='newtonproject.org',
                         link="%s/feed/" % settings.BASE_URL,
                         description="newtonproject",
                         lastBuildDate=datetime.datetime.now(),
                         docs='%s/about/' % settings.BASE_URL,
                         items=items)
    rss.rss_attrs['xmlns:atom'] = 'http://www.w3.org/2005/Atom'
    xml = rss.to_xml(encoding='UTF-8')
    return HttpResponse(xml, mimetype='application/rss+xml;charset=utf-8')
Example #2
0
 def get_queryset(self):
     language = translation.get_language()
     language_code = codes.EntryLanguage.ENGLISH.value
     for language_item in settings.LANGUAGE_LIST:
         if language.startswith(language_item[0]):
             language_code = language_item[1]
             break
     entry = EntryDetail()
     entries = entry.get_queryset().filter(entry_type=TYPE_ANNOUNCEMENT, language=language_code, status=PUBLISHED)
     if not entries:
         entries = entry.get_queryset().filter(entry_type=TYPE_ANNOUNCEMENT,
                                               language=codes.EntryLanguage.ENGLISH.value, status=PUBLISHED)
     for entry in entries:
         url = entry.get_absolute_url().replace('/blog/', '/announcement/')
         entry.urls = url
     return entries
Example #3
0
 def get_queryset(self):
     language = translation.get_language()
     language_code = codes.EntryLanguage.ENGLISH.value
     for language_item in settings.LANGUAGE_LIST:
         if language.startswith(language_item[0]):
             language_code = language_item[1]
             break
     entry = EntryDetail()
     if language_code == codes.EntryLanguage.CHINESE.value:
         entries = entry.get_queryset().filter(entry_type=TYPE_COMMUNITY_VOICE,
                                               language=codes.EntryLanguage.CHINESE.value, status=PUBLISHED)
     else:
         entries = entry.get_queryset().filter(entry_type=TYPE_COMMUNITY_VOICE,
                                               language=codes.EntryLanguage.ENGLISH.value, status=PUBLISHED)
     for entry in entries:
         url = entry.get_absolute_url().replace('/blog/', '/community-voice/')
         entry.urls = url
     return entries