From 0323ee803a6f9a94ccb6ba4ce61604821bd08d23 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Sun, 2 Oct 2022 16:46:06 -0400 Subject: [PATCH] Add "free tier" max template count. --- app/routes.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/routes.py b/app/routes.py index bd7aa16..86070ac 100644 --- a/app/routes.py +++ b/app/routes.py @@ -6,7 +6,7 @@ import subprocess import threading import urllib.parse -from flask import Blueprint, render_template, request, make_response, session, redirect, jsonify, Response +from flask import Blueprint, render_template, request, make_response, session, redirect, jsonify, Response, current_app from wtforms import Form, SelectField, StringField, TextAreaField, validators from email_validator import validate_email, EmailNotValidError @@ -155,6 +155,9 @@ def logout() -> Response: return redirect('/') +FREE_TIER_TEMPLATES = 2 + + @writing_blueprint.route('/add_letter') def add_letter() -> Response: email_address = session.get('username') @@ -163,6 +166,8 @@ def add_letter() -> Response: user = db.get_user(email_address) existing_letter_count = len(db.get_user_letters(user.id)) + if user.in_free_tier() and existing_letter_count >= FREE_TIER_TEMPLATES: + return render_index(error=f'A maximum of {FREE_TIER_TEMPLATES} templates are available to each user.') new_letter_name = f'Letter{existing_letter_count + 1}' default_form_json = jsonify(CLForm().to_cl_data()).get_data(True) db.add_letter(user.id, new_letter_name, default_form_json)