Browse Source

deleted custion and borrow fields

main
crunk 5 months ago
parent
commit
36090a402c
  1. 59
      library/application/csvparser.py
  2. 2
      library/forms/uploadform.py
  3. 12
      library/page.py
  4. 36
      library/templates/publication.html
  5. 10
      library/templates/upload.html

59
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")

2
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!")],

12
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("/<publicationID>", 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(

36
library/templates/publication.html

@ -29,10 +29,6 @@
<td>Year</td>
<td>{{ fullpublication["Year"] }}</td>
</tr>
<tr>
<td>Custodian</td>
<td>{{ fullpublication["Custodian"] }}</td>
</tr>
<tr>
<td>Fields</td>
<td>{{ fullpublication["Fields"] }}</td>
@ -57,33 +53,7 @@
<td>Comments</td>
<td><p>{{ fullpublication["Comments"] }}</p></td>
</tr>
<tr>
<td>Currently borrowed by:</td>
<td><p>{{ fullpublication["Borrowed"] }}</p></td>
</tr>
<tr>
<td colspan="2">
<form class="borrow" method="POST" action="/{{ publicationID }}">
{{ borrowform.csrf_token }}
<fieldset class="borrowform-field">
{{ borrowform.borrowed.label }}
{{ borrowform.borrowed }}
{% for message in borrowform.borrowed.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
<fieldset class="borrowform-field">
{{ borrowform.secret.label }}
{{ borrowform.secret }}
{% for message in borrowform.secret.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
{{ borrowform.submit }}
<form>
</td>
</tr>
</tbody>
</table>
</div>
</tbody>
</table>
</div>
{% endblock %}

10
library/templates/upload.html

@ -44,11 +44,6 @@
{% endfor %}
</fieldset>
<fieldset class="uploadform-field">
{{ uploadform.custodian.label }}
{{ uploadform.custodian }}
</fieldset>
<fieldset class="uploadform-field">
{{ uploadform.fields.label }}
{{ uploadform.fields }}
@ -82,11 +77,6 @@
{{ uploadform.comments }}
</fieldset>
<fieldset class="uploadform-field">
{{ uploadform.borrowed.label }}
{{ uploadform.borrowed }}
</fieldset>
<fieldset class="fileupload-field">
{{ uploadform.image.label }}
{{ uploadform.image }}

Loading…
Cancel
Save