def website_settings(): loading_icon = dict(current_app.config['LOADING_ICON']) loading_icon = url_for(loading_icon.pop('endpoint'), **loading_icon) result = { 'SITE_NAME': sitename(), 'EMAIL_SITE_NAME': emailsitename(), 'STATIC_V': current_app.static_v, 'LOADING_ICON': loading_icon, 'base': current_app.jinja_env.get_template( 'base.json' if getattr(g, 'is_ajax', False) else 'base.html'), 'contact_types': {x['name']: x for x in current_app.config['CONTACTS']}, 'extra_css': current_app.extra_css, 'extra_js': current_app.extra_js, } for k in [ 'SERVER_NAME', 'PREFERRED_URL_SCHEME', 'DEFAULT_DATE_FORMAT', 'DEFAULT_DATETIME_FORMAT', 'DEFAULT_TIME_FORMAT', ]: result[k] = current_app.config[k] return result
def feed_chapters(): feed = AtomFeed( title='Обновления глав — {}'.format(sitename()), subtitle='Новые главы рассказов', feed_url=request.url, url=request.url_root ) chapters = select(c for c in Chapter if not c.draft and c.story_published) chapters = chapters.order_by(Chapter.first_published_at.desc(), Chapter.order.desc()) count = current_app.config['RSS'].get('chapters', 20) chapters = chapters.prefetch(Chapter.story)[:count] for chapter in chapters: story = chapter.story author = story.authors[0] data = chapter.text_preview feed.add( '{} : {}'.format(chapter.autotitle, story.title), data, content_type='text', author=author.username, url=url_for('chapter.view', story_id=story.id, chapter_order=chapter.order, _external=True), updated=chapter.updated, published=chapter.date, ) return feed.get_response()
def feed_chapters(): feed = AtomFeed(title='Обновления глав — {}'.format(sitename()), subtitle='Новые главы рассказов', feed_url=request.url, url=request.url_root) chapters = select(c for c in Chapter if not c.draft and c.story_published) chapters = chapters.order_by(Chapter.first_published_at.desc(), Chapter.order.desc()) count = current_app.config['RSS'].get('chapters', 20) chapters = chapters.prefetch(Chapter.story)[:count] for chapter in chapters: story = chapter.story author = story.authors[0] data = chapter.text_preview feed.add( '{} : {}'.format(chapter.autotitle, story.title), data, content_type='text', author=author.username, url=url_for('chapter.view', story_id=story.id, chapter_order=chapter.order, _external=True), updated=chapter.updated, published=chapter.date, ) return feed.get_response()
def website_settings(): loading_icon = dict(current_app.config['LOADING_ICON']) loading_icon = url_for(loading_icon.pop('endpoint'), **loading_icon) result = { 'SITE_NAME': sitename(), 'EMAIL_SITE_NAME': emailsitename(), 'SERVER_NAME': current_app.config['SERVER_NAME'], 'PREFERRED_URL_SCHEME': current_app.config['PREFERRED_URL_SCHEME'], 'STATIC_V': current_app.static_v, 'LOADING_ICON': loading_icon, 'base': current_app.jinja_env.get_template('base.json' if getattr(g, 'is_ajax', False) else 'base.html'), 'contact_types': {x['name']: x for x in current_app.config['CONTACTS']}, 'extra_css': current_app.extra_css, 'extra_js': current_app.extra_js, } return result
def feed_stories(): feed = AtomFeed(title='Новые рассказы — {}'.format(sitename()), subtitle='Новые фанфики', feed_url=request.url, url=request.url_root) count = current_app.config['RSS'].get('stories', 20) stories = Story.select_published().order_by( Story.first_published_at.desc(), Story.id.desc())[:count] for story in stories: author = story.authors[0] feed.add(story.title, Markup(story.summary).striptags(), content_type='text', author=author.username, url=url_for('story.view', pk=story.id, _external=True), updated=story.updated, published=story.first_published_at or story.date) return feed.get_response()
def feed_stories(): feed = AtomFeed( title='Новые рассказы — {}'.format(sitename()), subtitle='Новые фанфики', feed_url=request.url, url=request.url_root ) count = current_app.config['RSS'].get('stories', 20) stories = Story.select_published().order_by(Story.first_published_at.desc(), Story.id.desc())[:count] for story in stories: author = story.authors[0] feed.add( story.title, Markup(story.summary).striptags(), content_type='text', author=author.username, url=url_for('story.view', pk=story.id, _external=True), updated=story.updated, published=story.first_published_at or story.date ) return feed.get_response()
def feed_stories_top(): period = request.args.get('period', 0) try: period = int(period) except ValueError: period = 0 if period == 7: title = gettext('Top stories for the week') elif period == 30: title = gettext('Top stories for the month') elif period == 365: title = gettext('Top stories for the year') elif period == 0: title = gettext('Top stories for all time') else: title = ngettext('Top stories in %(num)d day', 'Top stories in %(num)d days', period) feed = AtomFeed( title='{} — {}'.format(title, sitename()), subtitle='Топ рассказов', feed_url=request.url, url=request.url_root ) count = current_app.config['RSS'].get('stories', 20) stories = Story.bl.select_top(period)[:count] for story in stories: author = story.authors[0] feed.add( story.title, Markup(story.summary).striptags(), content_type='text', author=author.username, url=url_for('story.view', pk=story.id, _external=True), updated=story.updated, published=story.first_published_at or story.date ) return feed.get_response()
def feed_accounts(user_id): author = Author.get(id=user_id) if not author: abort(404) feed = AtomFeed(title='Новые рассказы автора {} — {}'.format( author.username, sitename()), subtitle='Новые фанфики', feed_url=request.url, url=request.url_root) count = current_app.config['RSS'].get('accounts', 10) stories = Story.bl.select_by_author(author).order_by( Story.first_published_at.desc(), Story.id.desc())[:count] for story in stories: feed.add(story.title, Markup(story.summary).striptags(), content_type='text', author=author.username, url=url_for('story.view', pk=story.id, _external=True), updated=story.updated, published=story.first_published_at or story.date) return feed.get_response()
def feed_accounts(user_id): author = Author.get(id=user_id) if not author: abort(404) feed = AtomFeed( title='Новые рассказы автора {} — {}'.format(author.username, sitename()), subtitle='Новые фанфики', feed_url=request.url, url=request.url_root ) count = current_app.config['RSS'].get('accounts', 10) stories = Story.bl.select_by_author(author).order_by(Story.first_published_at.desc(), Story.id.desc())[:count] for story in stories: feed.add( story.title, Markup(story.summary).striptags(), content_type='text', author=author.username, url=url_for('story.view', pk=story.id, _external=True), updated=story.updated, published=story.first_published_at or story.date ) return feed.get_response()
def feed_stories_top(): period = request.args.get('period', 0) try: period = int(period) except ValueError: period = 0 if period == 7: title = gettext('Top stories for the week') elif period == 30: title = gettext('Top stories for the month') elif period == 365: title = gettext('Top stories for the year') elif period == 0: title = gettext('Top stories for all time') else: title = ngettext('Top stories in %(num)d day', 'Top stories in %(num)d days', period) feed = AtomFeed(title='{} — {}'.format(title, sitename()), subtitle='Топ рассказов', feed_url=request.url, url=request.url_root) count = current_app.config['RSS'].get('stories', 20) stories = Story.bl.select_top(period)[:count] for story in stories: author = story.authors[0] feed.add(story.title, Markup(story.summary).striptags(), content_type='text', author=author.username, url=url_for('story.view', pk=story.id, _external=True), updated=story.updated, published=story.first_published_at or story.date) return feed.get_response()