コード例 #1
0
def remove_fqs(_, fqs_id):
    source = FullyQualifiedSource.by_id(fqs_id)
    back = source.feed.route
    if source:
        source.delete()

    return redirect(redirect_back(back))
コード例 #2
0
def update_fqs(_, fqs_id):
    source = FullyQualifiedSource.by_id(fqs_id)

    try:
        articles = source.get_links()

        for article in articles:
            # skip if article already posted
            if Link.by_slug(article["slug"]) is not None:
                continue
            link = Link(
                title=article["title"],
                slug=article["slug"],
                text=article["text"],
                url=article["url"],
                feed_id=source.feed_id,
                user_id=12345,
            )
            link.commit()
        source.next_update = datetime.now() + timedelta(
            seconds=source.update_interval)
        source.save()
    except Exception as e:
        flash("Could not parse the RSS feed on URL".format(source.url),
              "error")

    return redirect(redirect_back(source.feed.route))
コード例 #3
0
def remove_link(feed, link_id):
    """
    Removes link from given feed
    This is a hard delete, so be careful
    :param feed: feed
    :param link_slug: link slug
    :return:
    """
    link = Link.by_id(link_id)
    if link is None:
        abort(404)
    link.delete()
    return redirect(redirect_back(feed.route))
コード例 #4
0
def save_link(link):
    """
    Save link to saved links
    :param link_slug: link slug
    :return:
    """
    if Ban.by_user_and_feed(current_user, link.feed) is not None:
        abort(403)

    # save the link
    saved_link = SavedLink(user_id=current_user.id, link_id=link.id)
    saved_link.commit()

    return redirect(redirect_back(link.route))
コード例 #5
0
def ban_user(feed, username):
    user = User.by_username(username)
    if user is None:
        abort(404)

    if Ban.by_user_and_feed(user, feed) is not None:
        flash("This user is already baned", "info")
        return redirect(redirect_back(feed.route + "/admin/reports"))

    ban_form = BanForm()
    ban_form.fill(user)

    return render_template("ban_user.html",
                           feed=feed,
                           form=ban_form,
                           user=user)
コード例 #6
0
ファイル: auth.py プロジェクト: matoous/newz
def post_login():
    """
    Login existing user
    :return:
    """
    if current_user.is_authenticated:
        return redirect("/")

    form = LoginForm()
    if form.validate():
        user = form.user()
        user.login(form.remember_me.data)
        return redirect(redirect_back("/"))

    return render_template("login.html",
                           form=form,
                           show_logo=True,
                           hide_menues=True)
コード例 #7
0
ファイル: comments.py プロジェクト: matoous/newz
def do_comment_vote(comment, vote_str=None):
    """
    Vote on comment
    :param comment_id: comment id
    :param vote_str: vote type
    :return:
    """
    if comment.link.archived:
        abort(405)

    vote = vote_type_from_string(vote_str)
    if comment is None or vote is None:
        abort(404)

    vote = CommentVote(user_id=current_user.id,
                       comment_id=comment.id,
                       vote_type=vote)
    vote.apply()

    return redirect(redirect_back(comment.link.route))
コード例 #8
0
def do_vote(link, vote_str=None):
    """
    Vote on link
    All kinds of votes are handled here (up, down, unvote)
    :param link: link
    :param vote_str:  vote type
    :return:
    """
    if (current_user.is_authenticated
            and Ban.by_user_and_feed(current_user, link.feed) is not None):
        abort(403)

    if link.archived:
        abort(405)

    vote = vote_type_from_string(vote_str)
    vote = LinkVote(user_id=current_user.id, link_id=link.id, vote_type=vote)
    vote.apply()

    return redirect(redirect_back(link.route))
コード例 #9
0
def remove_link(link):
    if current_user.is_feed_admin(link.feed) or current_user.is_god():
        link.delete()
        return redirect(redirect_back(link.feed.route))
    else:
        abort(403)
コード例 #10
0
def remove_avatar():
    current_user.profile_pic = None
    current_user.update_with_cache()
    return redirect(redirect_back(current_user.route))