|
|
@ -25,6 +25,7 @@ fieldnames = [ |
|
|
|
|
|
|
|
|
|
|
|
def parsecsv(): |
|
|
|
"""Test function to inspect csv file as dict""" |
|
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
|
with libcsv: |
|
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
|
@ -32,6 +33,7 @@ def parsecsv(): |
|
|
|
|
|
|
|
|
|
|
|
def getpublications(): |
|
|
|
"""get an overview of all publications for the main page""" |
|
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
|
with libcsv: |
|
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
|
@ -54,9 +56,8 @@ def getpublications(): |
|
|
|
|
|
|
|
|
|
|
|
def hasimage(id): |
|
|
|
"""does this Id from the csv have an image uploaded""" |
|
|
|
image_jpg = os.path.join(image_dir, "image-{0}.jpg".format(id)) |
|
|
|
image_png = os.path.join(image_dir, "image-{0}.png".format(id)) |
|
|
|
image_gif = os.path.join(image_dir, "image-{0}.gif".format(id)) |
|
|
|
if os.path.exists(image_jpg): |
|
|
|
return True |
|
|
|
else: |
|
|
@ -64,6 +65,7 @@ def hasimage(id): |
|
|
|
|
|
|
|
|
|
|
|
def gettypes(): |
|
|
|
"""for the dynamic menu get the unique types of publicatons""" |
|
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
|
with libcsv: |
|
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
|
@ -76,6 +78,7 @@ def gettypes(): |
|
|
|
|
|
|
|
|
|
|
|
def getyears(): |
|
|
|
"""for the dynamic menu get the unique years for publicatons""" |
|
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
|
with libcsv: |
|
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
|
@ -91,6 +94,7 @@ def getyears(): |
|
|
|
|
|
|
|
|
|
|
|
def getlicenses(): |
|
|
|
"""for the dynamic menu get the unique liscenses for publicatons""" |
|
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
|
with libcsv: |
|
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
|
@ -105,6 +109,7 @@ def getlicenses(): |
|
|
|
|
|
|
|
|
|
|
|
def getfieldsofinterest(): |
|
|
|
"""for the R&R page get the fields of interest from the publicatons""" |
|
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
|
with libcsv: |
|
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
|
@ -116,6 +121,7 @@ def getfieldsofinterest(): |
|
|
|
|
|
|
|
|
|
|
|
def getpublicationfromcsvrow(row): |
|
|
|
"""get entire publication info from a csv row""" |
|
|
|
year = row["Year"] |
|
|
|
if not year: |
|
|
|
year = "Unknown" |
|
|
@ -146,6 +152,7 @@ def getpublicationfromcsvrow(row): |
|
|
|
|
|
|
|
|
|
|
|
def getfullpublication(pubid): |
|
|
|
"""For the single book view, most complete overview""" |
|
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
|
pubinfo = {} |
|
|
|
with libcsv: |
|
|
@ -159,6 +166,7 @@ def getfullpublication(pubid): |
|
|
|
|
|
|
|
|
|
|
|
def generatenewpublicationid(): |
|
|
|
"""When uploading a book generate a new unique ID""" |
|
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
|
allidsincsv = [] |
|
|
|
with libcsv: |
|
|
@ -169,6 +177,7 @@ def generatenewpublicationid(): |
|
|
|
|
|
|
|
|
|
|
|
def writepublication(uploadform): |
|
|
|
"""When uploading a publication writes entry to the csv""" |
|
|
|
id = generatenewpublicationid() |
|
|
|
with open( |
|
|
|
os.path.join(script_dir, "varlib.csv"), |
|
|
@ -196,6 +205,7 @@ def writepublication(uploadform): |
|
|
|
|
|
|
|
|
|
|
|
def editborrowedby(pubid, borrower): |
|
|
|
"""Edits the borrowed by field for a publication entry in csv""" |
|
|
|
tempfile = NamedTemporaryFile('w+t', newline='', delete=False) |
|
|
|
filename = os.path.join(script_dir, "varlib.csv") |
|
|
|
with open(filename, 'r', newline='') as libcsv, tempfile: |
|
|
|