Browse Source

black formatting

main
crunk 5 months ago
parent
commit
221aa229d4
  1. 14
      library/application/csvparser.py
  2. 0
      library/data/files/fileshere
  3. 10
      library/forms/borrowform.py
  4. 16
      library/forms/uploadform.py
  5. 17
      library/page.py
  6. 6
      library/static/css/style.css

14
library/application/csvparser.py

@ -21,12 +21,12 @@ FIELDNAMES = [
"Currently borrowed by",
]
class CsvParser:
def __init__(self, csv_file, image_dir):
self.csv_file = csv_file
self.image_dir = image_dir
def _hasimage(self, id):
"""does this Id from the csv have an image uploaded"""
image_jpg = os.path.join(self.image_dir, "image-{0}.jpg".format(id))
@ -35,7 +35,6 @@ class CsvParser:
else:
return False
def parsecsv(self):
"""Test function to inspect csv file as dict"""
libcsv = open(os.path.join(DATA_DIR, self.csv_file), "r")
@ -43,7 +42,6 @@ class CsvParser:
csv_as_dict = csv.DictReader(libcsv)
return csv_as_dict
def getpublications(self):
"""get an overview of all publications for the main page"""
libcsv = open(os.path.join(DATA_DIR, self.csv_file), "r")
@ -66,7 +64,6 @@ class CsvParser:
publications[row["Id"]] = pubinfo
return publications
def gettypes(self):
"""for the dynamic menu get the unique types of publicatons"""
libcsv = open(os.path.join(DATA_DIR, self.csv_file), "r")
@ -79,7 +76,6 @@ class CsvParser:
listoftypes.append(lowertype)
return listoftypes
def getyears(self):
"""for the dynamic menu get the unique years for publicatons"""
libcsv = open(os.path.join(DATA_DIR, self.csv_file), "r")
@ -95,7 +91,6 @@ class CsvParser:
listofyears.sort()
return listofyears
def getlicenses(self):
"""for the dynamic menu get the unique liscenses for publicatons"""
libcsv = open(os.path.join(DATA_DIR, self.csv_file), "r")
@ -110,7 +105,6 @@ class CsvParser:
listoflicenses.append(license)
return listoflicenses
def getfieldsofinterest(self):
"""for the R&R page get the fields of interest from the publicatons"""
libcsv = open(os.path.join(DATA_DIR, self.csv_file), "r")
@ -122,7 +116,6 @@ class CsvParser:
fieldsofinterest[row["Id"]] = fields
return fieldsofinterest
def getpublicationfromcsvrow(self, row):
"""get entire publication info from a csv row"""
year = row["Year"]
@ -153,7 +146,6 @@ class CsvParser:
}
return pubinfo
def getfullpublication(self, pubid):
"""For the single book view, most complete overview"""
libcsv = open(os.path.join(DATA_DIR, self.csv_file), "r")
@ -167,7 +159,6 @@ class CsvParser:
# print(pubinfo)
return pubinfo
def generatenewpublicationid(self):
"""When uploading a book generate a new unique ID"""
libcsv = open(os.path.join(DATA_DIR, self.csv_file), "r")
@ -178,7 +169,6 @@ class CsvParser:
allidsincsv.append(int(row["Id"]))
return str(max(allidsincsv) + 1)
def writepublication(self, uploadform):
"""When uploading a publication writes entry to the csv"""
id = generatenewpublicationid()
@ -206,7 +196,6 @@ class CsvParser:
print("succesfully written book to csv")
return id
def editborrowedby(self, pubid, borrower):
"""Edits the borrowed by field for a publication entry in csv"""
tempfile = NamedTemporaryFile("w+t", newline="", delete=False)
@ -225,7 +214,6 @@ class CsvParser:
shutil.move(tempfile.name, filename)
def concatenate_csv_row(self, row):
rowcontent = []
rowcontent.append(row["Publication"])

0
library/data/files/fileshere

10
library/forms/borrowform.py

@ -1,10 +1,6 @@
"""Form object declaration."""
from flask_wtf import FlaskForm
from wtforms import (
StringField,
SubmitField,
)
from wtforms import validators
from wtforms import StringField, SubmitField, validators
from wtforms.validators import Length
@ -24,9 +20,7 @@ class BorrowForm(FlaskForm):
"Librarians secret:",
[
validators.InputRequired(),
Length(
min=2, message="Fill in the secret to unlock to library."
),
Length(min=2, message="Fill in the secret to unlock to library."),
],
)
submit = SubmitField("Borrow")

16
library/forms/uploadform.py

@ -1,17 +1,9 @@
"""Form object declaration."""
from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileAllowed
from wtforms import validators
from wtforms import (
StringField,
IntegerField,
RadioField,
SubmitField,
)
from wtforms.validators import (
Length,
NumberRange,
)
from flask_wtf.file import FileAllowed, FileField
from wtforms import (IntegerField, RadioField, StringField, SubmitField,
validators)
from wtforms.validators import Length, NumberRange
class PublicationForm(FlaskForm):

17
library/page.py

@ -15,10 +15,9 @@ from requests import get
from werkzeug.utils import secure_filename
from app import create_app
from application.csvparser import CsvParser
from forms.borrowform import BorrowForm
from forms.uploadform import PublicationForm
from application.csvparser import CsvParser
from search import search
APP = create_app()
@ -29,8 +28,10 @@ csrf.init_app(APP)
@APP.route("/")
def index():
"""Main route, shows all the books and you can filter them
based on year, license, type"""
csvparser = CsvParser(APP.config["LIBRARY_FILENAME"], APP.config["IMAGE_FOLDER"])
based on year, type"""
csvparser = CsvParser(
APP.config["LIBRARY_FILENAME"], APP.config["IMAGE_FOLDER"]
)
pubtypes = csvparser.gettypes()
pubyears = csvparser.getyears()
publicenses = csvparser.getlicenses()
@ -50,7 +51,9 @@ def index():
def upload():
"""Upload route, a page to upload a book to the csv"""
uploadform = PublicationForm()
csvparser = CsvParser(APP.config["LIBRARY_FILENAME"], APP.config["IMAGE_FOLDER"])
csvparser = CsvParser(
APP.config["LIBRARY_FILENAME"], APP.config["IMAGE_FOLDER"]
)
if request.method == "POST":
if uploadform.validate_on_submit() and checksecret(
uploadform.secret.data
@ -60,7 +63,9 @@ def upload():
return redirect(str(id), code=303)
else:
return render_template("upload.html", uploadform=uploadform)
return render_template("upload.html", title=APP.config["TITLE"], uploadform=uploadform)
return render_template(
"upload.html", title=APP.config["TITLE"], uploadform=uploadform
)
@APP.route("/<publicationID>", methods=["GET", "POST"])

6
library/static/css/style.css

@ -31,7 +31,7 @@ body:after {
line-height: 1.03em;
position: relative;
color: #FFFFFF;
text-shadow: 2px 2px #8B5B7F;
text-shadow: 2px 2px #004225;
font-size: 52px;
text-align: center;
font-family: libreBaskerville;
@ -54,9 +54,9 @@ body:after {
}
@supports (-webkit-text-stroke: 1px lightpink) {
@supports (-webkit-text-stroke: 1px darkgreen) {
#library {
-webkit-text-stroke: 1px lightpink;
-webkit-text-stroke: 1px darkgreen;
}
}

Loading…
Cancel
Save