moved form code to application folder

This commit is contained in:
crunk 2024-03-30 18:22:53 +01:00
parent b435b159e3
commit f393f7389f
11 changed files with 10 additions and 217 deletions

View File

@ -22,7 +22,7 @@ Or run `make`.
* currently this software is broken.
## readme driven development
* add regular login instead of a secret key
* add regular login instead of a secret key
* have a settings file for the application ✅
* downloadable pdfs
* upon boot check for images of the book otherwise extract front page of pdfs

View File

@ -16,11 +16,4 @@ class BorrowForm(FlaskForm):
),
],
)
secret = StringField(
"Librarians secret:",
[
validators.InputRequired(),
Length(min=2, message="Fill in the secret to unlock to library."),
],
)
submit = SubmitField("Borrow")

View File

@ -1,26 +0,0 @@
"""Form object declaration."""
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, validators
from wtforms.validators import Length
class BorrowForm(FlaskForm):
"""Borrow a publication form."""
borrowed = StringField(
"Fill in your name if you're going to borrow this publication.",
[
validators.InputRequired(),
Length(
min=3, message="Just so we know who is borrowing this book."
),
],
)
secret = StringField(
"Librarians secret:",
[
validators.InputRequired(),
Length(min=2, message="Fill in the secret to unlock to library."),
],
)
submit = SubmitField("Borrow")

View File

@ -1,14 +0,0 @@
"""Forgotten password form to help user."""
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, validators
from wtforms.validators import Email, Length
class ForgotPasswordForm(FlaskForm):
"""Forgotten password csv-library form"""
email = StringField(
"Email address:",
validators=[validators.InputRequired(), Email(), Length(6, 64)],
)
submit = SubmitField("Send email")

View File

@ -1,17 +0,0 @@
"""Login form to validate user."""
from flask_wtf import FlaskForm
from wtforms import PasswordField, StringField, SubmitField, validators
from wtforms.validators import Email, Length
class LoginForm(FlaskForm):
"""Login csv-library form"""
email = StringField(
"Email address:",
validators=[validators.InputRequired(), Email(), Length(6, 64)],
)
password = PasswordField(
"Password:", validators=[validators.InputRequired()]
)
submit = SubmitField("Sign In")

View File

@ -1,37 +0,0 @@
"""Register form to make a new user."""
from flask_wtf import FlaskForm
from wtforms import PasswordField, StringField, SubmitField, validators
from wtforms.validators import Email, EqualTo, Length, ValidationError
class RegisterForm(FlaskForm):
"""Register for csv-library form"""
username = StringField(
"Username:",
validators=[validators.InputRequired(), Length(3, 150)],
)
email = StringField(
"Email address:",
validators=[
validators.InputRequired(),
Email(),
Length(6, 64),
],
)
password = PasswordField(
"New password:",
validators=[validators.InputRequired(), Length(12, 72)],
)
confirmpassword = PasswordField(
"Confirm your password:",
validators=[
validators.InputRequired(),
Length(12, 72),
EqualTo("password", message="Passwords must match !"),
],
)
submit = SubmitField("Register to the library")

View File

@ -1,22 +0,0 @@
"""Reset Password Form form to reset a users PasswordField."""
from flask_wtf import FlaskForm
from wtforms import PasswordField, SubmitField, validators
from wtforms.validators import EqualTo, Length
class ResetPasswordForm(FlaskForm):
"""ResetPassword for csv-library form"""
password = PasswordField(
"New password:",
validators=[validators.InputRequired(), Length(12, 72)],
)
confirmpassword = PasswordField(
"Confirm your password:",
validators=[
validators.InputRequired(),
Length(12, 72),
EqualTo("password", message="Passwords must match !"),
],
)
submit = SubmitField("Reset your password")

View File

@ -1,76 +0,0 @@
"""Form object declaration."""
from flask_wtf import FlaskForm
from flask_wtf.file import FileAllowed, FileField
from wtforms import (
IntegerField,
RadioField,
StringField,
SubmitField,
validators,
)
from wtforms.validators import Length, NumberRange
class PublicationForm(FlaskForm):
"""Publication upload form."""
uploadpublication = StringField(
"Title of the publication:",
[
validators.InputRequired(),
Length(
min=3, message="A publication in the library needs a title."
),
],
)
author = StringField(
"The author or editor:",
[
validators.InputRequired(),
Length(
min=3,
message=(
"If the author or editor is not known just type unkown."
),
),
],
)
year = IntegerField(
"Year:",
[validators.InputRequired(), NumberRange(min=0, max=2050)],
default=2023,
)
fields = StringField("Fields:")
type = StringField(
"Type of publication:",
[
validators.InputRequired(),
Length(
min=3,
message=(
"Here you can use terms such as zine, paperback,"
" hardcover."
),
),
],
)
publishers = StringField("Publishers:")
license = StringField("License:")
highlights = StringField("Highlights from the publication:")
comments = StringField("Comments on the publication:")
image = FileField(
"Image of the book:",
validators=[FileAllowed(["jpg", "png", "gif"], "Images only!")],
)
pdf = FileField(
"Pdf of the book:",
validators=[FileAllowed(["pdf"], "Only pdf uploads supported")],
)
secret = StringField(
"Librarians secret:",
[
validators.InputRequired(),
Length(min=2, message="Fill in the secret to unlock to library."),
],
)
submit = SubmitField("Submit")

View File

@ -90,9 +90,7 @@ def show_book(publicationID):
fullpublication = csvparser.getfullpublication(publicationID)
borrowform = BorrowForm()
if request.method == "POST":
if borrowform.validate_on_submit() and checksecret(
borrowform.secret.data
):
if borrowform.validate_on_submit():
editborrowedby(publicationID, borrowform.borrowed.data)
fullpublication["Borrowed"] = borrowform.borrowed.data
return render_template(

View File

@ -1,8 +1,12 @@
{% extends "base.html" %}
{% block main %}
<div id="nav" class="container">
<button id="leftmostbtn"><a href="/">Back to books</a></button>
<button><a href="/upload">Upload</a></button>
<div id="nav" class="menu">
<div class="dropdown">
<button><a href="/">Back to books</a></button>
</div>
<div class="dropdown">
<button><a href="/upload">Upload</a></button>
</div>
<div class="dropdown" style="visibility: hidden">
<button id="Year" class="dropbtn">Year</button>
</div>
@ -92,17 +96,7 @@
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
<fieldset class="uploadform-field">
{{ uploadform.secret.label }}
{{ uploadform.secret }}
{% for message in uploadform.secret.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
{{ uploadform.submit }}
</form>
</div>
{% endblock %}

View File

@ -18,7 +18,7 @@
</a>
</div>
{% else %}
<div class="logout">
<div class="auth">
<a href="/logout">
<svg class="feather">
<use href="{{ url_for('static', filename='icons/users-feather-sprite.svg') + '#log-out'}}" />