diff --git a/library/application/csvparser.py b/library/application/csvparser.py index ab767a7..dc3bdd0 100644 --- a/library/application/csvparser.py +++ b/library/application/csvparser.py @@ -10,7 +10,6 @@ FIELDNAMES = [ "Publication", "Author", "Year", - "Custodian", "Fields", "Type", "Publishers", @@ -18,7 +17,6 @@ FIELDNAMES = [ "LicenseShort", "Highlights", "Comments", - "Currently borrowed by", ] @@ -35,6 +33,30 @@ class CsvParser: else: return False + def _getpublicationfromcsvrow(self, row): + """get entire publication info from a csv row""" + year = row["Year"] + if not year: + year = "Unknown" + + license = row["License"] + if not license: + license = "No license mentioned" + + pubinfo = { + "Title": row["Publication"], + "Author": row["Author"], + "Year": year, + "Fields": row["Fields"], + "Type": row["Type"], + "Publishers": row["Publishers"], + "License": license, + "Highlights": row["Highlights"], + "Comments": row["Comments"], + "Image": self._hasimage(row["Id"]), + } + return pubinfo + def parsecsv(self): """Test function to inspect csv file as dict""" libcsv = open(os.path.join(DATA_DIR, self.csv_file), "r") @@ -116,35 +138,6 @@ class CsvParser: fieldsofinterest[row["Id"]] = fields return fieldsofinterest - def getpublicationfromcsvrow(self, row): - """get entire publication info from a csv row""" - year = row["Year"] - if not year: - year = "Unknown" - - license = row["License"] - if not license: - license = "No license mentioned" - - borrowed = row["Currently borrowed by"] - if not borrowed: - borrowed = "No one" - - pubinfo = { - "Title": row["Publication"], - "Author": row["Author"], - "Year": year, - "Custodian": row["Custodian"], - "Fields": row["Fields"], - "Type": row["Type"], - "Publishers": row["Publishers"], - "License": license, - "Highlights": row["Highlights"], - "Comments": row["Comments"], - "Borrowed": borrowed, - "Image": self._hasimage(self, row["Id"]), - } - return pubinfo def getfullpublication(self, pubid): """For the single book view, most complete overview""" @@ -154,7 +147,7 @@ class CsvParser: csv_as_dict = csv.DictReader(libcsv) for row in csv_as_dict: if pubid == row["Id"]: - pubinfo = getpublicationfromcsvrow(row) + pubinfo = self._getpublicationfromcsvrow(row) # print(pubinfo) return pubinfo @@ -182,7 +175,6 @@ class CsvParser: "Publication": uploadform.uploadpublication.data, "Author": uploadform.author.data, "Year": uploadform.year.data, - "Custodian": uploadform.custodian.data, "Fields": uploadform.fields.data, "Type": uploadform.type.data, "Publishers": uploadform.publishers.data, @@ -190,7 +182,6 @@ class CsvParser: "LicenseShort": uploadform.licenseshort.data, "Highlights": uploadform.highlights.data, "Comments": uploadform.comments.data, - "Currently borrowed by": uploadform.borrowed.data, } ) print("succesfully written book to csv") diff --git a/library/forms/uploadform.py b/library/forms/uploadform.py index 9a3e8f0..92544b9 100644 --- a/library/forms/uploadform.py +++ b/library/forms/uploadform.py @@ -33,7 +33,6 @@ class PublicationForm(FlaskForm): year = IntegerField( "Year:", [validators.InputRequired(), NumberRange(min=0, max=2050)] ) - custodian = StringField("Custodian:") fields = StringField("Fields:") type = StringField( "Type of publication:", @@ -52,7 +51,6 @@ class PublicationForm(FlaskForm): license = StringField("License:") highlights = StringField("Highlights from the publication:") comments = StringField("Comments on the publication:") - borrowed = StringField("Currently borrowed by:") image = FileField( "Image of the book:", validators=[FileAllowed(["jpg", "png", "gif"], "Images only!")], diff --git a/library/page.py b/library/page.py index 8b75be1..32b0b43 100644 --- a/library/page.py +++ b/library/page.py @@ -23,15 +23,14 @@ from search import search APP = create_app() csrf = CSRFProtect() csrf.init_app(APP) - +csvparser = CsvParser( + APP.config["LIBRARY_FILENAME"], APP.config["IMAGE_FOLDER"] +) @APP.route("/") def index(): """Main route, shows all the books and you can filter them based on year, type""" - csvparser = CsvParser( - APP.config["LIBRARY_FILENAME"], APP.config["IMAGE_FOLDER"] - ) pubtypes = csvparser.gettypes() pubyears = csvparser.getyears() publicenses = csvparser.getlicenses() @@ -51,9 +50,6 @@ 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"] - ) if request.method == "POST": if uploadform.validate_on_submit() and checksecret( uploadform.secret.data @@ -71,7 +67,7 @@ def upload(): @APP.route("/", methods=["GET", "POST"]) def show_book(publicationID): """route for a single publication, shows full info and allows borrowing""" - fullpublication = getfullpublication(publicationID) + fullpublication = csvparser.getfullpublication(publicationID) borrowform = BorrowForm() if request.method == "POST": if borrowform.validate_on_submit() and checksecret( diff --git a/library/templates/publication.html b/library/templates/publication.html index a308c0a..e5ae9c1 100644 --- a/library/templates/publication.html +++ b/library/templates/publication.html @@ -29,10 +29,6 @@ Year {{ fullpublication["Year"] }} - - Custodian - {{ fullpublication["Custodian"] }} - Fields {{ fullpublication["Fields"] }} @@ -57,33 +53,7 @@ Comments

{{ fullpublication["Comments"] }}

- - Currently borrowed by: -

{{ fullpublication["Borrowed"] }}

- - - -
- {{ borrowform.csrf_token }} -
- {{ borrowform.borrowed.label }} - {{ borrowform.borrowed }} - {% for message in borrowform.borrowed.errors %} -
{{ message }}
- {% endfor %} -
-
- {{ borrowform.secret.label }} - {{ borrowform.secret }} - {% for message in borrowform.secret.errors %} -
{{ message }}
- {% endfor %} -
- {{ borrowform.submit }} - - - - - - + + + {% endblock %} diff --git a/library/templates/upload.html b/library/templates/upload.html index bb32d74..bbf5630 100644 --- a/library/templates/upload.html +++ b/library/templates/upload.html @@ -44,11 +44,6 @@ {% endfor %} -
- {{ uploadform.custodian.label }} - {{ uploadform.custodian }} -
-
{{ uploadform.fields.label }} {{ uploadform.fields }} @@ -82,11 +77,6 @@ {{ uploadform.comments }}
-
- {{ uploadform.borrowed.label }} - {{ uploadform.borrowed }} -
-
{{ uploadform.image.label }} {{ uploadform.image }}