Browse Source

deleted custion and borrow fields

main
crunk 10 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", "Publication",
"Author", "Author",
"Year", "Year",
"Custodian",
"Fields", "Fields",
"Type", "Type",
"Publishers", "Publishers",
@ -18,7 +17,6 @@ FIELDNAMES = [
"LicenseShort", "LicenseShort",
"Highlights", "Highlights",
"Comments", "Comments",
"Currently borrowed by",
] ]
@ -35,6 +33,30 @@ class CsvParser:
else: else:
return False 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): 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")
@ -116,35 +138,6 @@ class CsvParser:
fieldsofinterest[row["Id"]] = fields fieldsofinterest[row["Id"]] = fields
return fieldsofinterest 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): def getfullpublication(self, pubid):
"""For the single book view, most complete overview""" """For the single book view, most complete overview"""
@ -154,7 +147,7 @@ class CsvParser:
csv_as_dict = csv.DictReader(libcsv) csv_as_dict = csv.DictReader(libcsv)
for row in csv_as_dict: for row in csv_as_dict:
if pubid == row["Id"]: if pubid == row["Id"]:
pubinfo = getpublicationfromcsvrow(row) pubinfo = self._getpublicationfromcsvrow(row)
# print(pubinfo) # print(pubinfo)
return pubinfo return pubinfo
@ -182,7 +175,6 @@ class CsvParser:
"Publication": uploadform.uploadpublication.data, "Publication": uploadform.uploadpublication.data,
"Author": uploadform.author.data, "Author": uploadform.author.data,
"Year": uploadform.year.data, "Year": uploadform.year.data,
"Custodian": uploadform.custodian.data,
"Fields": uploadform.fields.data, "Fields": uploadform.fields.data,
"Type": uploadform.type.data, "Type": uploadform.type.data,
"Publishers": uploadform.publishers.data, "Publishers": uploadform.publishers.data,
@ -190,7 +182,6 @@ class CsvParser:
"LicenseShort": uploadform.licenseshort.data, "LicenseShort": uploadform.licenseshort.data,
"Highlights": uploadform.highlights.data, "Highlights": uploadform.highlights.data,
"Comments": uploadform.comments.data, "Comments": uploadform.comments.data,
"Currently borrowed by": uploadform.borrowed.data,
} }
) )
print("succesfully written book to csv") print("succesfully written book to csv")

2
library/forms/uploadform.py

@ -33,7 +33,6 @@ class PublicationForm(FlaskForm):
year = IntegerField( year = IntegerField(
"Year:", [validators.InputRequired(), NumberRange(min=0, max=2050)] "Year:", [validators.InputRequired(), NumberRange(min=0, max=2050)]
) )
custodian = StringField("Custodian:")
fields = StringField("Fields:") fields = StringField("Fields:")
type = StringField( type = StringField(
"Type of publication:", "Type of publication:",
@ -52,7 +51,6 @@ class PublicationForm(FlaskForm):
license = StringField("License:") license = StringField("License:")
highlights = StringField("Highlights from the publication:") highlights = StringField("Highlights from the publication:")
comments = StringField("Comments on the publication:") comments = StringField("Comments on the publication:")
borrowed = StringField("Currently borrowed by:")
image = FileField( image = FileField(
"Image of the book:", "Image of the book:",
validators=[FileAllowed(["jpg", "png", "gif"], "Images only!")], validators=[FileAllowed(["jpg", "png", "gif"], "Images only!")],

12
library/page.py

@ -23,15 +23,14 @@ from search import search
APP = create_app() APP = create_app()
csrf = CSRFProtect() csrf = CSRFProtect()
csrf.init_app(APP) csrf.init_app(APP)
csvparser = CsvParser(
APP.config["LIBRARY_FILENAME"], APP.config["IMAGE_FOLDER"]
)
@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, type""" based on year, type"""
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()
@ -51,9 +50,6 @@ 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"]
)
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
@ -71,7 +67,7 @@ def upload():
@APP.route("/<publicationID>", methods=["GET", "POST"]) @APP.route("/<publicationID>", methods=["GET", "POST"])
def show_book(publicationID): def show_book(publicationID):
"""route for a single publication, shows full info and allows borrowing""" """route for a single publication, shows full info and allows borrowing"""
fullpublication = getfullpublication(publicationID) fullpublication = csvparser.getfullpublication(publicationID)
borrowform = BorrowForm() borrowform = BorrowForm()
if request.method == "POST": if request.method == "POST":
if borrowform.validate_on_submit() and checksecret( if borrowform.validate_on_submit() and checksecret(

36
library/templates/publication.html

@ -29,10 +29,6 @@
<td>Year</td> <td>Year</td>
<td>{{ fullpublication["Year"] }}</td> <td>{{ fullpublication["Year"] }}</td>
</tr> </tr>
<tr>
<td>Custodian</td>
<td>{{ fullpublication["Custodian"] }}</td>
</tr>
<tr> <tr>
<td>Fields</td> <td>Fields</td>
<td>{{ fullpublication["Fields"] }}</td> <td>{{ fullpublication["Fields"] }}</td>
@ -57,33 +53,7 @@
<td>Comments</td> <td>Comments</td>
<td><p>{{ fullpublication["Comments"] }}</p></td> <td><p>{{ fullpublication["Comments"] }}</p></td>
</tr> </tr>
<tr> </tbody>
<td>Currently borrowed by:</td> </table>
<td><p>{{ fullpublication["Borrowed"] }}</p></td> </div>
</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>
{% endblock %} {% endblock %}

10
library/templates/upload.html

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

Loading…
Cancel
Save