def add_collection_to_g(): if not hasattr(g, "collection"): try: collection = controllers.get_current_collection() setattr(g, "collection", collection) except Exception, e: # discutir o que fazer aqui setattr(g, "collection", {})
def add_collection_to_g(): if not hasattr(g, 'collection'): try: collection = controllers.get_current_collection() setattr(g, 'collection', collection) except Exception: # discutir o que fazer aqui setattr(g, 'collection', {})
def collection_list_feed(): language = session.get('lang', get_locale()) collection = controllers.get_current_collection() title = 'SciELO - %s - %s' % (collection.name, _('Últimos periódicos inseridos na coleção')) subtitle = _('10 últimos periódicos inseridos na coleção %s' % collection.name) feed = AtomFeed(title, subtitle=subtitle, feed_url=request.url, url=request.url_root) journals = controllers.get_journals_paginated(title_query='', page=1, order_by='-created', per_page=10) if not journals.items: feed.add('Nenhum periódico encontrado', url=request.url, updated=datetime.now()) for journal in journals.items: issues = controllers.get_issues_by_jid(journal.jid, is_public=True) last_issue = issues[0] if issues else None articles = [] if last_issue: articles = controllers.get_articles_by_iid(last_issue.iid, is_public=True) result_dict = OrderedDict() for article in articles: section = article.get_section_by_lang(language[:2]) result_dict.setdefault(section, []) result_dict[section].append(article) context = { 'journal': journal, 'articles': result_dict, 'language': language, 'last_issue': last_issue } feed.add(journal.title, render_template("collection/list_feed_content.html", **context), content_type='html', author=journal.publisher_name, url=url_external('main.journal_detail', url_seg=journal.url_segment), updated=journal.updated, published=journal.created) return feed.get_response()
def collection_list_feed(): default_lang = current_app.config.get('BABEL_DEFAULT_LOCALE') language = session.get('lang', default_lang) or default_lang collection = controllers.get_current_collection() title = 'SciELO - %s - %s' % (collection.name, _('Últimos periódicos inseridos na coleção')) subtitle = _('10 últimos periódicos inseridos na coleção %s' % collection.name) feed = AtomFeed(title, subtitle=subtitle, feed_url=request.url, url=request.url_root) journals = controllers.get_journals_paginated( title_query='', page=1, order_by='-created', per_page=10) if not journals.items: feed.add('Nenhum periódico encontrado', url=request.url, updated=datetime.now()) for journal in journals.items: issues = controllers.get_issues_by_jid(journal.jid, is_public=True) last_issue = issues[0] if issues else None articles = [] if last_issue: articles = controllers.get_articles_by_iid(last_issue.iid, is_public=True) result_dict = OrderedDict() for article in articles: section = article.get_section_by_lang(language[:2]) result_dict.setdefault(section, []) result_dict[section].append(article) context = { 'journal': journal, 'articles': result_dict, 'language': language, 'last_issue': last_issue } feed.add(journal.title, render_template("collection/list_feed_content.html", **context), content_type='html', author=journal.publisher_name, url=url_external('main.journal_detail', url_seg=journal.url_segment), updated=journal.updated, published=journal.created) return feed.get_response()
def collection_list_feed(): default_lang = current_app.config.get("BABEL_DEFAULT_LOCALE") language = session.get("lang", default_lang) or default_lang collection = controllers.get_current_collection() title = "SciELO - %s - %s" % (collection.name, _("Últimos periódicos inseridos na coleção")) subtitle = _("10 últimos periódicos inseridos na coleção %s" % collection.name) feed = AtomFeed( title, subtitle=subtitle, logo=utils.get_resources_url(g.collection.logo_resource, "img", language), feed_url=request.url, url=request.url_root, ) journals = controllers.get_journals_paginated(title_query="", page=1, order_by="-created", per_page=10) if not journals.items: feed.add("Nenhum periódico encontrado", url=request.url, updated=datetime.now()) for journal in journals.items: issues = controllers.get_issues_by_jid(journal.jid, is_public=True) last_issue = issues[0] if issues else None articles = [] if last_issue: articles = controllers.get_articles_by_iid(last_issue.iid, is_public=True) result_dict = OrderedDict() for article in articles: section = article.get_section_by_lang(language[:2]) result_dict.setdefault(section, []) result_dict[section].append(article) context = {"journal": journal, "articles": result_dict, "language": language, "last_issue": last_issue} feed.add( journal.title, render_template("collection/list_feed_content.html", **context), content_type="html", author=journal.publisher_name, url=url_external("main.journal_detail", url_seg=journal.url_segment), updated=journal.updated, published=journal.created, ) return feed.get_response()
def test_get_current_collection(self): collection = utils.makeOneCollection() controller_col = controllers.get_current_collection() self.assertEqual(collection, controller_col)