|
@ -25,6 +25,7 @@ fieldnames = [ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parsecsv(): |
|
|
def parsecsv(): |
|
|
|
|
|
"""Test function to inspect csv file as dict""" |
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
with libcsv: |
|
|
with libcsv: |
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
@ -32,6 +33,7 @@ def parsecsv(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getpublications(): |
|
|
def getpublications(): |
|
|
|
|
|
"""get an overview of all publications for the main page""" |
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
with libcsv: |
|
|
with libcsv: |
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
@ -54,9 +56,8 @@ def getpublications(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def hasimage(id): |
|
|
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_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): |
|
|
if os.path.exists(image_jpg): |
|
|
return True |
|
|
return True |
|
|
else: |
|
|
else: |
|
@ -64,6 +65,7 @@ def hasimage(id): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gettypes(): |
|
|
def gettypes(): |
|
|
|
|
|
"""for the dynamic menu get the unique types of publicatons""" |
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
with libcsv: |
|
|
with libcsv: |
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
@ -76,6 +78,7 @@ def gettypes(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getyears(): |
|
|
def getyears(): |
|
|
|
|
|
"""for the dynamic menu get the unique years for publicatons""" |
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
with libcsv: |
|
|
with libcsv: |
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
@ -91,6 +94,7 @@ def getyears(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getlicenses(): |
|
|
def getlicenses(): |
|
|
|
|
|
"""for the dynamic menu get the unique liscenses for publicatons""" |
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
with libcsv: |
|
|
with libcsv: |
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
@ -105,6 +109,7 @@ def getlicenses(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getfieldsofinterest(): |
|
|
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") |
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
with libcsv: |
|
|
with libcsv: |
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
@ -116,6 +121,7 @@ def getfieldsofinterest(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getpublicationfromcsvrow(row): |
|
|
def getpublicationfromcsvrow(row): |
|
|
|
|
|
"""get entire publication info from a csv row""" |
|
|
year = row["Year"] |
|
|
year = row["Year"] |
|
|
if not year: |
|
|
if not year: |
|
|
year = "Unknown" |
|
|
year = "Unknown" |
|
@ -146,6 +152,7 @@ def getpublicationfromcsvrow(row): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getfullpublication(pubid): |
|
|
def getfullpublication(pubid): |
|
|
|
|
|
"""For the single book view, most complete overview""" |
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
pubinfo = {} |
|
|
pubinfo = {} |
|
|
with libcsv: |
|
|
with libcsv: |
|
@ -159,6 +166,7 @@ def getfullpublication(pubid): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def generatenewpublicationid(): |
|
|
def generatenewpublicationid(): |
|
|
|
|
|
"""When uploading a book generate a new unique ID""" |
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") |
|
|
allidsincsv = [] |
|
|
allidsincsv = [] |
|
|
with libcsv: |
|
|
with libcsv: |
|
@ -169,6 +177,7 @@ def generatenewpublicationid(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def writepublication(uploadform): |
|
|
def writepublication(uploadform): |
|
|
|
|
|
"""When uploading a publication writes entry to the csv""" |
|
|
id = generatenewpublicationid() |
|
|
id = generatenewpublicationid() |
|
|
with open( |
|
|
with open( |
|
|
os.path.join(script_dir, "varlib.csv"), |
|
|
os.path.join(script_dir, "varlib.csv"), |
|
@ -196,12 +205,13 @@ def writepublication(uploadform): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def editborrowedby(pubid, borrower): |
|
|
def editborrowedby(pubid, borrower): |
|
|
|
|
|
"""Edits the borrowed by field for a publication entry in csv""" |
|
|
tempfile = NamedTemporaryFile('w+t', newline='', delete=False) |
|
|
tempfile = NamedTemporaryFile('w+t', newline='', delete=False) |
|
|
filename = os.path.join(script_dir, "varlib.csv") |
|
|
filename = os.path.join(script_dir, "varlib.csv") |
|
|
with open(filename, 'r', newline='') as libcsv, tempfile: |
|
|
with open(filename, 'r', newline='') as libcsv, tempfile: |
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
|
csv_as_writer = csv.DictWriter(tempfile, fieldnames=fieldnames) |
|
|
csv_as_writer = csv.DictWriter(tempfile, fieldnames=fieldnames) |
|
|
#use the reader to read where, then writer to write the new row. |
|
|
# use the reader to read where, then writer to write the new row. |
|
|
csv_as_writer.writeheader() |
|
|
csv_as_writer.writeheader() |
|
|
for row in csv_as_dict: |
|
|
for row in csv_as_dict: |
|
|
if pubid == row["Id"]: |
|
|
if pubid == row["Id"]: |
|
|