Example #1
0
def insert_webyear(curdir):
	"""set web year (Wissenschaftlicher Ergebnis Berichtsjahr)
	This function has to be called after insert_date function"""
	try:
		recid = int(get_recordid(curdir))
	except:
		return #when do we get this exception???
	orig_record_980 = get_fieldvalues(recid,'980__a') #create_hgf_collection was alreay active at this step and changed 980-field, so we have to get the original collections of the record from database
	if "VDB" in orig_record_980: return # do not change web_year after it was released by library (collection tag VDB)
	web_year = None
	current_year = str(datetime.datetime.now().year)
	if check_field_exists(curdir,"hgf_260__c"): # publication_year exists
		pub_year = read_file(curdir,"hgf_260__c")
		if pub_year == current_year: web_year = pub_year # publication year is current system year --> set web-year
	else:
		if check_field_exists(curdir,"hgf_245__f"): # check thesis end_date
			date = read_file(curdir,"hgf_245__f") #insert_date function has already been executed
			sdate,edate = date.split(" - ")
			if ((current_year in edate) or (current_year in sdate)): web_year = current_year # ending year of thesis is current system year --> set web-year
		if check_field_exists(curdir,"hgf_1112_d"): # check conf end_date
			date = read_file(curdir,"hgf_1112_d")
			sdate,edate = date.split(" - ")
			if ((current_year in edate) or (current_year in sdate)): web_year = current_year # ending year of conference is current system year --> set web-year

	if web_year: #write web_year
		write_file(curdir,"hgf_9141_y",web_year)
Example #2
0
def prefill_vdb_relevant(curdir):
	if not check_field_exists(curdir,"hgf_980__"): return
	text = read_file(curdir,"hgf_980__")
	if (('VDBRELEVANT' in text) or ('"VDB"' in text) or ('VDBINPRINT' in text)): value = "yes"
	else: value = "no"
	write_file(curdir,"hgf_vdb",value)
	if 'MASSMEDIA' in text: #prefill Massmedia 
		write_file(curdir,"hgf_massmedia","yes")
Example #3
0
def handle_0247(curdir):
	""" Handle persistend identifiers in 0247_. This implies to set $2
	to source and $a to value. only in case of user input

	Note: if we get new PIDs that should be handled we need to adopt
	this function!"""

	if check_field_exists(curdir,"hgf_0247_"):
		listdict_ = read_json(curdir,"hgf_0247_")

	else: listdict_ = []

	if check_field_exists(curdir,"hgf_0247_a2pat"): # Patent
		text = read_file(curdir,"hgf_0247_a2pat")
		listdict_.append({"2":"Patent","a":text})
	if check_field_exists(curdir,"hgf_0247_a2urn"): # URN
		text = read_file(curdir,"hgf_0247_a2urn")
		listdict_.append({"2":"URN","a":text})
	if check_field_exists(curdir,"hgf_773__a"):     # store DOI in both 773__ and in 0247, this is an input field
		text = read_file(curdir,"hgf_773__a")
		listdict_.append({"2":"doi","a":text})
	if (not check_field_exists(curdir,"hgf_773__a") and check_field_exists(curdir,"hgf_773__")): # doi can be stored in 773__ as json array
		dict_773 = read_json(curdir,"hgf_773__")
		for ent in dict_773: #more then 1 DOI
			if not "a" in ent.keys(): continue
			listdict_.append({"2":"doi","a":ent["a"]})

	if listdict_ == []: return

	new_listdict = []
	for dict in listdict_:
		if dict in new_listdict: continue # remove double entries
		new_listdict.append(dict)
	write_json(curdir,"hgf_0247_",new_listdict)

	#Insert DOI into 773__a only in case no 773__a or 773 json array exist
	if check_field_exists(curdir,"773__a"):     return #we have a 773__a

	if check_field_exists(curdir,"773__"):
		listdict_773 = read_json(curdir,"773__")
		for ent in listdict_773:
			if ent.has_key("a"): return # we have a 773__a

	for ent in new_listdict:
		if not ent.has_key("2"):     continue
		if not (ent["2"] == "doi"):  continue
		# map doi into 773__a

		# write DOI in 773__a if we do not yet have one.
		# in case of multiple DOIs the first one will win <--> we cannot
		# write the 773__ because we do not know if other 773__* fields
		# has been inputted and to which belongs the DOI. TODO!
		write_file(curdir,"hgf_773__a",ent["a"])

	return
Example #4
0
def handle_date(curdir,fielddate,sdate,edate):
	"""preprocessing date into 245$f
	fielddate can be hgf_245__f, hgf_1112_d
	sdate: hgf_245__fs or hgf_1112_dcs
	edate: hgf_245__fe or hgf_1112_dce
	"""
	if not check_field_exists(curdir,fielddate): return
	date = read_file(curdir,fielddate)
	try: dat1,dat2 = date.split(" - ")
	except: return
	if dat1 != "": write_file(curdir,sdate,dat1)
	if dat2 != "": write_file(curdir,edate,dat2)
Example #5
0
def prefill_gender(curdir):
	"""prefill gender. normally the radio,checkboxes are prefilled by the Create_modify_interface_hgf, but that field is part of hgf_1001_ technical field, which is by default not a checkbox or radio botton"""
	if not check_field_exists(curdir,"hgf_1001_"): return # no author
	jsonlist = read_json(curdir,"hgf_1001_")
	
	for jsondict in jsonlist: # there can be only one first author --> len(jsonlist ==1)
		if not jsondict.has_key("g"): continue
		write_file(curdir,"hgf_1001_g",jsondict["g"])
		
		#delete gender information from technical field and store info in 1001_g
		del jsondict["g"]
		write_json(curdir,"hgf_1001_",[jsondict])
Example #6
0
def prefill_245(curdir):
	"""prefill 245__a and 245__f as simple input fields. only 245__h (publication form) into 245__"""
	jsonlist = read_json(curdir,"hgf_245__")
	pubforms = []
	for jsondict in jsonlist:
		if jsondict.has_key("h"): 
			pubformnames = jsondict["h"].split(",") #split multiple pubforms
			for i,pubform in enumerate(pubformnames): pubforms.append({"h":pubform,"x":i}) 
		for key in jsondict.keys(): #we have some Input fields
			filename = "hgf_245__" + key
			# encode jsondict[key] to utf-8 to handle utf-chars.
			# TODO Tomek, why does it seem that we need this only here and
			# not for any other field?
			write_file(curdir,filename,jsondict[key].encode('utf-8'))
	write_json(curdir,"hgf_245__",pubforms)
Example #7
0
def handle_url(curdir):
	if check_field_exists(curdir,"hgf_8564_"): 
		remove_file(curdir,"hgf_8564_u")
		
		jsondict_list = read_json(curdir,"hgf_8564_")
		#only one URL can be submitted/modified. bibedit urls die ;)
		for i in jsondict_list:
			if not i.has_key("u"): continue # no subfield u detected
			if CFG_SITE_URL in i["u"]: continue # skip internal file
			write_file(curdir,"hgf_8564_u",i["u"])
			remove_file(curdir,"hgf_8564_")
			return # write only one URL
	if check_field_exists(curdir,"hgf_8564_u"):
		text = read_file(curdir,"hgf_8564_u")
		if CFG_SITE_URL in text: remove_file(curdir,"hgf_8564_u") #skip internal file
def set_timestamp(curdir,uid):
	"""manage timestamp"""
	timestamp = datetime.datetime.now().isoformat()
	user = get_user(uid)
	if not check_field_exists(curdir,"hgf_961__x"): write_file(curdir,"hgf_961__x",str(timestamp)) # only in submit
	if user == "EDITORS": write_file(curdir,"hgf_961__i",str(timestamp)) # only if Editors finish & release
	if user == "STAFF": write_file(curdir,"hgf_961__z",str(timestamp)) # only if stuff finish & release
	write_file(curdir,"hgf_961__c",str(timestamp)) # in submit and modify
	os.system("cp %s/SuE %s/hgf_961__a" %(curdir,curdir)) #only in submit
Example #9
0
def insert_date(curdir,fielddate,sdate,edate):
	"""preprocessing date into 245$f
	fielddate can be hgf_245__f, hgf_1112_d
	sdate: hgf_245__fs or hgf_1112_dcs
	edate: hgf_245__fe or hgf_1112_dce
	"""
	if check_field_exists(curdir,sdate):
		hgf_sdate = read_file(curdir,sdate)
	else: hgf_sdate = ""
	if check_field_exists(curdir,edate):
		hgf_edate = read_file(curdir,edate)
	else: hgf_edate = ""
	if (hgf_sdate == "" and hgf_edate == "" ): return ""
	else: datestring = hgf_sdate + " - " + hgf_edate
	write_file(curdir,fielddate,datestring)
	remove_file(curdir, sdate)
	remove_file(curdir, edate)
Example #10
0
def prefill_0247(curdir):
	"""prefill URN, Patent"""
	if check_field_exists(curdir,"hgf_0247_"): #json structure
		jsonlist = read_json(curdir,"hgf_0247_")
		for jsondict in jsonlist:
			if not jsondict.has_key("2"): continue
			if jsondict["2"] == "Patent":
				write_file(curdir,"hgf_0247_a2pat",jsondict["a"])
			elif jsondict["2"] == "URN":	
				write_file(curdir,"hgf_0247_a2urn",jsondict["a"])
	
	if check_field_exists(curdir,"hgf_0247_2"):
		if check_field_exists(curdir,"hgf_0247_a"):
			subfield_2 = read_file(curdir,"hgf_0247_2")
			subfield_a = read_file(curdir,"hgf_0247_a")
			if subfield_2 == "Patent":
				write_file(curdir,"hgf_0247_a2pat",subfield_a)
			elif subfield_2 == "URN":
				write_file(curdir,"hgf_0247_a2urn",subfield_a)	
Example #11
0
def insert_thesis_note(curdir):
	"""insert 502__a --> thesis note:
	syntax: 'University, Doctype, Granted Year'
	insert 502__b (if possible)
	insert 655_7
	"""
	doctype = read_file(curdir,"doctype")
	jsondict = get_pubtype_info(doctype)
	if "I502__b" in jsondict.keys(): write_file(curdir,"hgf_502__b",jsondict["I502__b"])

	all_fields = True
	if check_field_exists(curdir,"hgf_502__c") and (check_field_exists(curdir,"hgf_260__c") or check_field_exists(curdir,"hgf_502__d")): pass
	else: all_fields = None

	if not "I502__a" in jsondict.keys(): all_fields = None
	if not all_fields: return #if some field is missing, do not create thesis_note
	norm_doctype = jsondict["I502__a"]
	if check_field_exists(curdir,"hgf_502__d"):
		thesis_note = read_file(curdir,"hgf_502__c") + ", " + norm_doctype + ", " + read_file(curdir,"hgf_502__d") # uese granted year
	else: thesis_note = read_file(curdir,"hgf_502__c") + ", " + norm_doctype + ", " + read_file(curdir,"hgf_260__c") #use publication year

	if "I650_7a" in jsondict.keys(): write_file(curdir,"hgf_650_7a",jsondict["I650_7a"].encode('utf-8'))
	if "I650_72" in jsondict.keys(): write_file(curdir,"hgf_650_72",jsondict["I650_72"])
	if "I650_70" in jsondict.keys(): write_file(curdir,"hgf_650_70",jsondict["I650_70"])

	write_file(curdir,"hgf_650_7x",norm_doctype)
	write_file(curdir,"hgf_502__a",thesis_note)
Example #12
0
def insert_reportnr(curdir):
	"""preprocessing of reportnumber"""
	rn = read_file(curdir,"rn")
	write_file(curdir,"hgf_037__a",rn)
Example #13
0
def insert_email(curdir):
	"""read SuE (emails of submitter) file and store it in 8560_f"""
	if not check_field_exists(curdir,"SuE"): return
	email = read_file(curdir,"SuE")
	write_file(curdir,"hgf_8560_f",email)