def export(): """ Export to OPML or JSON. """ user = UserController(current_user.id).get(id=current_user.id) if request.args.get('format') == "JSON": # Export to JSON for the export of account. try: json_result = export_json(user) except Exception as e: flash(gettext("Error when exporting articles."), 'danger') return redirect(redirect_url()) response = make_response(json_result) response.mimetype = 'application/json' response.headers["Content-Disposition"] \ = 'attachment; filename=account.json' elif request.args.get('format') == "OPML": # Export to the OPML format. categories = {cat.id: cat.dump() for cat in CategoryController(user.id).read()} response = make_response(render_template('opml.xml', user=user, categories=categories, now=datetime.now())) response.headers['Content-Type'] = 'application/xml' response.headers['Content-Disposition'] = 'attachment; filename=feeds.opml' else: flash(gettext('Export format not supported.'), 'warning') return redirect(redirect_url()) return response
def export(): """ Export to OPML or JSON. """ user = UserController(current_user.id).get(id=current_user.id) if request.args.get('format') == "JSON": # Export to JSON for the export of account. try: json_result = export_json(user) except Exception as e: flash(gettext("Error when exporting articles."), 'danger') return redirect(redirect_url()) response = make_response(json_result) response.mimetype = 'application/json' response.headers["Content-Disposition"] \ = 'attachment; filename=account.json' elif request.args.get('format') == "OPML": # Export to the OPML format. categories = { cat.id: cat.dump() for cat in CategoryController(user.id).read() } response = make_response( render_template('opml.xml', user=user, categories=categories, now=datetime.now())) response.headers['Content-Type'] = 'application/xml' response.headers[ 'Content-Disposition'] = 'attachment; filename=feeds.opml' else: flash(gettext('Export format not supported.'), 'warning') return redirect(redirect_url()) return response
def like(article_id=None): """ Mark or unmark an article as favorites. """ art_contr = ArticleController(current_user.id) article = art_contr.get(id=article_id) art_contr = art_contr.update({'id': article_id}, {'like': not article.like}) return redirect(redirect_url())
def delete(category_id=None): category = CategoryController(current_user.id).delete(category_id) flash( gettext( "Category %(category_name)s successfully deleted.", category_name=category.name, ), "success", ) return redirect(redirect_url())
def import_pinboard(): bookmarks = request.files.get('jsonfile', None) if bookmarks: try: nb_bookmarks = import_pinboard_json(current_user, bookmarks.read()) flash(gettext("%(nb_bookmarks)s bookmarks successfully imported.", nb_bookmarks=nb_bookmarks), 'success') except Exception as e: flash(gettext('Error when importing bookmarks.'), 'error') return redirect(redirect_url())
def fetch(feed_id=None): """ Triggers the download of news. News are downloaded in a separated process. """ if conf.CRAWLING_METHOD == "default" \ and (not conf.ON_HEROKU or current_user.is_admin): misc_utils.fetch(current_user.id, feed_id) flash(gettext("Downloading articles..."), "info") else: flash(gettext("The manual retrieving of news is only available " + "for administrator, on the Heroku platform."), "info") return redirect(redirect_url())
def expire(): """ Delete articles older than the given number of weeks. """ current_time = datetime.utcnow() weeks_ago = current_time - timedelta(int(request.args.get('weeks', 10))) art_contr = ArticleController(current_user.id) query = art_contr.read(__or__={'date__lt': weeks_ago, 'retrieved_date__lt': weeks_ago}) count = query.count() query.delete() db.session.commit() flash(gettext('%(count)d articles deleted', count=count), 'info') return redirect(redirect_url())
def export(): """ Export articles to JSON. """ user = UserController(current_user.id).get(id=current_user.id) try: json_result = export_json(user) except Exception as e: flash(gettext("Error when exporting articles."), 'danger') return redirect(redirect_url()) response = make_response(json_result) response.mimetype = 'application/json' response.headers["Content-Disposition"] \ = 'attachment; filename=account.json' return response
def import_pinboard(): bookmarks = request.files.get("jsonfile", None) if bookmarks: nb_bookmarks = import_pinboard_json(current_user, bookmarks.read()) try: nb_bookmarks = import_pinboard_json(current_user, bookmarks.read()) flash( gettext( "%(nb_bookmarks)s bookmarks successfully imported.", nb_bookmarks=nb_bookmarks, ), "success", ) except Exception: flash(gettext("Error when importing bookmarks."), "error") return redirect(redirect_url())
def fetch(feed_id=None): """ Triggers the download of news. News are downloaded in a separated process. """ if conf.CRAWLING_METHOD == "default" and current_user.is_admin: misc_utils.fetch(current_user.id, feed_id) flash(gettext("Downloading articles..."), "info") else: flash( gettext( "The manual retrieving of news is only available " + "for administrator, on the Heroku platform." ), "info", ) return redirect(redirect_url())
def expire(): """ Delete articles older than the given number of weeks. """ current_time = datetime.utcnow() weeks_ago = current_time - timedelta(int(request.args.get('weeks', 10))) art_contr = ArticleController(current_user.id) query = art_contr.read(__or__={ 'date__lt': weeks_ago, 'retrieved_date__lt': weeks_ago }) count = query.count() query.delete() db.session.commit() flash(gettext('%(count)d articles deleted', count=count), 'info') return redirect(redirect_url())
def mark_as(new_value='read', feed_id=None, article_id=None): """ Mark all unreaded articles as read. """ readed = new_value == 'read' art_contr = ArticleController(current_user.id) filters = {'readed': not readed} if feed_id is not None: filters['feed_id'] = feed_id message = 'Feed marked as %s.' elif article_id is not None: filters['id'] = article_id message = 'Article marked as %s.' else: message = 'All article marked as %s.' art_contr.update(filters, {"readed": readed}) flash(gettext(message % new_value), 'info') if readed: return redirect(redirect_url()) return redirect('home')
def delete_all(): "Delete all bookmarks." bookmark = BookmarkController(current_user.id).read().delete() db.session.commit() flash(gettext("Bookmarks successfully deleted."), 'success') return redirect(redirect_url())
def delete(category_id=None): category = CategoryController(current_user.id).delete(category_id) flash(gettext("Category %(category_name)s successfully deleted.", category_name=category.name), 'success') return redirect(redirect_url())