diff --git a/hal/forms.py b/hal/forms.py index 3c2a54c4005cbd35f14753b4777b28fe246dd664..364d7879557ccb3758a16960f8c1fdea81ed939d 100644 --- a/hal/forms.py +++ b/hal/forms.py @@ -20,7 +20,12 @@ CHOICES_DEPOT= ( ) CHOICES_SOURCE_BIBTEX = ( -('DBLP','DBLP'), +('DBLP','DBLP'), +('ENDNOTE','ENDNOTE'), +) + +CHOICES_SOURCE_CSV = ( +('KN','KeyNote'), ) CHOICES_SOURCE_TEXT = ( @@ -68,6 +73,28 @@ class BibtexXmlForm(forms.Form): bibtex_file = forms.CharField(required=True, label="contenu bibtex", widget=forms.Textarea(attrs={'rows':20, 'cols':90}),) +class Csv2halForm(forms.Form): + form_author = forms.CharField(required=True, max_length=40, label="Forme auteur (*)") + name_user = forms.CharField(required=True, max_length=40, label="Nom chercheur (*)") + firstname_user = forms.CharField(required=True, max_length=40, label="Prénom chercheur (*)") + labo_auth_final = forms.CharField(required=True, max_length=40, label="N° de structure (*) (Ex: 490706)") + id_hal_user = forms.CharField(required=True, max_length=40, label="IdHal chercheur (*)") + login_user = forms.CharField(required=True, max_length=40, label="Login HAL chercheur (*)") + + choice_source = forms.ChoiceField(widget=forms.RadioSelect, choices=CHOICES_SOURCE_CSV, label="Choix de la source", initial='KN' ) + + login_depot = forms.CharField(required=True, max_length=40, label="Login HAL référent (*)") + passwd_depot = forms.CharField(required=True, max_length=40, label=("Password HAL référent (*)"), widget=forms.PasswordInput()) + choice_depot = forms.ChoiceField(widget=forms.RadioSelect, choices=CHOICES_DEPOT, label="Choix du dépôt", initial='NODEPOT' ) + + domain1 = forms.CharField(required=True, max_length=20, label="Domaine 1 (*)") + domain2 = forms.CharField(required=False, max_length=20, label="Domaine 2") + domain3 = forms.CharField(required=False, max_length=20, label="Domaine 3") + domain4 = forms.CharField(required=False, max_length=20, label="Domaine 4") + domain5 = forms.CharField(required=False, max_length=20, label="Domaine 5") + + csv_file = forms.CharField(required=True, label="contenu CSV", widget=forms.Textarea(attrs={'rows':20, 'cols':90}),) + class Text2halForm(forms.Form): form_author = forms.CharField(required=True, max_length=40, label="Forme auteur (*)") diff --git a/hal/scripts_bibtex.py b/hal/scripts_bibtex.py index 8d2eb287f2e7e8a786b05e76b3897aebf7d7ea28..9524fb4c563d905a7ce1cfda119cb173034b9d86 100644 --- a/hal/scripts_bibtex.py +++ b/hal/scripts_bibtex.py @@ -176,7 +176,7 @@ def script_bibtex_2_hal (bibtex_file, bib_name_user, name_user, firstname_user, #print ("TEST name_user "+name_user+" - auth "+auth) if name_user in auth : - print ("Script_DBLP Match form_author DBLP") + print ("Script_bibtex Match form_author DBLP") auth = firstname_user+" "+name_user lab_struct = labo_auth_final if auth[-4:] == " and" : @@ -191,6 +191,33 @@ def script_bibtex_2_hal (bibtex_file, bib_name_user, name_user, firstname_user, except KeyError : cnt_error_auth+=1 + if source_bibtex == "ENDNOTE" : + try : + print ("AUTHOR:"+entry['author']) + authors = entry['author'] + + list_authors_mix = authors.split("and") + for auth in list_authors_mix : + lab_struct = "" + print ("TEST bib_name_user "+bib_name_user+" - auth "+auth) + + if bib_name_user in auth : + print ("Script_bibtex Match form_author EndNote") + auth = name_user + ", " + firstname_user + lab_struct = labo_auth_final + + auth_full = auth.split(",") + nom = auth_full[0] + nom = nom.encode('utf-8') + nom = nom.strip() + prenom = auth_full[-1] + prenom = prenom.encode('utf-8') + prenom = prenom.strip() + + #print ("Script_dblp "+"author "+auth.encode('utf-8')+ " - prenom "+ prenom.encode('utf-8')+ " - nom "+nom.encode('utf-8')+ str(type(auth.encode('utf-8')))) + listauthors.append((nom,prenom,lab_struct)) + except KeyError : + cnt_error_auth+=1 # if source_bibtex == "..." : # Get journal for ARTICLES diff --git a/hal/scripts_csv.py b/hal/scripts_csv.py new file mode 100644 index 0000000000000000000000000000000000000000..acd61b243afd277d7006c78381216f26de3662cd --- /dev/null +++ b/hal/scripts_csv.py @@ -0,0 +1,430 @@ +#!/usr/bin/python +#-*- coding: utf-8 -*- + +from __future__ import unicode_literals +import requests +import csv + +# lib XML +from lxml import etree + +# lib csv + + + +from create_xml2hal import createXml_sendHal, create_single_xml + +################# +## VARIABLES +################# + + +# Fichier CSV en sortie +file_publis_csv = "all_csv.csv" + + +######################################################################################################################################## +######################################################################################################################################## +########## SCRIPT PRINCIPAL +######################################################################################################################################## +######################################################################################################################################## + + +def script_csv_2_hal (csv_file, bib_name_user, name_user, firstname_user, labo_auth_final, id_hal_user, login_user, listdomains, login_depot, passwd_depot, bool_depot_preprod, bool_depot_prod, single, source_csv): + ''' + take bibtex file and some values in entry and parse the bibtex to get info upon publications + + if the bool 'single' == False -> bibtex file has many publications, call createXml_sendHal (create XML and deposit) return a lis of results + if the bool 'single' == True -> bibtex file has one publication, call create_single_xml (post single XML no deposit) return the XML in string + ''' + print ("script_csv_2_hal bool_depot_prod ",bool_depot_prod) + resultat = "" + problemes_url = "" + problemes_doublon = "" + problemes_depot = "" + depots = "" + reponse_single_xml = "" + + ################################### + ###### COMPTEURS + ################################### + + cnt_article = 0 + cnt_inproceeding = 0 + cnt_proceeding = 0 + cnt_incollection = 0 + cnt_book = 0 + cnt_total = 0 + cnt_phdthesis = 0 + + # errors bibtex + cnt_error_auth = 0 + cnt_error_title = 0 + cnt_error_jrn = 0 + cnt_error_vol = 0 + cnt_error_numb = 0 + cnt_error_pages = 0 + cnt_error_year_art = 0 + cnt_error_doi = 0 + cnt_error_booktitle = 0 + cnt_error_pages = 0 + cnt_error_year_inp = 0 + cnt_error_crossref = 0 + cnt_error_publisher = 0 + cnt_error_editor = 0 + cnt_error_idcrossref = 0 + cnt_error_publisher_p = 0 + cnt_error_editor_p = 0 + + list_pub_csv = [] + + # une participation a une conf (inproceeding) peut avoir une crossref reliee a une proceeding qui est une conf, celle ci + # se trouve en fin du doc bibtex donc -> + # on cherche crossref dans inproceeding, si on le trouve aller le chercher en bas, sinon chercher editor et publier directement dans inproceeding + # car certains chercheurs peuvent creer leur bibtex comme ceci + + #bibtex_file = bibtex_file.encode("utf-8") + print (csv_file) + + parser = BibTexParser() + parser.ignore_nonstandard_types = False + parser.homogenize_fields = False + parser.common_strings = False + parser.customization = convert_to_unicode + bib_database = bibtexparser.loads(bibtex_file, parser = parser) + ''' + parser = BibTexParser() + parser.customization = convert_to_unicode + bib_database = bibtexparser.load(bibtex_file, parser=parser) + ''' + + # list_acronym_country -> nom du pays en anglais majuscule , acronyme du pays + list_acronym_country = [] + with open('hal/countries.csv', 'rb') as csvfile: + delim = str(':') + quotech = str('|') + list_countries = csv.reader(csvfile, delimiter=delim, quotechar=quotech) + for row in list_countries: + list_acronym_country.append((row[1],row[0])) + + + for entry in bib_database.entries : + # initialize entries + type_publi ="" + numero = "" + language = "en" + title = "" + conf="" + nb_pages="" + volume = "" + town="" + country="" + country_acr="XX" + year = 0 + doi_value = "" + publisher_book = "" + editor_book = "" + + # Recup type publi, numero, language + if entry['ENTRYTYPE']=='article' : + cnt_article +=1 + type_publi = "ART" + numero = "RI"+str(cnt_article) + language = "en" + + if entry['ENTRYTYPE']=='inproceedings' : + cnt_inproceeding +=1 + type_publi = "COMM" + numero = "CI"+str(cnt_inproceeding) + language = "en" + + if entry['ENTRYTYPE']=='book' : + cnt_book +=1 + type_publi = "OUV" + numero = "O"+str(cnt_book) + language = "en" + + # Recup title and format + title = entry['title'] + title = title.replace("\n"," ") + title = title.replace("\\emph","") + + # get authors according to source_bibtex + listauthors = [] + if source_bibtex == "DBLP" : + try : + #print ("AUTHOR:"+entry['author']) + authors = entry['author'] + list_authors_mix = authors.split("\n") + for auth in list_authors_mix : + lab_struct = "" + #print ("TEST name_user "+name_user+" - auth "+auth) + + if name_user in auth : + print ("Script_DBLP Match form_author DBLP") + auth = firstname_user+" "+name_user + lab_struct = labo_auth_final + if auth[-4:] == " and" : + auth = auth[:-4] + auth_full = auth.split(" ") + prenom = auth_full[0] + prenom = prenom.encode('utf-8') + nom = auth_full[-1] + nom = nom.encode('utf-8') + #print ("Script_dblp "+"author "+auth.encode('utf-8')+ " - prenom "+ prenom.encode('utf-8')+ " - nom "+nom.encode('utf-8')+ str(type(auth.encode('utf-8')))) + listauthors.append((nom,prenom,lab_struct)) + except KeyError : + cnt_error_auth+=1 + + # if source_bibtex == "..." : + + # Get journal for ARTICLES + if type_publi == "ART" : + try : + conf = entry['journal'] + conf = conf.replace("\n"," ") + except KeyError : + cnt_error_jrn+=1 + + # Get conf for COMM, split entry with ',' , first occurence is conf name + # then search country from CSV in other occurences and if found, get previous occurence to get town (except USA previuous previous occurence) + if type_publi == "COMM" : + try : + booktitle = entry['booktitle'] + conf_all = booktitle.split(",") + conf = conf_all[0] + conf = conf.replace("\n"," ") + conf = conf.replace("\\(^\\mboxth\\)","th") + conf = conf.replace("\\(^\\mboxe\\)","e") + prev_conf_elmt = "" + prev_prev_conf_elmt = "" + for conf_elmt in conf_all : + conf_elmt = conf_elmt.strip() + for csv_country in list_acronym_country : + if conf_elmt.upper() == csv_country[0] : + if csv_country[0] == "USA" : + prev_prev_conf_elmt = prev_prev_conf_elmt.replace("\n"," ") + town = prev_prev_conf_elmt + country_acr = csv_country[1] + country = csv_country[0] + + else : + prev_conf_elmt = prev_conf_elmt.replace("\n"," ") + town = prev_conf_elmt + country_acr = csv_country[1] + country = csv_country[0] + + prev_prev_conf_elmt = prev_conf_elmt + prev_conf_elmt = conf_elmt + + except KeyError : + cnt_error_booktitle+=1 + + # get volume + try : + volume = entry['volume'] + except KeyError : + cnt_error_vol+=1 + + # get nb_pages + try : + nb_pages = entry['pages'] + except KeyError : + cnt_error_pages+=1 + + # get Year + try : + year = entry['year'] + except KeyError : + cnt_error_year_art+=1 + + # get DOI + try : + doi_value = entry['doi'] + except KeyError : + cnt_error_doi+=1 + + + if (type_publi == "COMM") or (type_publi == "BOOK") : + # get Publisher + try : + publisher_book = entry['publisher'] + except KeyError : + cnt_error_publisher+=1 + + # get Editor + try : + editor_book = entry['editor'] + except KeyError : + cnt_error_editor+=1 + + + # Test value "single" + # if false -> call createXml_sendHal (create XML and deposit) + # if true -> call create_single_xml (build XML without creation, no deposit) + if (type_publi == "ART") or (type_publi == "COMM") or (type_publi == "OUV") : + if single == False : + + action_todo="" + + # Verification que la publi n'existe pas deja dans HAL + # pour un meilleur matching, titre en minuscule et recherche par le champ title_t (sans casse ni accent) + title_low = title.lower() + url_request = "https://api.archives-ouvertes.fr/search/?q=title_t:\"{0}\"&fl=uri_s,halId_s,authFullName_s,authIdHal_s,title_s&wt=json".format(title_low) + + req = requests.get(url_request) + json = "" + try : + json = req.json() + except ValueError : + print ("PROBLEME VALUEERROR") + try : + if json is not "" : + result = json['response']['docs'] + + # si un resultat est trouve, recup authors et URI pour affichage dans 'resultat', action_todo = "E" + if (len(result) == 1 ) : + all_auth = "" + try : + tous_authors = result[0]["authFullName_s"] + for auth in tous_authors: + all_auth = all_auth + auth+"-" + except KeyError, e : + print ("error print authors existing publi") + resultat = resultat + "num. "+numero+" - "+result[0]["uri_s"]+" - auteurs:"+all_auth+"<br/>" + action_todo = "E" + + # si plusieurs resultats trouves, recup URI pour affichage dans 'problemes_doublon', action_todo = "2" + if (len(result) >1 ) : + problemes_doublon = problemes_doublon + "num. "+numero+" - URLS "+result[0]["uri_s"]+" "+result[1]["uri_s"]+"<br/>" + action_todo = "2" + + # Si aucun resultat on peut deposer, action_todo = "D" + if (len(result) == 0 ) : + action_todo = "D" + result = False + accept_depot = True + + # Si caracteres incoherents (issus de DBLP) dans le titre -> pas de depot -> problemes_depot + if ("\\(^\\mbox" in title) : + print("-----------------> MBOX") + accept_depot = False + result = False + + title = title.encode("utf-8") + conf = conf.encode("utf-8") + town = town.encode("utf-8") + editor_book = editor_book.encode("utf-8") + + if accept_depot == True : + print ("bool_depot_prod ",bool_depot_prod ) + result = createXml_sendHal(numero, listauthors, language, title, conf, nb_pages, year, listdomains, type_publi, town, country, country_acr,doi_value, editor_book, volume, name_user, labo_auth_final, id_hal_user, login_user, login_depot, passwd_depot, bool_depot_preprod, bool_depot_prod) + + # methode createXml_sendHal renvoie true -> depot HAL ou preprod OK + if result == True : + depots = depots + "num. "+numero+" au titre "+title.decode("utf-8")+" deposee dans HAL<br/>" + # methode createXml_sendHal renvoie true -> pb depot HAL ou preprod ou pas de depot demande + if result == False : + problemes_depot = problemes_depot + "num. "+numero+" au titre "+title.decode("utf-8")+" a un probleme de depot<br/>" + else : + # pb de lecture json, pas depot -> problemes_url + action_todo = "P" + problemes_url = problemes_url + "num. "+numero+" au titre "+title.decode("utf-8")+"<br/>" + except KeyError : + # pb de lecture json, pas depot -> problemes_url + action_todo = "P" + problemes_url = problemes_url + "num. "+numero+" au titre "+title.decode("utf-8")+"<br/>" + + # Creation du CSV qui sera renvoye et affiche + authors = authors.replace(" and",", ") + list_pub_csv.append((numero,authors,title,conf,nb_pages, volume,year, type_publi, action_todo, town, country, country_acr, language)) + + + elif single == True : + title = title.encode("utf-8") + conf = conf.encode("utf-8") + town = town.encode("utf-8") + editor_book = editor_book.encode("utf-8") + login_user = login_depot + reponse_single_xml = create_single_xml(listauthors, language, title, conf, nb_pages, year, listdomains, type_publi, town, country, country_acr, doi_value, editor_book, volume, name_user, labo_auth_final, id_hal_user, login_user) + + # ------------------END LOOP ----------------- + cnt_total+=1 + + ######################## + ####### ECRITURE RESULTATS -> list_resultats + print ("list_pub_csv length :",cnt_total) + + list_resultats=[] + for pub in list_pub_csv : + allauth = pub[1] + allauth = allauth.replace("\n","") + title = pub[2]#.decode("utf-8") + conf = pub[3]#.decode("utf-8") + ville = pub[9]#.decode("utf-8") + + list_resultats.append((str(pub[0]),allauth,title,conf,str(pub[4]),str(pub[5]),str(pub[6]),str(pub[7]),str(pub[8]),ville,str(pub[10]),str(pub[11]),str(pub[12]))) + + cnt_nb_publis = cnt_article + cnt_inproceeding + cnt_book + cnt_incollection + cnt_phdthesis + + list_resultats.append(("RESULTATS","nombre de publis",str(cnt_nb_publis),"","","","","","","","","","")) + list_resultats.append(("RESULTATS","publis deja presentes dans HAL",resultat,"","","","","","","","","","")) + list_resultats.append(("RESULTATS","depots",depots,"","","","","","","","","","")) + list_resultats.append(("RESULTATS","problemes de depot",problemes_depot,"","","","","", "","","","","")) + list_resultats.append(("RESULTATS","problemes de doublon",problemes_doublon,"","","","", "","","","","","")) + list_resultats.append(("RESULTATS","problemes url",problemes_url,"","","","","","","","","","")) + + print ("####### RESULTATS PARSING BIBTEX ########") + print ("cnt_article ", cnt_article) + print ("cnt_inproceeding ", cnt_inproceeding) + print ("cnt_proceeding ", cnt_proceeding) + print ("cnt_incollection ", cnt_incollection) + print ("cnt_book ", cnt_book) + print ("cnt_phdthesis ", cnt_phdthesis) + print ("cnt_total ", cnt_total) + + print ("ERROR Author", cnt_error_auth) + print ("ERROR Title", cnt_error_title) + + print ("-------ERRORS ARTICLE------") + print ("cnt_error_jrn",cnt_error_jrn) + print ("cnt_error_vol",cnt_error_vol) + print ("cnt_error_numb",cnt_error_numb) + print ("cnt_error_pages",cnt_error_pages) + print ("cnt_error_year_art",cnt_error_year_art) + print ("cnt_error_doi",cnt_error_doi) + + print ("-------ERRORS INPROCEEDINGS------") + print ("cnt_error_booktitle:",cnt_error_booktitle) + print ("cnt_error_pages:",cnt_error_pages) + print ("cnt_error_year_inp:",cnt_error_year_inp) + print ("cnt_error_crossref:",cnt_error_crossref) + print ("cnt_error_publisher:",cnt_error_publisher) + print ("cnt_error_editor:",cnt_error_editor) + + print ("-------ERRORS PROCEEDINGS------") + print ("cnt_error_idcrossref:",cnt_error_idcrossref) + + print ("#########################################") + + print ("######## RESULTATS XML + DEPOTS ##########") + print ("RESULTATS existants") + print (resultat.encode("utf-8")) + print ("------------------") + print ("DEPOTS effectues") + print (depots.encode("utf-8")) + print ("------------------") + print ("PROBLEMES DEPOTS") + print (problemes_depot.encode("utf-8")) + print ("------------------") + print ("PROBLEMES DOUBLONS") + print (problemes_doublon.encode("utf-8")) + print ("------------------") + print ("PROBLEMES URL") + print (problemes_url.encode("utf-8")) + + + if single == False : + return list_resultats + if single == True : + return reponse_single_xml diff --git a/hal/templates/base.html b/hal/templates/base.html index 54ea2d6d8d7ab4e19decaf29ac6fee035d0fe289..39ab07ed13c13fcba82117dcdd24f29456cfa88b 100644 --- a/hal/templates/base.html +++ b/hal/templates/base.html @@ -10,7 +10,7 @@ <head> <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"> <link rel="shortcut icon" href="{% static 'imgsite/favicon.ico' %}"> - <title>Outils Hal</title> + <title>ImportHal</title> </head> {% endblock %} <!-- <body> --> @@ -49,6 +49,13 @@ </div> </li> + <li class="nav-item dropdown"> + <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">CSV</a> + <div class="dropdown-menu" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(0px, 39px, 0px);"> + <a class="dropdown-item" href="{% url "csv2hal" %}">CSV_2_Hal</a> + </div> + </li> + <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">TEXT</a> <div class="dropdown-menu" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(0px, 39px, 0px);"> @@ -72,7 +79,7 @@ <h1 class="site-heading text-center text-white d-none d-lg-block"> - <span class="site-heading-upper text-primary mb-3">Outils HAL</span> + <span class="site-heading-upper text-primary mb-3">Import'HAL</span> </h1> diff --git a/hal/templates/hal/aide.html b/hal/templates/hal/aide.html index 3fe54813281880f0f1ff05855fbbc182fd1327b0..04bea03f9b485eba73e7046a07719c6b93d354b1 100644 --- a/hal/templates/hal/aide.html +++ b/hal/templates/hal/aide.html @@ -8,7 +8,7 @@ <head> <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"> <link rel="shortcut icon" href="{% static 'imgsite/favicon.ico' %}"> - <title>Outils HAL</title> + <title>ImportHAL</title> </head> {% endblock %} @@ -243,8 +243,39 @@ Copiez-collez le contenu de ce fichier dans l'emplacement prévu nommé <b>conte <p align="left"><b><u><a id="dblp_2_xml"></a>Create XML (from DBLP)</u></b></p> <p align="justify"> -TODO +Cet outil permet de générer un fichier XML au format TEI, donc importable dans HAL, mais sans faire d'import. +<br/> +Il ne permet de générer qu'un seul fichier XML à partir d'une seule entrée Bibtex. +<br/> +Cet outil sera utile lorsqu'un dépôt ne passe pas. +En effet l'idée est d'utiliser une fonctionnalité de <a href="https://api.archives-ouvertes.fr/docs/sword">SWORD</a>, un client web permettant d'importer un fichier XML. +<br/> +<br/> +Comme pour l'outil Bibtex_2_hal, remplissez les champs demandés. +<br/><br/> + +La <b>forme auteur</b> correspond à la dénomination littérale de l'auteur dans le fichier bibtex. +<br> +Le <b>nom</b> et <b>prénom</b> du chercheur correspondent à ce que vous souhaitez voir apparaître dans HAL +<br/> +Le <b>login Hal</b> et l<b>'idHal</b> du chercheur doivent vous être fournis par l'auteur lui-même dans le cas d'un dépôt sur la base HAL. +<br/> +Le <b>numéro de structure</b> correspond à son identifiant (id). Rentrez le nom de la structure sur la base AuréHAL pour l'obtenir et rentrez le tel quel (Ex : 490706) +<br/> +Les <b>domaines</b> sont généralement fournis par le chercheur et s'appliquent à toutes les publications. +<br/> +Cliquez <a href="#trav_equip">ici</a> pour en avoir la liste. +<br/><br/> + +Ouvrir le client web avec vos identifiants HAL à l'URL suivante <a href="https://api.archives-ouvertes.fr/sword/upload/"> + https://api.archives-ouvertes.fr/sword/upload/</a> +<br/> +Vous pouvez laisser tels quels tous les champs et juste importer votre fichier et cliquer sur "Transférer". +Si le transfert (import dans HAL) ne se fait pas, un message d'erreur vous indiquera où se situe le problème. +<br/> +<img src="{% static 'img/aide_upload_xml1.png' %}" > </p> + <br/> <br/> diff --git a/hal/templates/hal/bibtex2hal.html b/hal/templates/hal/bibtex2hal.html index 547584ad3e4a03b8cfbc93e9a78d293b829b6dd2..49ec8f5596a0152b258acbde271af9c546d5989c 100644 --- a/hal/templates/hal/bibtex2hal.html +++ b/hal/templates/hal/bibtex2hal.html @@ -8,7 +8,7 @@ <head> <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"> <link rel="shortcut icon" href="{% static 'imgsite/favicon.ico' %}"> - <title>Outils HAL</title> + <title>ImportHAL</title> </head> {% endblock %} diff --git a/hal/templates/hal/bibtexxml.html b/hal/templates/hal/bibtexxml.html index 4af806455ddd1a4dafb01155b4639c4b70f84a57..6014c2434cccf4f6a5a7f3bc6f528a1fec1ff57d 100644 --- a/hal/templates/hal/bibtexxml.html +++ b/hal/templates/hal/bibtexxml.html @@ -8,7 +8,7 @@ <head> <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"> <link rel="shortcut icon" href="{% static 'imgsite/favicon.ico' %}"> - <title>Outils HAL</title> + <title>ImportHAL</title> </head> {% endblock %} diff --git a/hal/templates/hal/blog.html b/hal/templates/hal/blog.html index 114a4c0a8cc182d0c6c5ed2b51c16c01b663aeb9..58e53c03665e1b04f2d8cd6661c1c44fb87c01fc 100644 --- a/hal/templates/hal/blog.html +++ b/hal/templates/hal/blog.html @@ -8,7 +8,7 @@ <head> <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"> <link rel="shortcut icon" href="{% static 'imgsite/favicon.ico' %}"> - <title>Outils HAL</title> + <title>ImportHAL</title> </head> {% endblock %} diff --git a/hal/templates/hal/connexion.html b/hal/templates/hal/connexion.html index adf7603a6fd16aeedbc2d43658c7648a915e40a4..8369beaef5a0675e086261f467088cd5d16d0fdd 100644 --- a/hal/templates/hal/connexion.html +++ b/hal/templates/hal/connexion.html @@ -8,7 +8,7 @@ <head> <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"> <link rel="shortcut icon" href="{% static 'imgsite/favicon.ico' %}"> - <title>Outils HAL</title> + <title>ImportHAL</title> </head> {% endblock %} diff --git a/hal/templates/hal/csv2hal.html b/hal/templates/hal/csv2hal.html new file mode 100644 index 0000000000000000000000000000000000000000..519ef5721615256c509f5aa1b9b5354290ae1583 --- /dev/null +++ b/hal/templates/hal/csv2hal.html @@ -0,0 +1,263 @@ +{% extends "base.html" %} +{% load static %} +{% load staticfiles %} +{% load bootstrap3 %} +{% load bootstrap_themes %} + +{% block head %} +<head> + <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"> + <link rel="shortcut icon" href="{% static 'imgsite/favicon.ico' %}"> + <title>ImportHAL</title> + +</head> +{% endblock %} + +{% block content %} +<h3>CSV to HAL</h3> + <br/> + {% if user.is_authenticated %} + <p align="left">Remplissez les données demandées ci-dessous + <br/> + Tous les champs sont requis + <br/> + Dans un premier temps, simulez le dépôt en laissant les champs "dépôt préprod" et "dépôt prod" décochés + <br/> + Copiez-collez le contenu de votre fichier CSV dans la zone prévue</p> + + <div class="well bs-component"> + <form action="{% url "csv2hal" %}" method="post"> + {% csrf_token %} + + <div class="row"> + + <div class="col-lg-12"> + <div class="fieldWrapper"> + <h3>Auteur</h3> + </div> + </div> + + <!-- 1e ligne --> + <div class="col-lg-4"> + <div class="fieldWrapper"> + {{ form.form_author.errors }} + {{ form.form_author.label_tag }}<br/> + {{ form.form_author }} + </div> + </div> + + <div class="col-lg-4"> + <div class="fieldWrapper"> + {{ form.name_user.errors }} + {{ form.name_user.label_tag }}<br/> + {{ form.name_user }} + </div> + </div> + + <div class="col-lg-4"> + <div class="fieldWrapper"> + {{ form.firstname_user.errors }} + {{ form.firstname_user.label_tag }}<br/> + {{ form.firstname_user }} + </div> + </div> + <!-- 2e ligne --> + + <div class="col-lg-4"> + <div class="fieldWrapper"> + {{ form.login_user.errors }} + {{ form.login_user.label_tag }}<br/> + {{ form.login_user }} + </div> + </div> + + <div class="col-lg-4"> + <div class="fieldWrapper"> + {{ form.id_hal_user.errors }} + {{ form.id_hal_user.label_tag }}<br/> + {{ form.id_hal_user }} + </div> + </div> + + <div class="col-lg-4"> + <div class="fieldWrapper"> + {{ form.labo_auth_final.errors }} + {{ form.labo_auth_final.label_tag }}<br/> + {{ form.labo_auth_final }} + </div> + <br/> + </div> + + + <!-- 3e ligne --> + <div class="col-lg-4"> + <div class="fieldWrapper"> + {{ form.domain1.errors }} + {{ form.domain1.label_tag }}<br/> + {{ form.domain1 }} + </div> + </div> + + <div class="col-lg-4"> + <div class="fieldWrapper"> + {{ form.domain2.errors }} + {{ form.domain2.label_tag }}<br/> + {{ form.domain2 }} + </div> + </div> + + <div class="col-lg-4"> + <div class="fieldWrapper"> + {{ form.domain3.errors }} + {{ form.domain3.label_tag }}<br/> + {{ form.domain3 }} + </div> + </div> + + <!-- 4e ligne --> + <div class="col-lg-4"> + <div class="fieldWrapper"> + {{ form.domain4.errors }} + {{ form.domain4.label_tag }}<br/> + {{ form.domain4 }} + </div> + </div> + + <div class="col-lg-4"> + <div class="fieldWrapper"> + {{ form.domain5.errors }} + {{ form.domain5.label_tag }}<br/> + {{ form.domain5 }} + </div> + </div> + + <div class="col-lg-4"> + <div class="fieldWrapper"> + </div> + </div> + + <div class="col-lg-12"> + <div class="fieldWrapper"> + <h3>Source</h3> + </div> + </div> + + <div class="col-lg-12"> + <div class="fieldWrapper"> + {{ form.choice_source.errors }} + {{ form.choice_source.label_tag }}<br/> + {{ form.choice_source }} + </div> + </div> + + <div class="col-lg-12"> + <div class="fieldWrapper"> + <h3>Déposant</h3> + </div> + </div> + + <!-- 5e ligne --> + <div class="col-lg-4"> + <div class="fieldWrapper"> + {{ form.login_depot.errors }} + {{ form.login_depot.label_tag }}<br/> + {{ form.login_depot }} + </div> + </div> + + <div class="col-lg-4"> + <div class="fieldWrapper"> + {{ form.passwd_depot.errors }} + {{ form.passwd_depot.label_tag }}<br/> + {{ form.passwd_depot }} + </div> + </div> + + <div class="col-lg-4"> + <div class="fieldWrapper"> + {{ form.choice_depot.errors }} + {{ form.choice_depot.label_tag }}<br/> + {{ form.choice_depot }} + </div> + </div> + + + <!-- 6e ligne --> + <div class="col-lg-12"> + <br/> + <hr> + <div class="fieldWrapper"> + {{ form.csv_file.errors }} + {{ form.csv_file.label_tag }}<br/> + {{ form.csv_file }} + </div> + </div> + </div> + + + <input type="submit" class="btn btn-primary" value="Submit" /> + </form> + </div> + + <div class="well bs-component"> + <div class="row"> + <div class="col-lg-12"> + <br/> + <b><u>Résultats :</u></b> + {% autoescape off %} + <br/> + <p align="left"> + {{ reponse_to_post }} + </p> + <br/> + {% endautoescape %} + <br/> + </div> + </div> + </div> + + {% if list_to_post|length > 0%} + <table class="table table-striped table-hover "> + <tr> + <th>n°</th> + <th>Auteurs </th> + <th>Titre</th> + <th>Conf</th> + <th>pp </th> + <th>vol</th> + <th>date</th> + <th>type </th> + <th>todo</th> + <th>Ville</th> + <th>pays </th> + <th>acr</th> + <th>lang</th> + </tr> + + {% for pub in list_to_post %} + <tr> + <td>{{ pub.num }}</td> + <td>{{ pub.authors }}</td> + <td>{{ pub.title }}</td> + <td>{{ pub.conf }}</td> + <td>{{ pub.page }}</td> + <td>{{ pub.vol }}</td> + <td>{{ pub.date }}</td> + <td>{{ pub.type }}</td> + <td>{{ pub.todo }}</td> + <td>{{ pub.ville }}</td> + <td>{{ pub.pays }}</td> + <td>{{ pub.acr }}</td> + <td>{{ pub.lang }}</td> + </tr> + {% endfor %} + </table> + {% endif %} + + {% else %} + <h5>Pour faire une demande d'identifiants, envoyer un mail à jessica.leyrit@uca.fr</h5> + <br/> + + {% endif %} + +{% endblock %} diff --git a/hal/templates/hal/index.html b/hal/templates/hal/index.html index a165d2567a5a895ea9e3144531c087dea93ec72d..d5fa2ca4eda6a9b98c3db28f4a86dfd4c5e7952a 100644 --- a/hal/templates/hal/index.html +++ b/hal/templates/hal/index.html @@ -8,7 +8,7 @@ <head> <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"> <link rel="shortcut icon" href="{% static 'imgsite/favicon.ico' %}"> - <title>Outils HAL</title> + <title>ImportHAL</title> </head> {% endblock %} @@ -30,7 +30,13 @@ <b>Bibtex_2_Hal</b> permet de faire des imports massifs dans HAL à partir de fichiers au format bibtex provenant de différentes sources. <br/> - <a href="https://dblp.uni-trier.de/" target="_blank">DBLP</a>. + <br/> + - <a href="https://dblp.uni-trier.de/" target="_blank">ENDNOTE</a>. <br/><br/> + <b>CSV_2_Hal</b> permet de faire des imports massifs dans HAL à partir de fichiers au format CSV provenant de différentes sources. + <br/> + - <a href="https://dblp.uni-trier.de/" target="_blank">KEYNOTE</a>. + <br/><br/> <b>Text_2_Hal</b> permet de faire des imports massifs dans HAL à partir d'une liste texte, de formater une liste texte ou de formater du texte issu de différentes sources telles que : <br/> - <a href="https://www.researchgate.net/" target="_blank">Research Gate</a> diff --git a/hal/templates/hal/text2hal.html b/hal/templates/hal/text2hal.html index 391d303002a816263b7848518f7fc127241dd4fa..374c075f6630d9fe6b4dc98fd9d59a0b4fe4101a 100644 --- a/hal/templates/hal/text2hal.html +++ b/hal/templates/hal/text2hal.html @@ -8,7 +8,7 @@ <head> <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"> <link rel="shortcut icon" href="{% static 'imgsite/favicon.ico' %}"> - <title>Outils HAL</title> + <title>ImportHAL</title> </head> {% endblock %} diff --git a/hal/templates/hal/text_format.html b/hal/templates/hal/text_format.html index 16522f201ade48197a4247ed095763ff1ef774fc..318b4288ae85e4d3ca60a794bf8a0ddfc9ed43d6 100644 --- a/hal/templates/hal/text_format.html +++ b/hal/templates/hal/text_format.html @@ -8,7 +8,7 @@ <head> <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"> <link rel="shortcut icon" href="{% static 'imgsite/favicon.ico' %}"> - <title>Outils HAL</title> + <title>ImportHAL</title> </head> {% endblock %} diff --git a/hal/templates/hal/textmodif.html b/hal/templates/hal/textmodif.html index 6783e7b4dbb98de83ba72d8f73a8c74de6b4210b..9691b1467c6d933f7cbd7308d7f3e7568609e5d8 100644 --- a/hal/templates/hal/textmodif.html +++ b/hal/templates/hal/textmodif.html @@ -8,7 +8,7 @@ <head> <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"> <link rel="shortcut icon" href="{% static 'imgsite/favicon.ico' %}"> - <title>Outils HAL</title> + <title>ImportHAL</title> </head> {% endblock %} diff --git a/hal/templates/hal/textxml.html b/hal/templates/hal/textxml.html index 02f43631f43a80655b6ad63dec1e4151ae42de1a..42b886b7783b03fc7f654b950ccb28107d19d079 100644 --- a/hal/templates/hal/textxml.html +++ b/hal/templates/hal/textxml.html @@ -8,7 +8,7 @@ <head> <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"> <link rel="shortcut icon" href="{% static 'imgsite/favicon.ico' %}"> - <title>Outils HAL</title> + <title>ImportHAL</title> </head> {% endblock %} diff --git a/hal/urls.py b/hal/urls.py index 2255940537281ad06899147f9e0c5a5eba0e1291..6932707f742793786435dbd1ac6600c2c9d0ee0b 100644 --- a/hal/urls.py +++ b/hal/urls.py @@ -10,6 +10,7 @@ urlpatterns = [ url(r'^blog$', views.article_blog, name='blog'), url(r'^bibtex2hal$', views.bibtex2hal, name='bibtex2hal'), url(r'^bibtexxml$', views.bibtexxml, name='bibtexxml'), + url(r'^csv2hal$', views.csv2hal, name='csv2hal'), url(r'^text2hal$', views.text2hal, name='text2hal'), url(r'^textxml$', views.textxml, name='textxml'), url(r'^textmodif$', views.textmodif, name='textmodif'), diff --git a/hal/views.py b/hal/views.py index 788fcc7c232a0870f502ed2d6ec97d8f7edc5990..8b9e02721139263a7d58b965dea1175daf6b0f0e 100644 --- a/hal/views.py +++ b/hal/views.py @@ -7,7 +7,8 @@ from django.contrib.auth.backends import ModelBackend from django.contrib.auth import authenticate, login from django.contrib.auth.views import logout -from forms import ConnexionForm, Bibtex2halForm, Text2halForm, BibtexXmlForm, TextXmlForm, ModifTextForm,TextFromRG +from forms import ConnexionForm, Bibtex2halForm, Text2halForm, BibtexXmlForm, Csv2halForm, \ + TextXmlForm, ModifTextForm,TextFromRG from scripts_bibtex import script_bibtex_2_hal from scripts_text import script_text_2_hal @@ -228,6 +229,99 @@ def bibtexxml(request): return render(request, 'hal/bibtexxml.html', locals()) + +################################################################################################################################## +## CSV2HAL ##################################################################################################################### +################################################################################################################################## + + +def csv2hal(request): + + reponse = "" + form = Csv2halForm(request.POST or None) + + if form.is_valid(): + # recup donnees + form_author = form.cleaned_data['form_author'] + name_user = form.cleaned_data['name_user'] + firstname_user = form.cleaned_data['firstname_user'] + labo_auth_final = form.cleaned_data['labo_auth_final'] + id_hal_user = form.cleaned_data['id_hal_user'] + login_user = form.cleaned_data['login_user'] + domain1 = form.cleaned_data['domain1'] + domain2 = form.cleaned_data['domain2'] + domain3 = form.cleaned_data['domain3'] + domain4 = form.cleaned_data['domain4'] + domain5 = form.cleaned_data['domain5'] + + login_depot = form.cleaned_data['login_depot'] + passwd_depot = form.cleaned_data['passwd_depot'] + #bool_depot_preprod = form.cleaned_data['bool_depot_preprod'] + #bool_depot_prod = form.cleaned_data['bool_depot_prod'] + choice_depot = form.cleaned_data['choice_depot'] + csv_file = form.cleaned_data['csv_file'] + + bool_depot_preprod = False + bool_depot_prod = False + + # recup du type de depot + if choice_depot == 'PREPROD' : + print ("Views.py depot preprod") + bool_depot_preprod = True + if choice_depot == 'PRODHAL' : + print ("Views.py depot prod") + bool_depot_prod = True + + + labo_auth_final = "struct-"+labo_auth_final + + #gestion domaines domain1 obligatoire + listdomains = [] + listdomains.append(domain1) + if domain2 is not "" : + listdomains.append(domain2) + if domain3 is not "" : + listdomains.append(domain3) + if domain4 is not "" : + listdomains.append(domain4) + if domain5 is not "" : + listdomains.append(domain5) + + single = False + + print ("begin script") + reponse = script_csv_2_hal (csv_file, bib_name_user, name_user, firstname_user, labo_auth_final, id_hal_user, login_user, listdomains, login_depot, passwd_depot, bool_depot_preprod, bool_depot_prod, single, source_csv) + + reponse_to_post = "" + list_to_post = [] + for result in reponse : + if result[0] == "RESULTATS" : + reponse_to_post = reponse_to_post+"<br/><br/><b>"+result[1]+"</b><br/>"+result[2] + else : + p = PubliDescribe() + p.num = result[0] + p.authors = result[1] + p.title = result[2] + p.conf = result[3] + p.page = result[4] + p.vol = result[5] + p.date = result[6] + p.type = result[7] + p.todo = result[8] + p.ville = result[9] + p.pays = result[10] + p.acr = result[11] + p.lang = result[12] + + list_to_post.append(p) + #list_to_post.append((result[0],result[1],result[2],result[3],result[4],result[5],\ + #result[6],result[7],result[8],result[9],result[10],result[11],result[12],)) + #reponse=("reponse HAL") + return render(request, 'hal/csv2hal.html', locals()) + + + + ################################################################################################################################## ## TEXT2HAL ##################################################################################################################### ################################################################################################################################## diff --git a/staticfiles/img/aide_upload_xml1.png b/staticfiles/img/aide_upload_xml1.png new file mode 100644 index 0000000000000000000000000000000000000000..7c3284212f8b32f6d46e6d90c55b945e9494543e Binary files /dev/null and b/staticfiles/img/aide_upload_xml1.png differ