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)
def add_FFT(curdir): """ !!!move_files_to_storage, move files to done have to be deleted from websubmit function!!! add FFT tag into record if this function is used: the functions stamp_uploaded_files should not be used in the websubmit anymore """ if not check_field_exists(curdir,"hgf_file"): return None # no file submitted fulltext_filename = read_file(curdir,"hgf_file") fulltext_path = os.path.join(curdir,"files","hgf_file",fulltext_filename) if not os.path.exists(fulltext_path): return None # no file named in hgf_file in files directory. something is wrong.. if os.path.getsize(fulltext_path) == 0: #check file size #send email #first get the url record link if not check_field_exists(curdir,"SN"): return None # no recid-->something is wrong.. recid = get_recordid(curdir) rec_url = CFG_SITE_URL + "/record/" + recid #create email email_txt = 'Dear Sir or Madam, \n\nAn empty file has been submitted for the record: %s\n\nProbably it was caused, because the file has been deleted from its directory before final submission into %s !!!\nIt is possible, that the record itself is not available, when this email was sent, but it should be processed within minutes. Once this is finished you may add the fulltext by accessing %s and using "modify record" link \n\n' %(rec_url,CFG_SITE_NAME,rec_url) email_subject = 'File submission incomplete!!!' #email check if check_field_exists(curdir,"SuE"): email_to = read_file(curdir,"SuE") # get email from submitter else: email_to = CFG_SITE_ADMIN_EMAIL # in case somehow no email of submitter exists, send email to admin send_email(CFG_SITE_ADMIN_EMAIL, email_to, email_subject, email_txt,copy_to_admin=CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN,header="",html_header="") return None #cancel file submission (the submitter has already been informed via email), the original submission will be processed. inst_dict_list = read_json(curdir,"hgf_9201_") #read in institutes inst_list = [] restriction = "firerole: allow groups 'STAFF'" # staff is always # add the institutes id and append the external auth info as this # builds the actual group name we need to allow here. for inst in inst_dict_list: restriction += ",'" + inst["0"] + ' ['+CFG_EXTERNAL_AUTH_DEFAULT+']' + "'" # TODO: multiple authentifications filename = read_file(curdir,"hgf_file") file_path = os.path.join(curdir,"files","hgf_file",filename) if not check_field_exists(curdir,"rn"): return rn = read_file(curdir,"rn") #fill subfields for FFT fft_dict = {} fft_dict["a"] = file_path fft_dict["n"] = rn fft_dict["r"] = restriction write_json(curdir,"hgf_FFT__",fft_dict)
def Create_hgf_record_json(parameters,curdir, form, user_info=None): """run over all hgf_fields and create hgf_record in json-format""" # sort the files by name. This results in getting all structured # fields FIRST and then (in case they exist) individual subfields. hgf_files = sorted(get_hgf_files(curdir)) hgf_rec = Create_json_hgf_record(curdir) for fieldname in hgf_files: flag, ident = check_hgf_field(fieldname) if not flag: continue # no standard marc-field (e.g. hgf_vdb) if ident == "json": hgf_rec.add_jsondict(fieldname) #add json structure elif ident == "asci": hgf_rec.add_field(fieldname) #add non json structure elif ident == "master": backup_file(curdir,fieldname) hgf_rec.process_master(fieldname) #process master record else: continue recid = get_recordid(curdir) hgf_rec.transform_values_into_list() #convert values into lists for Make_HGF_Record hgf_rec.add_key_value("001",recid) #add recid to json-dict hgf_rec.write_json()
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)