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 export(): """ Export articles to JSON. """ user = UserController(current_user.id).get(id=current_user.id) try: json_result = export_json(user) except Exception: 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 application.config["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 delete_all(): "Delete all bookmarks." BookmarkController(current_user.id).read().delete() db.session.commit() flash(gettext("Bookmarks successfully deleted."), "success") return redirect(redirect_url())