def feed(self): feed = Atom1Feed(u'Сказка: Форум', self.request.build_absolute_uri('/'), u'Новые темы на форуме мморпг «Сказка»', language=u'ru', feed_url=self.request.build_absolute_uri( reverse('forum:feed'))) threads = [ ThreadPrototype(model=thread) for thread in Thread.objects.filter(subcategory__restricted=False). order_by('-created_at')[:forum_settings.FEED_ITEMS_NUMBER] ] for thread in threads: if datetime.datetime.now( ) - thread.created_at < datetime.timedelta( seconds=forum_settings.FEED_ITEMS_DELAY): continue post = PostPrototype(model=Post.objects.filter( thread_id=thread.id).order_by('created_at')[0]) url = self.request.build_absolute_uri( reverse('forum:threads:show', args=[thread.id])) feed.add_item(title=thread.caption, link=url, description=post.safe_html, pubdate=thread.created_at, unique_id=url) return self.atom(feed.writeString('utf-8'))
def atom(request, issue=None): issue = Issue.objects.get(is_default=True, is_published=True, language=request.language) articles = issue.article_set.filter(is_published=True).all() feed = Atom1Feed(title=request.locals['magazine_name'] + u' - ' + issue.title + u' ' + request.locals['number'], link=u'http://' + request.get_host() + request.get_full_path(), description=request.locals['magazine_slogan'], subtitle=request.locals['magazine_slogan']) for article in articles: intro_text = article.intro_text if not intro_text: intro_text = '' guid = article.guid if not guid: guid = '' feed.add_item(title=article.headline, link=u'http://' + request.get_host() + article.get_absolute_url(), description=intro_text, pubdate=article.created_at, unique_id=guid) return HttpResponse(feed.writeString('UTF-8'), mimetype='application/atom+xml')
def atomFeed(req): """Generates an Atom syndication feed for shared searches. Returns an XML string.""" ctx = getsearchresults(req) feed = Atom1Feed( _('Search: ') + ctx['q'], u'/catalog/feed/atom/', _('Fac-Back-OPAC Search in Atom syndication')) return feedCreator(ctx, feed)
def add_item(self,**kwargs): # add item on the feed makes u feed it the title link # and description, this is annoying title = kwargs.get('title') link = kwargs.get('link') description = kwargs.get('description') del kwargs['link'] del kwargs['title'] del kwargs['description'] return _Atom1Feed.add_item(self,title,link,description,**kwargs)
def _convert_feed(input_feed, current_url): # TODO more params? return Atom1Feed(title=input_feed['title'], link=input_feed['link'], description=_try_extract(input_feed['description']) or _try_extract(input_feed['subtitle']), language=_try_extract(input_feed, 'language'), subtitle=(_try_extract(input_feed, 'subtitle') + _(' // via Feed Muncher')).strip(), feed_url=current_url, feed_copyright=_try_extract(input_feed, 'rights'))
def generate_failed_feed(e, munched_feed_url, source_feed_url, now): failed_feed = Atom1Feed( title=_('Error in Feed Muncher'), link=munched_feed_url, description=_('There was an error while munching this feed.'), subtitle=_('Feed Muncher')) failed_feed.add_item( title='Error in Feed Muncher', link=munched_feed_url, description=_( 'There was an error processing your feed in Feed Muncher. ' 'An exception was thrown. %(exception)r' % {'exception': e}), author_name=_('Feed Muncher'), pubdate=now, unique_id=source_feed_url + ':error', unique_id_is_permalink=False, updateddate=now) return failed_feed
def gen(self, args): # TODO generalize posts = self.posts() with open(config["index_path"], mode="w") as index: print("Writing index <%s> (%s most recent posts) ..." % (index.name, N_POSTS)) write_template(index, "index.html", recent_posts=posts[:N_POSTS]) print("Writing posts ...") for post in posts: with open(post.output_path, mode="w") as op: write_template(op, "post.html", post=post) with open(config["archive_path"], mode="w") as archive: print("Writing archive <%s>" % archive.name) write_template(archive, "archive.html", posts=posts) print("Writing ATOM feed ...") feed = Atom1Feed(**config["feed"]) [feed.add_item(**feedify(post).__dict__) for post in posts] with open(config["feed"]["feed_url"], mode="w") as f: f.write(feed.writeString("UTF-8")) print("Copying assets ...") copy_tree(config["assets_path"], OUTPUT_PATH) print("Generation done.")
def entry(request, path): def entry_url(p): return request.build_absolute_uri( ensure_trailing_slash( reverse("bumble.bumbl.views.entry", args=[urlify_path(p)]))) try: full_path = normalize_path(request.get_full_path()) redirection = Redirect.objects.get(redirect_from=full_path) return redirect(link=entry_url(redirection.redirect_to), permanent=redirection.permanent) except: pass path = normalize_path(path) if path.endswith("/feed"): path = path[0:-len("/feed")] if "/tag/" in path: path, tags = path.split("/tag/") entry = get_entry(path, request) feed = Atom1Feed(title=entry.title + ":" + tags, description=tags, link=entry_url(path) + "tag/" + tags) entries = get_tag_entries(tags.split("+"), path) for e in entries: feed.add_item(title=e.title, description=md(filepaths(e.lead)), link=entry_url(e.path), pubdate=e.created) return HttpResponse(feed.writeString("UTF-8"), content_type="application/atom+xml") entry = get_entry(path, request) feed = Atom1Feed(title=entry.title, description=entry.lead, link=entry_url(path)) entries = Entry.objects.filter(path__startswith=path + '/', created__lte=now()).order_by("-created") for e in entries: feed.add_item(title=e.title, description=md(filepaths(e.lead)), link=entry_url(e.path), pubdate=e.created) return HttpResponse(feed.writeString("UTF-8"), content_type="application/atom+xml") if "/tag/" in path: entry_path, tags = path.split("/tag/") return render_to_response( 'tag.html', { 'media': settings.MEDIA_URL, 'entry': get_entry(entry_path, request), 'tags': tags.split("+"), "entries": get_tag_entries(tags.split("+"), entry_path)[0:PAGINATION], 'pagination_url': reverse("bumble.bumbl.views.page", args=[578329023, urlify_path(path)]), 'feed_url': entry_url(path) + "feed" }) e = get_entry(path, request) recaptcha_error = None if request.method == "POST": form = CommentForm(request.POST) try: recaptcha_result = verify_recaptcha( request.META['REMOTE_ADDR'], request.POST['recaptcha_challenge_field'], request.POST['recaptcha_response_field']) except: return HttpResponseForbidden() if not recaptcha_result[0]: recaptcha_error = recaptcha_result[1] else: if form.is_valid(): new_comment = form.save(commit=False) new_comment.entry = e new_comment.ip = request.META['REMOTE_ADDR'] new_comment.save() mail_admins("New comment by " + new_comment.commenter, new_comment.text, html_message="<html><body><a href=\"" + entry_url(path) + "#" + str(new_comment.id) + "\">" + new_comment.commenter + "</a><br>" + new_comment.text + "</body></html>") return HttpResponseRedirect(request.path) else: form = CommentForm() c = { 'media': settings.MEDIA_URL, 'entry': e, 'commentForm': form, 'recaptcha_key': RECAPTCHA_PUBLIC, 'recaptcha_error': recaptcha_error, 'descendents': Entry.objects.filter( path__startswith=path + '/', created__lte=now()).order_by("-created")[0:PAGINATION], 'pagination_url': reverse("bumble.bumbl.views.page", args=[578329023, urlify_path(path)]), 'feed_url': entry_url(path) + "feed", 'user': request.user } c.update(csrf(request)) return render_to_response('entry.html', c)
def render_atom(self, request, context, template_name): (title, desc, link) = extractFeedDetails(request) feed = Atom1Feed(title, link, desc) return self.renderGeneralFeed(request, context, template_name, feed)