Browse Source

black formatting

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

0
library/data/files/fileshere

10
library/forms/borrowform.py

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

16
library/forms/uploadform.py

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

17
library/page.py

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

6
library/static/css/style.css

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

Loading…
Cancel
Save