def insert_inst_into_980(curdir,uid): """collection handling for institutes""" user_groups = get_usergroups(uid) if check_field_exists(curdir,"hgf_9201_"): if read_file(curdir,"hgf_9201_") == "[]": remove_file(curdir,"hgf_9201_") # delete file in case of empty sequence! TODO: this should not happen and has to be fixed in hgfInstitutes.js if not check_field_exists(curdir,"hgf_9201_"): #make sure that we have at least one institute if str(uid) == "1": return #do not add institutes for admin user_insts = extract_user_institutes("0",user_groups) if user_insts == []: email_txt = "%s is not assigned to any institute. This email was generated from Covert_hgf_fields and function insert_inst_into_980" %get_recordid(curdir) send_email(CFG_SITE_ADMIN_EMAIL, CFG_SITE_ADMIN_EMAIL, "ERROR: no institute assigned", email_txt,header="",html_header="") return #this should not happen! jsondict = user_insts #add institute even if no institute chosen to be inserted into 980 else: jsondict = read_json(curdir,"hgf_9201_") inst_list = [] list_980 = read_json(curdir,"hgf_980__") for inst in jsondict: if {"a":inst["0"]} in list_980: continue inst_list.append({"a":inst["0"]}) if inst_list == []: return list_980 += inst_list #check if users institut in 980, if not take it from user_info if str(uid) == "1": pass # no adding of institutes into 980 for admin else: str_list_980 = [str(i) for i in list_980] #convert list with dicts into list with str(dicts), because python sets use list with strings intersection_groups = set(str_list_980) & set(user_groups) # user institute not in 980 yet intersection_vdb = set(["{'a': 'VDB'}", "{'a': 'VDBRELEVANT'}","{'a': 'VDBINPRINT'}"]) & set(str_list_980) # not vdb_relevant if intersection_groups == set([]) and intersection_vdb == set([]): # # prevent submitting vdb irrelevant stuff for another institute list_980 += extract_user_institutes("a",user_groups) write_json(curdir,"hgf_980__",list_980)
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)
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