def latest_contents_feed(request): try: syndicationFeed = Rss201rev2Feed(title = "The Reckoner! Blog Feed!", link = "".join((settings.SITE_ROOT,"/blog",)), description = "The freshest blog content on the Reckon Blog!", subtitle = "The freshest blog content on the Reckon Blog!", feed_url = "".join((settings.SITE_ROOT,"/feed/blog",))) contents_response = client_get_contents(sort_by="postingDate", ascending=False, page=0, size=5) if (contents_response.status.success): if (contents_response.contents): for content in contents_response.contents: syndicationFeed.add_item(title=content.title, link="".join((settings.SITE_ROOT,content.getURL(),)), description=content.body, pubdate=content.posting_date, author_name="The Reckoner!", author_link=settings.SITE_ROOT) return HttpResponse(syndicationFeed.writeString("utf-8"), mimetype="text/xml") else: logger.error("Error from getting Blog RSS feed: " + contents_response.status.message) except Exception: logger.error("Exception when showing and processing Blog RSS Feed:") logger.error(traceback.print_exc(8)) raise Exception return HttpResponse("", mimetype="text/xml")
def get_recent_blog_ajax(request, id = None): site_response = AjaxServiceResponse(success=False, message="whoops", message_description='No go. Try again later.') if (request.user.has_perm('VIEW_CONTENT')): try: if request.method == 'GET': size = request.GET.get("size", "1") service_response = client_get_contents(type="BLOG", page=0, size=int(size), sort_by="postingDate", ascending=False) if (service_response.status.success): site_response = ContentAjaxResponse(contents=service_response.contents, success=service_response.status.success) else: logger.error("Error when retrieving recent blog posts: " + service_response.status.message) except Exception: logger.error("Exception when retrieving recent blog posts:") logger.error(traceback.print_exc(8)) return HttpResponse(site_response.getXMLString())
def set_podcast_info(request): ''' Used to ensure the latest podcast is always available for the sidebar in the Django templates. If the sidebar DOESN'T INCLUDE THE LATEST PODCAST, DELETE THIS. There is no reason to make the call if not necessary. ''' content_list_response = client_get_contents(type = "PODCAST", page=0, size=1, sort_by="postingDate", ascending=False) if (content_list_response.contents): content = content_list_response.contents[0] else: content = None return {'last_podcast' : content}
def createContentsSitemap(request): ''' Function responsible for returning Content URLs to be included in The Reckoner sitemap, as used for search engine traversal. Return value is a SiteMap object. ''' siteMapUrlList = [] # Contents contents_response = client_get_contents(sort_by="postingDate", ascending=False, session_id=request.user.session_id) if (contents_response.status.success): for content in contents_response.contents: siteMapUrlList.append(SiteMapUrl(loc="".join((settings.SITE_ROOT,content.getURL(),)), changefreq='monthly', priority='0.6')) return SiteMap(urls = siteMapUrlList)
def latest_podcasts_feed(request): try: syndicationFeed = iTunesPodcastsFeedGenerator(title = settings.PODCAST_TITLE, link = "".join((settings.SITE_ROOT,)), description = settings.PODCAST_DESCRIPTION, subtitle = settings.PODCAST_SUBTITLE, feed_url = "".join((settings.SITE_ROOT,"/feed/podcast",)), author_name = settings.PODCAST_AUTHOR, category = settings.PODCAST_ITUNES_CATEGORY, itunes_explicit = settings.PODCAST_ITUNES_EXPLICIT, itunes_name = settings.PODCAST_AUTHOR_NAME, itunes_email = settings.CONTACT_US_EMAIL, itunes_image_url = settings.PODCAST_ITUNES_IMAGE, itunes_keywords = settings.PODCAST_ITUNES_KEYWORDS, itunes_podcast_id = settings.PODCAST_ITUNES_ID, itunes_block = settings.PODCAST_BLOCKED) contents_response = client_get_contents(type="PODCAST", sort_by="postingDate", ascending=False, page=0, size=50) if (contents_response.status.success): if (contents_response.contents): for content in contents_response.contents: # Check to make sure media is attached to the content. # If so, check for audio elements and images. Assume the last attached is best. # If no attached audio files are found, move along to the next one. if (content.media_items): image_url = settings.PODCAST_ITUNES_IMAGE podcast = None for media in content.media_items: if (media.media_type == "AUDIO"): podcast = media elif (media.media_type == "IMAGE"): image_url = media.url # Add in tracking prefix to URL by splitting off the http prefix and adding the prefix string. url_seq = media.url.split("//", 1) if (len(url_seq) == 2): url = "".join((settings.PODCAST_TRACKING_PREFIX, url_seq[1],)) else: url = "".join((settings.PODCAST_TRACKING_PREFIX, url_seq[0],)) if (podcast): syndicationFeed.add_item(title=media.name, link="".join((settings.SITE_ROOT,content.getURL(),)), description=content.summary, pubdate=content.posting_date, subtitle=content.summary, summary=content.summary, duration=media.duration, url=url, type=media.file_type, bytes=media.size, guid=media.media_id, block = settings.PODCAST_BLOCKED, explicit = settings.PODCAST_ITUNES_EXPLICIT, itunes_image_url=image_url, itunes_keywords=content.getTagCSV()) return HttpResponse(syndicationFeed.writeString("utf-8"), mimetype="text/xml") else: logger.error("Error from getting Podcast RSS feed: " + contents_response.status.message) except Exception: logger.error("Exception when showing and processing Podcast RSS Feed:") logger.error(traceback.print_exc(8)) raise Exception return HttpResponse("", mimetype="text/xml")
def content_list_page(request, content_type="blog"): page_url = "".join(("/", content_type)) errors={} try: if request.method == 'GET': page = request.GET.get('page', None) size = request.GET.get('size', None) tag = request.GET.get('tag', None) month = request.GET.get('month', None) year = request.GET.get('year', None) posted_after = None posted_before = None if (month and year): if (int(month) > 11): next_month = '1' next_year = str(int(year) + 1) posted_after = convertFormToDateTime("".join((month,"/01/",year," 00:01"))) posted_before = convertFormToDateTime("".join((next_month,"/01/",next_year," 00:01"))) else: next_month = str(int(month) + 1) posted_after = convertFormToDateTime("".join((month,"/01/",year," 00:01"))) posted_before = convertFormToDateTime("".join((next_month,"/01/",year," 00:01"))) # Persist the filter information. Keep it if we're moving across pages. if (tag is not None): request.session[content_type + '-include-tags'] = tag elif (page is not None): tag = request.session.get(content_type + '-include-tags', None) if (posted_after is not None): request.session[content_type + '-posted-after'] = posted_after elif (page is not None): posted_after = request.session.get(content_type + '-posted-after', None) if (posted_before is not None): request.session[content_type + '-posted-before'] = posted_before elif (page is not None): posted_before = request.session.get(content_type + '-posted-before', None) if not page: page = '1' if not size: size = '5' content_list_response = client_get_contents(type = content_type, page=(int(page)-1), size=int(size), include_tags = tag, posted_before=posted_before, posted_after=posted_after, sort_by="postingDate", ascending=False) context = {'page': int(page), 'size': int(size), 'contents' : content_list_response.contents, 'page_url' : page_url, 'errors' : errors} context.update(pageDisplay(page, size, content_list_response.count)) context.update(getContentTagContext(request, content_type)) context.update(getContentMonthContext(request)) c = RequestContext(request, context) if (content_type == "podcast"): return render_to_response('podcast_list.html', c) elif (content_type == "video"): return render_to_response('video_list.html', c) return render_to_response('blog_list.html', c) except Exception: logger.error("Exception when rending content list page:") logger.error(traceback.print_exc(8)) raise Exception