示例#1
0
def subscribe(author_id):
    """
    Create a Subscription to an author
    """
    author = Author.query.get_or_404(author_id)

    sub = (
        db.session.query(Subscription)
        .filter(
            Subscription.user_id == current_user.id, Subscription.author_id == author.id
        )
        .first()
    )

    if not sub:
        sub = Subscription(user=current_user, author=author, active=True)
        app.logger.info("%s created", sub)
    else:
        sub.active = True
        app.logger.info("%s set to active", sub)

    if not sub.periods:
        sub.add_period(PERIOD.DAILY)

    sub.save()

    update_user_rss.send(bp, users=[current_user])

    flash(
        f"Successfully created a {sub.period_string()} Email Subscription to {author.name}",
        ALERT.SUCCESS,
    )

    return redirect_back("authors.authors")
示例#2
0
def subscribe(author_id):
    author = Author.query.get_or_404(author_id)
    sub = Subscription.query.filter(
        Subscription.user_id == current_user.id,
        Subscription.author_id == author.id).first()
    if not sub:
        sub = Subscription(user=current_user, author=author, active=True)
        app.logger.info(u'Subscription {0} created'.format(sub))
    else:
        sub.active = True
        app.logger.info(u'Subscription {0} set to active'.format(sub))
    if not sub.periods:
        sub.add_period(PERIOD.DAILY)
    sub.save()
    flash(u'Successfully created a {0} Email Subscription to {1}'.format(
        sub.period_string(), author.name), ALERT.SUCCESS)
    return redirect_back('authors.authors')