def unsubscribe(author_id): """ Unsubscribe from 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: app.logger.warning("No subscription found for %s and %s", current_user, author) flash(f"No Subscription found for {author.name}", ALERT.WARNING) return redirect(url_for("authors.authors")) sub.active = False sub.save() app.logger.info("%s set to inactive", sub) update_user_rss.send(bp, users=[current_user]) flash(f"Successfully Unsubscribed from {author.name}", ALERT.SUCCESS) return redirect_back("authors.authors")
def add_period(): """ Add an email notification period to a Subscription """ period_name = request.args.get("period") sub_id = request.args.get("subscription_id") sub = Subscription.query.filter_by(id=sub_id).first() if sub.has_period(period_name): flash( f"You already receive {period_name} Emails for {sub.author.name}", ALERT.WARNING, ) return redirect(url_for("users.user_home")) sub.add_period(period_name) sub.save() app.logger.info("Period %s added to %s", period_name, sub) flash( f"Successfully added {period_name} Email to your Subscription to {sub.author.name}", ALERT.SUCCESS, ) return redirect_back("users.user_home")
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")
def remove_period(): """ Remove an Email notification Period from a Subscription """ period_name = request.args.get("period") sub_id = request.args.get("subscription_id") sub = Subscription.query.filter_by(id=sub_id).first() sub.remove_period(period_name) sub.save() if len(sub.periods) == 0: flash( f"You will no longer receive Email notifications for {sub.author.name}", ALERT.WARNING, ) app.logger.info("Period %s removed from %s", period_name, sub) flash( f"Successfully removed {period_name} Email from Subscription to {sub.author.name}", ALERT.SUCCESS, ) return redirect_back("users.user_home")
def add_period(): period_name = request.args.get('period') sub_id = request.args.get('subscription_id') sub = Subscription.query.filter_by(id=sub_id).first() if sub.has_period(period_name): flash(u'You already receive {0} emails for Subscription {1}' .format(period_name, sub), ALERT.WARNING) return redirect(url_for('users.user_home')) sub.add_period(period_name) sub.save() app.logger.info(u'Period {0} added to Subscription {1}' .format(period_name, sub)) flash(u'Successfully added {0} email to Subscription {1}' .format(period_name, sub.author.name), ALERT.SUCCESS) return redirect_back('users.user_home')
def remove_period(): period_name = request.args.get('period') sub_id = request.args.get('subscription_id') sub = Subscription.query.filter_by(id=sub_id).first() sub.remove_period(period_name) sub.save() if len(sub.periods) == 0: flash( u'You will no longer receive email notifications for Subscription {0}' .format(sub), ALERT.WARNING) app.logger.info(u'Period {0} removed from Subscription {1}' .format(period_name, sub)) flash(u'Successfully removed {0} email from Subscription to {1}' .format(period_name, sub.author.name), ALERT.SUCCESS) return redirect_back('users.user_home')
def unsubscribe(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: app.logger.warning(u'No subscription found for User {0} and Author {1}' .format(current_user, author)) flash(u'No Subscription found for {0}'.format(author.name), ALERT.WARNING) return redirect(url_for('authors.authors')) sub.active = False sub.save() app.logger.info(u'Subscription {0} set to inactive'.format(sub)) flash(u'Successfully Unsubscribed from {0}'.format(author.name), ALERT.SUCCESS) return redirect_back('authors.authors')
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')