Add "free tier" max template count.
This commit is contained in:
parent
a33f142b4b
commit
0323ee803a
|
@ -6,7 +6,7 @@ import subprocess
|
||||||
import threading
|
import threading
|
||||||
import urllib.parse
|
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 wtforms import Form, SelectField, StringField, TextAreaField, validators
|
||||||
from email_validator import validate_email, EmailNotValidError
|
from email_validator import validate_email, EmailNotValidError
|
||||||
|
|
||||||
|
@ -155,6 +155,9 @@ def logout() -> Response:
|
||||||
return redirect('/')
|
return redirect('/')
|
||||||
|
|
||||||
|
|
||||||
|
FREE_TIER_TEMPLATES = 2
|
||||||
|
|
||||||
|
|
||||||
@writing_blueprint.route('/add_letter')
|
@writing_blueprint.route('/add_letter')
|
||||||
def add_letter() -> Response:
|
def add_letter() -> Response:
|
||||||
email_address = session.get('username')
|
email_address = session.get('username')
|
||||||
|
@ -163,6 +166,8 @@ def add_letter() -> Response:
|
||||||
user = db.get_user(email_address)
|
user = db.get_user(email_address)
|
||||||
|
|
||||||
existing_letter_count = len(db.get_user_letters(user.id))
|
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}'
|
new_letter_name = f'Letter{existing_letter_count + 1}'
|
||||||
default_form_json = jsonify(CLForm().to_cl_data()).get_data(True)
|
default_form_json = jsonify(CLForm().to_cl_data()).get_data(True)
|
||||||
db.add_letter(user.id, new_letter_name, default_form_json)
|
db.add_letter(user.id, new_letter_name, default_form_json)
|
||||||
|
|
Loading…
Reference in New Issue