|
|
@ -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"]) |
|
|
|