diff --git a/hal/forms.py b/hal/forms.py index a592abd241f2c037ab6f292b2b6dfdeb3148ff15..74636cbf7a423f18e9d6d13451b69110be2aed3c 100644 --- a/hal/forms.py +++ b/hal/forms.py @@ -9,8 +9,8 @@ from django.contrib.admin import widgets class ConnexionForm(forms.Form): - username = forms.CharField(required=True, max_length=20, label="Login") - password = forms.CharField(required=True, max_length=20, label=("Mot de passe"), widget=forms.PasswordInput()) + username = forms.CharField(required=True, max_length=40, label="Login") + password = forms.CharField(required=True, max_length=400, label=("Mot de passe"), widget=forms.PasswordInput()) CHOICES_DEPOT= ( diff --git a/hal/templates/base.html b/hal/templates/base.html index 00ddf07ee52308235d3896fa06b77a3d36a2d0c7..77b7517a38572ce26c43925326633edef2cefcca 100644 --- a/hal/templates/base.html +++ b/hal/templates/base.html @@ -38,16 +38,7 @@ <a class="nav-link" href="{% url "blog" %}">Blog</a> </li> - {% if user.is_authenticated %} - - <li class="nav-item"> - <a class="nav-link" href="{% url "bibtex2hal" %}">Bibtex_2_Hal</a> - </li> - - <li class="nav-item"> - <a class="nav-link" href="{% url "csv2hal" %}">CSV_2_Hal</a> - </li> - + {% if user.is_authenticated %} <li class="nav-item"> <a class="nav-link" href="{% url "verifhalconf_ranking" %}">Fix_Hal_Ranking</a> </li> @@ -55,22 +46,32 @@ <li class="nav-item"> <a class="nav-link" href="{% url "search_hal_data" %}">Search_Data_Hal</a> </li> + {% endif %} + + {% if user.is_superuser %} + <li class="nav-item"> + <a class="nav-link" href="{% url "bibtex2hal" %}">Bibtex_2_Hal</a> + </li> + <li class="nav-item"> + <a class="nav-link" href="{% url "csv2hal" %}">CSV_2_Hal</a> + </li> <li class="nav-item"> <a class="nav-link" href="{% url "aide" %}">Aide</a> </li> - {% comment %} - <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);"> - <a class="dropdown-item" href="{% url "text2hal" %}">Text_2_Hal</a> - <a class="dropdown-item" href="{% url "textxml" %}">Create XML</a> - <a class="dropdown-item" href="{% url "textmodif" %}">Modify Text</a> - <a class="dropdown-item" href="{% url "text_format" %}">Format text</a> - </div> - </li> {% endcomment %} - {% endif %} + {% endif %} + + {% comment %} + <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);"> + <a class="dropdown-item" href="{% url "text2hal" %}">Text_2_Hal</a> + <a class="dropdown-item" href="{% url "textxml" %}">Create XML</a> + <a class="dropdown-item" href="{% url "textmodif" %}">Modify Text</a> + <a class="dropdown-item" href="{% url "text_format" %}">Format text</a> + </div> + </li> {% endcomment %} </ul> </div> diff --git a/hal/templates/hal/connexion.html b/hal/templates/hal/connexion.html index 57fa5bd0953ab222b921445723df5b69922b2e95..25ea4d159c404468255079d0df0b480a52e490d9 100644 --- a/hal/templates/hal/connexion.html +++ b/hal/templates/hal/connexion.html @@ -22,7 +22,7 @@ <br/> <a href="{% url "deconnexion" %}">Déconnexion</a> {% else %} - <h4>Pour faire une demande d'identifiants, envoyer un mail à jessica.leyrit@uca.fr</h4> + <h4>Pour vous identifier, vous devez être membre du LIMOS</h4> <br/> <div class="well bs-component"> <form action="{% url "connexion" %}" method="post"> diff --git a/hal/templates/hal/index.html b/hal/templates/hal/index.html index 9af6f6c0efbd0982261d0cad3f0f1a6dc012cc05..5103fe849018014278958aae4d19097dd9104362 100644 --- a/hal/templates/hal/index.html +++ b/hal/templates/hal/index.html @@ -36,13 +36,13 @@ <br/> <b>Bibtex_2_Hal</b> permet de faire des imports massifs dans HAL à partir de fichiers au format bibtex provenant de : <br/> - - <a href="https://dblp.uni-trier.de/" target="_blank">DBLP</a>. + - <a href="https://dblp.uni-trier.de/" target="_blank">DBLP</a> <i>(Uniquement pour les administrateurs)</i>. <!-- <br/> - <a href="https://endnote.com/" target="_blank">ENDNOTE</a>. --> - <br/><br/> + <!-- <br/><br/> <b>CSV_2_Hal</b> permet de faire des imports massifs dans HAL à partir de fichiers au format CSV provenant de : <br/> - - <a href="https://www.ncbi.nlm.nih.gov/pubmed/" target="_blank">PUBMED</a>. + - <a href="https://www.ncbi.nlm.nih.gov/pubmed/" target="_blank">PUBMED</a>. --> <br/><br/> <b>Fix_Hal_Ranking</b> permet de vérifier si les noms des journaux et conférences indiqués dans les publis déposées dans HAL correspondent aux entrées de Scimago et Core : <br/> diff --git a/hal/urls.py b/hal/urls.py index 75de25c4947e577c174da1e18018a3e7347e6a07..6baad6629fcddf0700907cd31b0198317cc2f8b2 100644 --- a/hal/urls.py +++ b/hal/urls.py @@ -10,7 +10,7 @@ urlpatterns = [ url(r'^blog$', views.article_blog, name='blog'), url(r'^bibtex2hal$', views.bibtex2hal, name='bibtex2hal'), url(r'^bibformat_2hal/(?P<csvfile>[\w\-]+)$', views.bibformat_2hal, name='bibformat_2hal'), - url(r'^validatepost2hal$', views.validatepost2hal, name='validatepost2hal'), + #url(r'^validatepost2hal$', views.validatepost2hal, name='validatepost2hal'), url(r'^verifhalconf_ranking$', views.verifhalconf_ranking, name='verifhalconf_ranking'), url(r'^verifhal_byuser/(?P<csvfile>[\w\-]+)$', views.verifhal_byuser, name='verifhal_byuser'), diff --git a/hal/views.py b/hal/views.py index ea122a738b3c5126eff5a995413276e415eef968..eb95d900563b15b43b27b069d9e8cd4e0afb5748 100644 --- a/hal/views.py +++ b/hal/views.py @@ -3,11 +3,16 @@ from __future__ import unicode_literals from django.shortcuts import render,redirect +from django_auth_ldap.backend import LDAPBackend from django.contrib.auth.backends import ModelBackend from django.contrib.auth import authenticate, login, logout +from django.contrib.auth.decorators import login_required + #from django.contrib.auth.views import logout from django.contrib import messages from django.core.checks.messages import Error +from django.db.models import Q +from django.contrib.auth.models import User, Permission from .forms import ConnexionForm, Bibtex2halForm, BibtexXmlForm, Csv2halForm, VerifHalConfForm, Bibformat2halForm ,SearchDataHalForm, \ TextXmlForm, ModifTextForm,TextFromRG, Text2halForm @@ -41,7 +46,7 @@ def index(request): return render(request, 'hal/index.html') # allows connection through table User in database haltools -def connexion(request): +def connexion_old(request): reponse = "" form = ConnexionForm(request.POST or None) if form.is_valid(): @@ -57,7 +62,42 @@ def connexion(request): reponse = ('Erreur d authentification') return render(request, 'hal/connexion.html', locals()) - + +# allows connection through table User in database haltools +def connexion(request): + reponse = "" + form = ConnexionForm(request.POST or None) + if form.is_valid(): + username = form.cleaned_data['username'] + password = form.cleaned_data['password'] + + try : + authldap = LDAPBackend() #authentification par le LDAP defini dans settings.py + authmodel = ModelBackend() + userldap = authldap.authenticate(request=request, username=username, password=password) + + if userldap is not None: + usermodels = User.objects.filter(Q(username=userldap.username) & Q(last_name=userldap.last_name) & Q(first_name=userldap.first_name)) + if len(usermodels) == 0 : + # jamais connecte, creation ds Django Auth User + print("create Auth User for {0}".format(userldap.username)) + uniq_user = User.objects.create(username=userldap.username,last_name=userldap.last_name,first_name=userldap.first_name, email=userldap.mail) + login (request, uniq_user, backend='django_auth_ldap.backend.LDAPBackend') + elif len(usermodels) == 1 : + # OK, connexion + uniq_user = usermodels[0] + login (request, uniq_user, backend='django_auth_ldap.backend.LDAPBackend') + else : + # probleme plusieurs users pr le meme username + print("PROBLEM") + reponse = 'Erreur d authentification' + + except authldap.ldap.INVALID_CREDENTIALS: + authldap.ldap_client.unbind() + print ('Wrong username password') + reponse = 'Erreur d authentification' + + return render(request, 'hal/connexion.html', locals()) # disconnect user def deconnexion(request): @@ -112,7 +152,8 @@ class PubliChange(): ################################################################################################################################## ## BIBTEX2HAL ###################################################################################################################### ################################################################################################################################## - + +@login_required def bibtex2hal(request): ''' treats a bibtex file and some variables @@ -145,6 +186,7 @@ def bibtex2hal(request): return render(request, 'hal/bibtex2hal.html', locals()) +@login_required def bibformat_2hal(request, csvfile): print("method views.bibformat_2hal") form = Bibformat2halForm(request.POST or None) @@ -213,7 +255,7 @@ def bibformat_2hal(request, csvfile): ## A enlever -def validatepost2hal(request): +""" def validatepost2hal(request): print("method views.validatepost2hal") if request.method == 'POST' : @@ -223,64 +265,14 @@ def validatepost2hal(request): for pub_upd in list_publis_to_update : print(pub_upd) - return redirect('https://http.cat/425') - -################################################################################################################################## -## bibtexXML ###################################################################################################################### -################################################################################################################################## - -""" def bibtexxml(request): - reponse = "" - form = BibtexXmlForm(request.POST or None) - - if form.is_valid(): - # recup donnees - bib_name_user = form.cleaned_data['bib_name_user'] - 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'] - - choice_source = form.cleaned_data['choice_source'] - - bibtex_file = form.cleaned_data['bibtex_file'] - login_depot = request.user - passwd_depot = "" - bool_depot_preprod = False - bool_depot_prod = False - single = 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) - - reponse_to_post = script_bibtex_2_hal(bibtex_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, choice_source) - - #print (reponse_to_post) - return render(request, 'hal/bibtexxml.html', locals()) """ - + return redirect('https://http.cat/425') """ ################################################################################################################################## ## UPDATE_HAL ###################################################################################################################### ################################################################################################################################## - + +@login_required def verifhalconf_ranking(request): ''' update HAL from Bitex DBLP -> change name conf @@ -311,7 +303,7 @@ def verifhalconf_ranking(request): return render(request, 'hal/verifhalconf_ranking.html', locals()) - +@login_required def verifhal_byuser(request, csvfile): print("method views.verifhal_byuser") try : @@ -340,7 +332,7 @@ def verifhal_byuser(request, csvfile): return redirect('https://http.cat/425') - +@login_required def valid_post_hal(request): print("method views.valid_update_hal") print(request) @@ -356,12 +348,41 @@ def valid_post_hal(request): return render(request,'hal/updatehal_byuser.html', locals() ) +################################################################################################################################## +## SEARCHHALDATA ################################################################################################################ +################################################################################################################################## + +@login_required +def search_hal_data(request): + + reponse = "" + csvfile = "" + form = SearchDataHalForm(request.POST or None) + + if form.is_valid(): + mail_response = form.cleaned_data['mail_response'] + annee_debut = form.cleaned_data['annee_debut'] + annee_fin = form.cleaned_data['annee_fin'] + users_hal = form.cleaned_data['users_hal'] + + if int(annee_debut) >= int(annee_fin) : + msg_to_announce = "Problème : l'année de début doit être inférieure à l'année de fin {0}".format(mail_response) + + else : + searchdatahal.delay(mail_response, annee_debut, annee_fin, users_hal) + + msg_to_announce = "Un mail vous sera envoyé à l'adresse suivante : {0}".format(mail_response) + + messages.add_message(request, messages.WARNING, msg_to_announce) + + return render(request, 'hal/searchdatahal.html', locals()) ################################################################################################################################## ## CSV2HAL ##################################################################################################################### ################################################################################################################################## - +## NOT USED +@login_required def csv2hal(request): reponse = "" csvfile = "" @@ -473,468 +494,4 @@ def csv2hal(request): -################################################################################################################################## -## SEARCHHALDATA ################################################################################################################ -################################################################################################################################## - - -def search_hal_data(request): - - reponse = "" - csvfile = "" - form = SearchDataHalForm(request.POST or None) - - if form.is_valid(): - mail_response = form.cleaned_data['mail_response'] - annee_debut = form.cleaned_data['annee_debut'] - annee_fin = form.cleaned_data['annee_fin'] - users_hal = form.cleaned_data['users_hal'] - - if int(annee_debut) >= int(annee_fin) : - msg_to_announce = "Problème : l'année de début doit être inférieure à l'année de fin {0}".format(mail_response) - - else : - searchdatahal.delay(mail_response, annee_debut, annee_fin, users_hal) - - msg_to_announce = "Un mail vous sera envoyé à l'adresse suivante : {0}".format(mail_response) - - messages.add_message(request, messages.WARNING, msg_to_announce) - - return render(request, 'hal/searchdatahal.html', locals()) - - -################################################################################################################################## -## TEXT2HAL ##################################################################################################################### -################################################################################################################################## -""" -def text2hal(request): - - reponse = "" - form = Text2halForm(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'] - text_file = form.cleaned_data['text_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_text_2_hal(text_file, form_author, name_user, firstname_user, labo_auth_final, id_hal_user, login_user, listdomains, login_depot, passwd_depot, bool_depot_preprod, bool_depot_prod, single) - - 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/text2hal.html', locals()) -""" -################################################################################################################################## -## TEXTXML ###################################################################################################################### -################################################################################################################################## -""" -def textxml (request): - reponse = "" - form = TextXmlForm(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'] - - text_file = form.cleaned_data['text_file'] - login_depot = request.user - passwd_depot = "" - bool_depot_preprod = False - bool_depot_prod = False - single = 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 = True - - print ("begin script") - reponse_to_post = script_text_2_hal(text_file, form_author, name_user, firstname_user, labo_auth_final, id_hal_user, login_user, listdomains, login_depot, passwd_depot, bool_depot_preprod, bool_depot_prod, single) - - #print ("REPONSE") - #print (reponse_to_post) - return render(request, 'hal/textxml.html', locals()) - -################################################################################################################################## -## TEXTMODIF #################################################################################################################### -################################################################################################################################## - -def textmodif(request): - reponse = "" - form = ModifTextForm(request.POST or None) - if form.is_valid(): - # recup donnees - delete_char = form.cleaned_data['delete_char'] - add_begin = form.cleaned_data['add_begin'] - clean_text = form.cleaned_data['clean_text'] - reverse_first_lastname = form.cleaned_data['reverse_first_lastname'] - get_volume = form.cleaned_data['get_volume'] - get_pages = form.cleaned_data['get_pages'] - transform_country = form.cleaned_data['transform_country'] - text_modif = form.cleaned_data['text_modif'] - - reponse_to_post = text_modif - - # Action effectuee sur l'ensemble du texte - if delete_char > 0 : - result = "" - list_publis = reponse_to_post.splitlines() - for publi in list_publis : - result = result + publi[delete_char:] + "\n" - reponse_to_post = result - - # Action effectuee sur l'ensemble du texte - if add_begin is not "" : - result = "" - cnt = 0 - list_publis = reponse_to_post.splitlines() - for publi in list_publis : - cnt+=1 - result = result + add_begin + str(cnt) + " - " + publi + "\n" - reponse_to_post = result - - # Action effectuee sur l'ensemble du texte - if clean_text == True : - reponse_to_post = reponse_to_post.replace("« ","\"") - reponse_to_post = reponse_to_post.replace(" »","\"") - reponse_to_post = reponse_to_post.replace("«","\"") - reponse_to_post = reponse_to_post.replace("»","\"") - reponse_to_post = reponse_to_post.replace("‘","'") - reponse_to_post = reponse_to_post.replace("’","'") - reponse_to_post = reponse_to_post.replace("“","\"") - reponse_to_post = reponse_to_post.replace("â€","\"") - reponse_to_post = reponse_to_post.replace("\"\"","\"") - reponse_to_post = reponse_to_post.replace(" "," ") - - # Action effectuee ligne par ligne - list_publis = reponse_to_post.splitlines() - result = "" - listauthors = "" - for publi in list_publis : - print ("**********") - x = publi.find("-") - numero = publi[0:x+1] - publi = publi[x:] - x = publi.find("\"") - authors = publi[1:x] - authors = authors.strip() - listauthors = authors - if reverse_first_lastname is True : - listauthors = "" - list_authors_mix = authors.split(",") - - # si champ vide, non pris en compte - if list_authors_mix[-1].strip() == "" : - del list_authors_mix[-1] - - for auth in list_authors_mix : - auth = auth.strip() - newauth = auth.split(" ") - prenom = newauth[0] - nom = newauth[1] - print (nom, prenom) - listauthors = listauthors+nom + " "+prenom+"," - - rest_publi = publi[x:] - - x = rest_publi.find("\"") - title = rest_publi[:x] - rest_publi = rest_publi[x:] - - x = rest_publi.find(",") - conf = rest_publi[:x] - rest_publi = rest_publi[x:] - - if get_volume == True : - rest_publi = rest_publi.replace("Volume ","Vol. ") - rest_publi = rest_publi.replace("volume ","Vol. ") - rest_publi = rest_publi.replace("vol. ","Vol. ") - - if get_pages == True : - - rest_publi = rest_publi.replace("pages ","pp. ") - - if transform_country == True : - print ("transform") - list_pays = [] - with open('hal/countries.csv', 'rb') as csvfile: #open('/home/bastien/halenv/haltools/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_pays.append((row[1],row[2],row[3])) - - match = False - - for pays in list_pays : - #rest_publi = rest_publi.decode("utf-8") - searched_country = pays[1].decode("utf-8") - country_index = rest_publi.find(searched_country) - if country_index > 0 : - country=rest_publi[country_index:] - print ("Country_text :"+country) - value_stop = re.findall(',',country)[0] #([[:punct:]]|[[:space:]]) - value_stop = country.find(value_stop) - if value_stop > 0 : - country=country[:value_stop] - print (country) - old_c = country - new_c = pays[0] - #print ("old ",old_c, " new ",new_c) - match = True - - if match == False : - for pays in list_pays : - #rest_publi = rest_publi.decode("utf-8") - searched_country = pays[2]#.decode("utf-8") - country_index = rest_publi.find(searched_country) - if country_index > 0 : - country=rest_publi[country_index:] - value_stop = re.findall(',',country)[0] - value_stop = country.find(value_stop) - if value_stop > 0 : - country=country[:value_stop] - print (country) - old_c = country - new_c = pays[0] - #print ("old ",old_c, " new ",new_c) - match = True - - if match == True : - rest_publi = rest_publi.replace(old_c, new_c) - - ''' - search_countries = rest_publi.split(",") - for country in search_countries : - for pays in list_pays : - if country.strip() == pays[1] : - print ("************ MATCH *****************") - old_c = country - new_c = pays[0] - print ("old ",old_c, " new ",new_c) - match = True - if match == True : - rest_publi = rest_publi.replace(old_c, new_c) - ''' - # reconstruction texte - print ("listauthors "+listauthors) - result = result + numero +" "+ listauthors + title + conf + rest_publi + "\n" - reponse_to_post = result - - - return render(request, 'hal/textmodif.html', locals()) - - -################################################################################################################################## -## FORMAT_RG #################################################################################################################### -################################################################################################################################## - -def text_format(request): - reponse = "" - form = TextFromRG(request.POST or None) - result = "" - if form.is_valid(): - # recup donnees - choice_source = form.cleaned_data['choice_source'] - text_modif = form.cleaned_data['text_modif'] - - reponse_to_post = text_modif - - list_publis = reponse_to_post.splitlines() - - result = "" - - # Format text for source Research_Gate - if choice_source == "RG" : - for publi in list_publis : - print ("********************") - #publi = publi[1:] - #print (publi) - x = publi.find(":")#.decode('utf-8') - authors = publi[0:x] - authors = authors.strip() - - rest_publi = publi[x+1:] - - x = rest_publi.find(".") - title = rest_publi[1:x] - rest_publi = rest_publi[x+1:] - - conf = "" - year = "" - vol = "" - pp = "" - # recherche de l'element mois + / -> 04/ 11/ ... - try : - end_conf = re.findall('\s[0-1][0-9][\/]', rest_publi)[0] - x = rest_publi.find(end_conf) - if x > -1 : - conf = rest_publi[:x] - conf = conf.replace(";","") - conf = conf.strip() - rest_publi = rest_publi[x:] - print ("rest_publi 1 :"+rest_publi) - year = rest_publi[4:] - x = year.find(";") - # si ; apres annee --> article, sinon conf - - if x > -1 : # ARTICLE - year = year[:x] - year = year.replace(",","") - year = year.strip() - rest_publi = rest_publi[x+4:] - print ("rest_publi 2 :"+rest_publi) - - vol = rest_publi - - y = vol.find("DOI") - if y > -1 : - vol = vol[:y] - - y = vol.find(":") - if y > -1 : - vol = vol[:y] - vol = vol.replace(";","") - vol = vol.strip() - rest_publi = rest_publi[y+1:] - print ("rest_publi 3 :"+rest_publi) - pp = rest_publi - z = pp.find("DOI") - pp = pp[:z-1] - pp = pp.replace(".","") - pp = pp.replace(",","") - pp = pp.strip() - rest_publi = rest_publi[z:] - - - print ("rest_publi 4 :"+rest_publi) - - elif y == -1 : - print ("--> --> --> NO PAGES rest_publi 3 :"+rest_publi) - y = vol.find(".") - vol = vol[:y] - vol = vol.replace(";","") - vol = vol.replace(",","") - rest_publi = rest_publi[y+2:] - - rest_publi = rest_publi.replace("DOI:","doi:") - - print ("year "+year + " vol "+vol+ " pages "+pp + " rest_pub "+ rest_publi) - - elif x == -1 : # CONF - end_year = re.findall('\D', year)[0] - x = year.find(end_year) - - year = year[:x] - print ("YEAR "+year) - - #print ("rest_publi "+rest_publi) - except IndexError : - print ("IndexError "+title) - - #x = publi.find("-")#.decode('utf-8') - #numero = publi[0:x] - end_string_vol_pages = "" - if vol is not "" : - end_string_vol_pages = end_string_vol_pages+", Vol. "+vol - if pp is not "" : - end_string_vol_pages = end_string_vol_pages+", pp. "+pp - #print ("end_string_vol_pages "+end_string_vol_pages) - result = result+authors+","+"\""+title+"\","+conf+", "+year+end_string_vol_pages+", "+rest_publi+"\n"# +rest_publi - - - print (result) - reponse_to_post = result - - return render(request, 'hal/text_format.html', locals()) - -""" \ No newline at end of file diff --git a/haltools/settings.py b/haltools/settings.py index fdb52480bc13d95ef30b8e4a2087523f2c01649a..6441f3c985e30e63d8ef178b6ab496ea2588f4b1 100644 --- a/haltools/settings.py +++ b/haltools/settings.py @@ -12,6 +12,43 @@ https://docs.djangoproject.com/en/1.11/ref/settings/ import os +import os + +# pour binder sur le LDAP : django-auth-ldap et python-ldap +from django_auth_ldap.config import LDAPSearch, LDAPSearchUnion, GroupOfNamesType, ActiveDirectoryGroupType, NestedActiveDirectoryGroupType, NestedGroupOfNamesType, ActiveDirectoryGroupType +import ldap + +# 1 - configuration pour l'utilisateur LDAP cherchant dans l'AD 192.168.100.75 = Samantha +AUTH_LDAP_SERVER_URI = "ldap://********"#"ldap://192.168.100.75:389" +AUTH_LDAP_BIND_DN = "cn=silimos,ou=Comptes de Services,dc=local,dc=isima,dc=fr" +AUTH_LDAP_BIND_PASSWORD = '*******' +AUTH_LDAP_CONNECTION_OPTIONS = { + ldap.OPT_REFERRALS: 0 +} + +# sur tony chercher dans IQ0C, IT0C, JA0L et JB0L mais ces OU comprennent aussi d autres personnes ne devant pas se connecter normalement +AUTH_LDAP_USER_SEARCH = LDAPSearch("dc=local,dc=isima,dc=fr", ldap.SCOPE_SUBTREE, "(samAccountName=%(user)s)") +#AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=uca,ou=Personnel,ou=Utilisateurs,dc=local,dc=isima,dc=fr", ldap.SCOPE_SUBTREE, "(samAccountName=%(user)s)") + +# Set up the basic group parameters. +# Ici, on veut le groupe limos_personnel ainsi que les groupes imbriques (nested) comme limos_externe +AUTH_LDAP_GROUP_SEARCH = LDAPSearch("dc=local,dc=isima,dc=fr", + ldap.SCOPE_SUBTREE, "(objectClass=group)" +) +AUTH_LDAP_GROUP_TYPE = NestedActiveDirectoryGroupType() + +#AUTH_LDAP_REQUIRE_GROUP = "cn=labo_total,ou=LABO,ou=GROUPES_LOCAUX,dc=local,dc=isima,dc=fr" +AUTH_LDAP_REQUIRE_GROUP = "CN=srv_grp_intranet_limos,OU=SERVICES,OU=GROUPES_LOCAUX,DC=local,DC=isima,DC=fr" + +# 3 - Liste des infos renvoyees +AUTH_LDAP_USER_ATTR_MAP = {"first_name": "givenName", "last_name": "sn",\ + "email": "mail", "login": "sAMAccountName", "dname":"distinguishedName"} + +# 4 - Moyen d'authentification, si le LDAP n'est pas accessible, on bascule sur la table auth_user +AUTHENTICATION_BACKENDS = ('django_auth_ldap.backend.LDAPBackend', \ +'django.contrib.auth.backends.ModelBackend',) + + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -19,7 +56,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '******' +SECRET_KEY = '********************************' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True @@ -102,7 +139,7 @@ DATABASES = { 'OPTIONS' : {"init_command": "SET foreign_key_checks = 0;"}, 'NAME': 'haltools', 'USER': 'haladmin', - 'PASSWORD': 'halpasswd', + 'PASSWORD': '***********', 'HOST': '127.0.0.1', 'PORT': '', } @@ -136,13 +173,13 @@ EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_USE_TLS = True EMAIL_HOST = 'mail.isima.fr' EMAIL_PORT = 587 -EMAIL_HOST_USER = '******@isima.fr'# 'cri-commun@isima.fr' -EMAIL_HOST_PASSWORD = '' +EMAIL_HOST_USER = 'cribot@isima.fr'# 'cri-commun@isima.fr' +EMAIL_HOST_PASSWORD = '****************' DEFAULT_FROM_EMAIL = EMAIL_HOST_USER # Celery Configuration Options CELERYD_NODES="w1 w2" -CELERY_BROKER_URL = "amqp://halrabbuser:******@localhost:5672//" +CELERY_BROKER_URL = "amqp://halrabbuser:*************@localhost:5672//" CELERY_TIMEZONE = "UTC" CELERY_TASK_TRACK_STARTED = True