From b20f2692c081e9760e9f8dbfc70e9646d5658f9c Mon Sep 17 00:00:00 2001 From: beaufilx <Est1tiam2y@24> Date: Thu, 23 Jan 2025 15:09:32 +0100 Subject: [PATCH 1/6] Sauvegarde de la recherche XML --- src/ptf_tools/indexingChecker.py | 114 +++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 src/ptf_tools/indexingChecker.py diff --git a/src/ptf_tools/indexingChecker.py b/src/ptf_tools/indexingChecker.py new file mode 100644 index 00000000..c000a066 --- /dev/null +++ b/src/ptf_tools/indexingChecker.py @@ -0,0 +1,114 @@ +from django.conf import settings + +import json +import requests +from lxml import etree +from ptf import model_helpers + +import os.path + +class Comparator: + + xml_files = [] + + def __init__(self): + self._start = 0 + self._count = 0 + self._result = [] + + def _query(self): + url = "https://api.adsabs.harvard.edu/v1/search/query" + query_param = { + "fl": "doi,title,pub", + "rows": "200", + "start": self._start, + # "fq": "{!type=aqp v=$fq_database}", + # "fq_database": "(database:astronomy OR database:physics)", + "q": "pub:\"comptes rendus physique\"", + } + """ + await fetch( + "https://ui.adsabs.harvard.edu/v1/search/query?fl=identifier%2C%5Bcitations%5D%2Cabstract%2Cauthor%2Cbook_author%2Corcid_pub%2Cpublisher%2Corcid_user%2Corcid_other%2Cbibcode%2Ccitation_count%2Ccomment%2Cdoi%2Cid%2Ckeyword%2Cpage%2Cproperty%2Cpub%2Cpub_raw%2Cpubdate%2Cpubnote%2Cread_count%2Ctitle%2Cvolume%2Cdatabase%2Clinks_data%2Cesources%2Cdata%2Ccitation_count_norm%2Cemail%2Cdoctype&fq=%7B!type%3Daqp%20v%3D%24fq_database%7D&fq_database=(database%3Aastronomy%20OR%20database%3Aphysics)&p_=0&q=pub%3A%22comptes rendus physique%22&rows=25&sort=date%20desc%2C%20bibcode%20desc&start=0", + { + "credentials": "include", + "headers": { + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:134.0) Gecko/20100101 Firefox/134.0", + "Accept": "application/json, text/javascript, */*; q=0.01", + "Accept-Language": "fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3", + "Content-Type": "application/x-www-form-urlencoded", + "Authorization": "Bearer c3Z1jnVwby4umAAvu3C6aHqP8fTDMjqivOjXp9Bg", + "X-Requested-With": "XMLHttpRequest", + "sentry-trace": "5df9278bedb844c7b650fb90ee8cc2fc-b84c9e138292d0e4-1", + "baggage": "sentry-environment=production,sentry-public_key=46062cbe0aeb7a3b2bb4c3a9b8cd1ac7,sentry-trace_id=5df9278bedb844c7b650fb90ee8cc2fc,sentry-sample_rate=0.75,sentry-sampled=true", + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-origin" + }, + "referrer": "https://ui.adsabs.harvard.edu/search/fq=%7B!type%3Daqp%20v%3D%24fq_database%7D&fq_database=(database%3Aastronomy%20OR%20database%3Aphysics)&p_=0&q=pub%3A%22comptes%20rendus%20physique%22&sort=date%20desc%2C%20bibcode%20desc", + "method": "GET", + "mode": "cors" + }); + """ + response = requests.get(url, params=query_param, headers={"Authorization": "Bearer " + settings.ADS_TOKEN}) + response.raise_for_status() + data = json.loads(response.text) + self._count = data["response"]["numFound"] + self._start += 200 + return data["response"]["docs"] + + def _loadXml(self, basefilename): + index = 1 + print("Basefilename " + basefilename) + filename = basefilename + while os.path.isfile(filename): + print("Filename " + filename) + tree = etree.parse(filename) + self.xml_files.append(XmlFile(filename, tree.getroot())) + filename = basefilename[:-4] + filename = filename + "(" + str(index) + ").xml" + index += 1 + + def _search(self, doi, index): + predicate = str('.//{https://ads.harvard.edu/schema/abs/1.1/jats}article-id[@pub-id-type="doi"][.="' + doi + '"]') + #print("Predicate " + predicate + " root " + str(self.xml_files[index].root)) + article = self.xml_files[index].root.findall(predicate) + return article + + def compare(self, collection_PID): + # self._loadXml("/home/beaufilx/Téléchargements/export-jatsxml.xml") + while self._count >= self._start: + self._result += self._query() + journal = model_helpers.get_collection(collection_PID) + print(journal) + result = model_helpers.get_volumes_in_collection(journal) + print(result) + sorted_issues = result["sorted_issues"] + volumes = sorted_issues[0]['volumes'] + for volume in volumes: + for issue in volume['issues']: + articles = issue.article_set.all().order_by("doi") + for article in articles: + if article.doi[:7] == '10.5802': + #print("------------ Searching " + article.doi + " ----------------") + found = False + end_of_file = False + index = 0 + while not found and not end_of_file: + #print("Search in " + self.xml_files[index].filename) + found = self._search(article.doi, index) + #print("DOI " + str(article.doi) + " " + str(found)) + if index + 1 == len(self.xml_files): + end_of_file = True + if not found: + index += 1 + if not found: + print(article.doi) + + +class XmlFile: + filename: str + root: any + + def __init__(self, filename, root): + self.filename = filename + self.root = root -- GitLab From 2773f132fa6bb17aebbf41b06dc3a92a0f8fd60b Mon Sep 17 00:00:00 2001 From: beaufilx <Est1tiam2y@24> Date: Fri, 31 Jan 2025 18:10:56 +0100 Subject: [PATCH 2/6] =?UTF-8?q?AdsQuery=20externalis=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ptf_tools/indexingChecker.py | 158 ++++++++--------------- src/ptf_tools/urls.py | 12 ++ src/ptf_tools/views/base_views.py | 35 +++++ src/templates/dashboard/referencing.html | 40 ++++++ src/templates/top_nav.html | 26 ++++ 5 files changed, 164 insertions(+), 107 deletions(-) create mode 100644 src/templates/dashboard/referencing.html diff --git a/src/ptf_tools/indexingChecker.py b/src/ptf_tools/indexingChecker.py index c000a066..01509b45 100644 --- a/src/ptf_tools/indexingChecker.py +++ b/src/ptf_tools/indexingChecker.py @@ -1,114 +1,58 @@ -from django.conf import settings - -import json -import requests -from lxml import etree from ptf import model_helpers +from ptf.external.ads import AdsQuery, AdsArticle -import os.path class Comparator: - - xml_files = [] + _journals = {} def __init__(self): - self._start = 0 - self._count = 0 - self._result = [] - - def _query(self): - url = "https://api.adsabs.harvard.edu/v1/search/query" - query_param = { - "fl": "doi,title,pub", - "rows": "200", - "start": self._start, - # "fq": "{!type=aqp v=$fq_database}", - # "fq_database": "(database:astronomy OR database:physics)", - "q": "pub:\"comptes rendus physique\"", - } - """ - await fetch( - "https://ui.adsabs.harvard.edu/v1/search/query?fl=identifier%2C%5Bcitations%5D%2Cabstract%2Cauthor%2Cbook_author%2Corcid_pub%2Cpublisher%2Corcid_user%2Corcid_other%2Cbibcode%2Ccitation_count%2Ccomment%2Cdoi%2Cid%2Ckeyword%2Cpage%2Cproperty%2Cpub%2Cpub_raw%2Cpubdate%2Cpubnote%2Cread_count%2Ctitle%2Cvolume%2Cdatabase%2Clinks_data%2Cesources%2Cdata%2Ccitation_count_norm%2Cemail%2Cdoctype&fq=%7B!type%3Daqp%20v%3D%24fq_database%7D&fq_database=(database%3Aastronomy%20OR%20database%3Aphysics)&p_=0&q=pub%3A%22comptes rendus physique%22&rows=25&sort=date%20desc%2C%20bibcode%20desc&start=0", - { - "credentials": "include", - "headers": { - "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:134.0) Gecko/20100101 Firefox/134.0", - "Accept": "application/json, text/javascript, */*; q=0.01", - "Accept-Language": "fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3", - "Content-Type": "application/x-www-form-urlencoded", - "Authorization": "Bearer c3Z1jnVwby4umAAvu3C6aHqP8fTDMjqivOjXp9Bg", - "X-Requested-With": "XMLHttpRequest", - "sentry-trace": "5df9278bedb844c7b650fb90ee8cc2fc-b84c9e138292d0e4-1", - "baggage": "sentry-environment=production,sentry-public_key=46062cbe0aeb7a3b2bb4c3a9b8cd1ac7,sentry-trace_id=5df9278bedb844c7b650fb90ee8cc2fc,sentry-sample_rate=0.75,sentry-sampled=true", - "Sec-Fetch-Dest": "empty", - "Sec-Fetch-Mode": "cors", - "Sec-Fetch-Site": "same-origin" - }, - "referrer": "https://ui.adsabs.harvard.edu/search/fq=%7B!type%3Daqp%20v%3D%24fq_database%7D&fq_database=(database%3Aastronomy%20OR%20database%3Aphysics)&p_=0&q=pub%3A%22comptes%20rendus%20physique%22&sort=date%20desc%2C%20bibcode%20desc", - "method": "GET", - "mode": "cors" - }); - """ - response = requests.get(url, params=query_param, headers={"Authorization": "Bearer " + settings.ADS_TOKEN}) - response.raise_for_status() - data = json.loads(response.text) - self._count = data["response"]["numFound"] - self._start += 200 - return data["response"]["docs"] - - def _loadXml(self, basefilename): - index = 1 - print("Basefilename " + basefilename) - filename = basefilename - while os.path.isfile(filename): - print("Filename " + filename) - tree = etree.parse(filename) - self.xml_files.append(XmlFile(filename, tree.getroot())) - filename = basefilename[:-4] - filename = filename + "(" + str(index) + ").xml" - index += 1 - - def _search(self, doi, index): - predicate = str('.//{https://ads.harvard.edu/schema/abs/1.1/jats}article-id[@pub-id-type="doi"][.="' + doi + '"]') - #print("Predicate " + predicate + " root " + str(self.xml_files[index].root)) - article = self.xml_files[index].root.findall(predicate) - return article - - def compare(self, collection_PID): - # self._loadXml("/home/beaufilx/Téléchargements/export-jatsxml.xml") - while self._count >= self._start: - self._result += self._query() - journal = model_helpers.get_collection(collection_PID) - print(journal) - result = model_helpers.get_volumes_in_collection(journal) - print(result) - sorted_issues = result["sorted_issues"] - volumes = sorted_issues[0]['volumes'] - for volume in volumes: - for issue in volume['issues']: - articles = issue.article_set.all().order_by("doi") - for article in articles: - if article.doi[:7] == '10.5802': - #print("------------ Searching " + article.doi + " ----------------") - found = False - end_of_file = False - index = 0 - while not found and not end_of_file: - #print("Search in " + self.xml_files[index].filename) - found = self._search(article.doi, index) - #print("DOI " + str(article.doi) + " " + str(found)) - if index + 1 == len(self.xml_files): - end_of_file = True - if not found: - index += 1 - if not found: - print(article.doi) - - -class XmlFile: - filename: str - root: any + self._journals['CRPHYS'] = Journal("comptes rendus physique", "CRPHYS") + self._journals['CRGEOS'] = Journal("comptes rendus geoscience", "CRGEOS") + self._journals['CRMECA'] = Journal("comptes rendus mecanique", "CRMECA") + + def compare(self, collections): + result = [] + for pid in collections: + journal = self._journals.get(pid, None) + if journal is None: + return None + pub = journal.title() + query = AdsQuery() + present = query.query_referencing(pub) + collection = model_helpers.get_collection(pid) + print(collection) + volumes_collections = model_helpers.get_volumes_in_collection(collection) + print(volumes_collections) + sorted_issues = volumes_collections["sorted_issues"] + volumes = sorted_issues[0]['volumes'] + journal = self._journals.get(pid) + for volume in volumes: + for issue in volume['issues']: + articles = issue.article_set.all().order_by("doi") + for article in articles: + if article.doi[:7] == '10.5802': + found_article = present.get(article.doi, None) + if not found_article: + print(article.doi) + result.append(AdsArticle(article.doi, article.title_html, journal.title())) + return result + + +class Journal: + _title: str + _collection_pid: str + _articles: [] + + def __init__(self, title, collection_pid): + self._title = title + self._collection_pid = collection_pid + + def collection_pid(self) -> str: + return self._collection_pid + + def title(self) -> str: + return self._title + + def articles(self) -> [AdsArticle]: + return self._articles - def __init__(self, filename, root): - self.filename = filename - self.root = root diff --git a/src/ptf_tools/urls.py b/src/ptf_tools/urls.py index 9a98c558..078d7dc0 100644 --- a/src/ptf_tools/urls.py +++ b/src/ptf_tools/urls.py @@ -78,6 +78,8 @@ from ptf_tools.views import ( PTFToolsContainerView, PTFToolsHomeView, PublishedArticlesDashboardView, + ReferencingDashboardView, + ReferencingDashboardExport, RegisterPubmedFormView, RegisterPubmedView, RestoreCMSAPIView, @@ -269,6 +271,16 @@ urlpatterns_staff = [ PublishedArticlesDashboardView.as_view(), name="published_articles", ), + path( + "mersenne_dashboard/referencing/view", + ReferencingDashboardView.as_view(), + name="referencingView", + ), + path( + "mersenne_dashboard/referencing/export", + ReferencingDashboardExport.as_view(), + name="referencingExport", + ), re_path( r"^mersenne_dashboard/created_volumes", CreatedVolumesDashboardView.as_view(), diff --git a/src/ptf_tools/views/base_views.py b/src/ptf_tools/views/base_views.py index f4823aab..7bb48e93 100644 --- a/src/ptf_tools/views/base_views.py +++ b/src/ptf_tools/views/base_views.py @@ -2,6 +2,7 @@ import io import json import os import re +import csv from datetime import datetime from itertools import groupby @@ -66,6 +67,7 @@ from history import models as history_models from history import views as history_views from ptf_tools.doaj import doaj_pid_register from ptf_tools.doi import get_or_create_doibatch, recordDOI +from ptf_tools.indexingChecker import Comparator from ptf_tools.forms import ( BibItemIdForm, CollectionForm, @@ -1552,6 +1554,39 @@ class CreatedVolumesDashboardView(BaseMersenneDashboardView): return data_by_year, total_articles, total_pages +class ReferencingDashboardExport(View): + + def post(self, request, *args, **kwargs): + collections = request.POST.getlist("collections", False) + comp = Comparator() + missings = comp.compare(collections) + response = HttpResponse( + content_type="text/csv", + headers={"Content-Disposition": 'attachment; filename="missings.csv"'}, + ) + writer = csv.writer(response) + writer.writerow(["DOI", "Title", "Pub"]) + for article in missings: + writer.writerow([article.doi(), article.title(), article.pub()]) + return response + + +class ReferencingDashboardView(BaseMersenneDashboardView): + + template_name = "dashboard/referencing.html" + + def post(self, request, *args, **kwargs): + collections = request.POST.getlist("collections", False) + comp = Comparator() + missings = comp.compare(collections) + return render(request, self.template_name, {'missings': missings}) + + + def get_context_data(self, **kwargs): + context = self.get_common_context_data(**kwargs) + + return context + class BaseCollectionView(TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) diff --git a/src/templates/dashboard/referencing.html b/src/templates/dashboard/referencing.html new file mode 100644 index 00000000..88fd582d --- /dev/null +++ b/src/templates/dashboard/referencing.html @@ -0,0 +1,40 @@ +{% extends 'base.html' %} +{% load static %} +{% load i18n %} +{% block content %} + <div class="right_col dashboard" role="main" dashboard="{{ dashboard.pk }}"> + <form method="POST" action="{% url 'referencingView' %}"> + {% csrf_token %} + <input type="checkbox" name="collections" id="CRPHYS" value="CRPHYS"><label for="CRPHYS">Comptes rendus Physique</label> + <input type="checkbox" name="collections" id="CRGEOS" value="CRGEOS"><label for="CRGEOS">Comptes rendus Geoscience</label> + <input type="checkbox" name="collections" id="CRMECA" value="CRMECA"><label for="CRMECA">Comptes rendus Mecanique</label> + <button type="submit" value="view" class="btn btn-default">Reference</button> + <button type="submit" value="export" class="btn btn-default">Reference</button> + </form> + <table id="tbleReference" class="table table-striped table-bordered" style="width:100%"> + <thead> + <tr> + <th>DOI</th> + <th>Title</th> + <th>Publication</th> + </tr> + </thead> + <tbody> + {% for missing in missings %} + <tr> + <td>{{missing.doi}}</td> + <td>{{missing.title}}</td> + <td>{{missing.pub}}</td> + </tr> + {% endfor %} + </tbody> + </table> + </div> +{% endblock content %} +{% block extrajs %} + <script > + var tblRef = $('#tbleReference').DataTable( { + buttons: ['copy', 'excel', 'pdf', 'csv'] + }); + </script> +{% endblock extrajs %} diff --git a/src/templates/top_nav.html b/src/templates/top_nav.html index 88895cba..43d8e9a8 100644 --- a/src/templates/top_nav.html +++ b/src/templates/top_nav.html @@ -27,6 +27,7 @@ <li class="nav-item{% if request.path == "/" %} active{% endif %}"><a href="/">Home</a></li> {% if user.is_staff %} <li class="nav-item"><a href="{% url 'published_articles' %}">Statistics</a></li> + <li class="nav-item"><a href="#" onclick="$('#RefModal').modal('toggle');">Referencing</a></li> {% endif %} {% comment %} Comments moderation. @@ -59,4 +60,29 @@ </div> </div> +<div class="modal fade" id="RefModal" tabindex="-1" role="dialog" aria-labelledby="RefModalLabel"> + <div class="modal-dialog" role="document"> + <div class="modal-content"> + <div class="modal-header"> + <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> + <h4 class="modal-title" id="refModalLabel">Referencing</h4> + </div> + <div class="modal-body"> + <form id="frmReference" method="POST"> <!-- action="{% url 'referencingView' %}"> --> + {% csrf_token %} + <div class="form-group"> + <input type="checkbox" name="collections" id="CRPHYS" value="CRPHYS"><label for="CRPHYS">Comptes rendus Physique</label> + <input type="checkbox" name="collections" id="CRGEOS" value="CRGEOS"><label for="CRGEOS">Comptes rendus Geoscience</label> + <input type="checkbox" name="collections" id="CRMECA" value="CRMECA"><label for="CRMECA">Comptes rendus Mecanique</label> + </div> + </form> + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> + <button type="submit" value="view" form="frmReference" formaction="{% url 'referencingView' %}" class="btn btn-default">View</button> + <button type="submit" value="export" form="frmReference" formaction="{% url 'referencingExport' %}" class="btn btn-default">Download</button> + </div> + </div> + </div> +</div> {% endif %} -- GitLab From 75103734b40181753572abf3c06fb3f003612c49 Mon Sep 17 00:00:00 2001 From: beaufilx <Est1tiam2y@24> Date: Fri, 31 Jan 2025 18:12:14 +0100 Subject: [PATCH 3/6] =?UTF-8?q?AdsQuery=20externalis=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ptf_tools/views/base_views.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/ptf_tools/views/base_views.py b/src/ptf_tools/views/base_views.py index 7bb48e93..65507cc1 100644 --- a/src/ptf_tools/views/base_views.py +++ b/src/ptf_tools/views/base_views.py @@ -1582,11 +1582,6 @@ class ReferencingDashboardView(BaseMersenneDashboardView): return render(request, self.template_name, {'missings': missings}) - def get_context_data(self, **kwargs): - context = self.get_common_context_data(**kwargs) - - return context - class BaseCollectionView(TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) -- GitLab From 7d5d1ac64a96b8e3f311b928fcc63bae8967129a Mon Sep 17 00:00:00 2001 From: beaufilx <Est1tiam2y@24> Date: Tue, 4 Feb 2025 14:29:21 +0100 Subject: [PATCH 4/6] Menu dropDown --- src/ptf_tools/indexingChecker.py | 47 +++++++++---------- .../static/ptf-tools/css/ptf_tools.css | 5 ++ src/ptf_tools/urls.py | 8 +--- src/ptf_tools/views/base_views.py | 24 ++-------- src/templates/dashboard/referencing.html | 20 ++++---- src/templates/top_nav.html | 13 +++-- 6 files changed, 51 insertions(+), 66 deletions(-) diff --git a/src/ptf_tools/indexingChecker.py b/src/ptf_tools/indexingChecker.py index 01509b45..a1efce08 100644 --- a/src/ptf_tools/indexingChecker.py +++ b/src/ptf_tools/indexingChecker.py @@ -10,31 +10,30 @@ class Comparator: self._journals['CRGEOS'] = Journal("comptes rendus geoscience", "CRGEOS") self._journals['CRMECA'] = Journal("comptes rendus mecanique", "CRMECA") - def compare(self, collections): + def compare(self, collect_id): result = [] - for pid in collections: - journal = self._journals.get(pid, None) - if journal is None: - return None - pub = journal.title() - query = AdsQuery() - present = query.query_referencing(pub) - collection = model_helpers.get_collection(pid) - print(collection) - volumes_collections = model_helpers.get_volumes_in_collection(collection) - print(volumes_collections) - sorted_issues = volumes_collections["sorted_issues"] - volumes = sorted_issues[0]['volumes'] - journal = self._journals.get(pid) - for volume in volumes: - for issue in volume['issues']: - articles = issue.article_set.all().order_by("doi") - for article in articles: - if article.doi[:7] == '10.5802': - found_article = present.get(article.doi, None) - if not found_article: - print(article.doi) - result.append(AdsArticle(article.doi, article.title_html, journal.title())) + journal = self._journals.get(collect_id, None) + if journal is None: + return None + pub = journal.title() + query = AdsQuery() + present = query.query_referencing(pub) + collection = model_helpers.get_collection(collect_id) + print(collection) + volumes_collections = model_helpers.get_volumes_in_collection(collection) + print(volumes_collections) + sorted_issues = volumes_collections["sorted_issues"] + volumes = sorted_issues[0]['volumes'] + journal = self._journals.get(collect_id) + for volume in volumes: + for issue in volume['issues']: + articles = issue.article_set.all().order_by("doi") + for article in articles: + if article.doi[:7] == '10.5802': + found_article = present.get(article.doi, None) + if not found_article: + print(article.doi) + result.append(AdsArticle(article.doi, article.title_html, journal.title())) return result diff --git a/src/ptf_tools/static/ptf-tools/css/ptf_tools.css b/src/ptf_tools/static/ptf-tools/css/ptf_tools.css index b9b4652e..eee2c7ed 100644 --- a/src/ptf_tools/static/ptf-tools/css/ptf_tools.css +++ b/src/ptf_tools/static/ptf-tools/css/ptf_tools.css @@ -49,6 +49,11 @@ background-color: #cfd5db; } +li.dropdown .dropdown-menu li { + float: left; + width: 100%; +} + #allauth-template { font-size: 16px; } diff --git a/src/ptf_tools/urls.py b/src/ptf_tools/urls.py index 078d7dc0..ad699278 100644 --- a/src/ptf_tools/urls.py +++ b/src/ptf_tools/urls.py @@ -79,7 +79,6 @@ from ptf_tools.views import ( PTFToolsHomeView, PublishedArticlesDashboardView, ReferencingDashboardView, - ReferencingDashboardExport, RegisterPubmedFormView, RegisterPubmedView, RestoreCMSAPIView, @@ -272,15 +271,10 @@ urlpatterns_staff = [ name="published_articles", ), path( - "mersenne_dashboard/referencing/view", + "mersenne_dashboard/referencing/<path:colid>", ReferencingDashboardView.as_view(), name="referencingView", ), - path( - "mersenne_dashboard/referencing/export", - ReferencingDashboardExport.as_view(), - name="referencingExport", - ), re_path( r"^mersenne_dashboard/created_volumes", CreatedVolumesDashboardView.as_view(), diff --git a/src/ptf_tools/views/base_views.py b/src/ptf_tools/views/base_views.py index 65507cc1..9868a506 100644 --- a/src/ptf_tools/views/base_views.py +++ b/src/ptf_tools/views/base_views.py @@ -1554,31 +1554,13 @@ class CreatedVolumesDashboardView(BaseMersenneDashboardView): return data_by_year, total_articles, total_pages -class ReferencingDashboardExport(View): - - def post(self, request, *args, **kwargs): - collections = request.POST.getlist("collections", False) - comp = Comparator() - missings = comp.compare(collections) - response = HttpResponse( - content_type="text/csv", - headers={"Content-Disposition": 'attachment; filename="missings.csv"'}, - ) - writer = csv.writer(response) - writer.writerow(["DOI", "Title", "Pub"]) - for article in missings: - writer.writerow([article.doi(), article.title(), article.pub()]) - return response - - class ReferencingDashboardView(BaseMersenneDashboardView): - template_name = "dashboard/referencing.html" - def post(self, request, *args, **kwargs): - collections = request.POST.getlist("collections", False) + def get(self, request, *args, **kwargs): + colid = self.kwargs.get("colid", None) comp = Comparator() - missings = comp.compare(collections) + missings = comp.compare(colid) return render(request, self.template_name, {'missings': missings}) diff --git a/src/templates/dashboard/referencing.html b/src/templates/dashboard/referencing.html index 88fd582d..7b8606bc 100644 --- a/src/templates/dashboard/referencing.html +++ b/src/templates/dashboard/referencing.html @@ -3,15 +3,10 @@ {% load i18n %} {% block content %} <div class="right_col dashboard" role="main" dashboard="{{ dashboard.pk }}"> - <form method="POST" action="{% url 'referencingView' %}"> - {% csrf_token %} - <input type="checkbox" name="collections" id="CRPHYS" value="CRPHYS"><label for="CRPHYS">Comptes rendus Physique</label> - <input type="checkbox" name="collections" id="CRGEOS" value="CRGEOS"><label for="CRGEOS">Comptes rendus Geoscience</label> - <input type="checkbox" name="collections" id="CRMECA" value="CRMECA"><label for="CRMECA">Comptes rendus Mecanique</label> - <button type="submit" value="view" class="btn btn-default">Reference</button> - <button type="submit" value="export" class="btn btn-default">Reference</button> - </form> - <table id="tbleReference" class="table table-striped table-bordered" style="width:100%"> + <div class="panel panel-default"> + <div class="panel-heading"> <h3 class="panel-title">Missing articles in ADS</h3></div> + <div class="panel-body"> + <table id="tblReference" class="table table-striped table-bordered" style="width:100%"> <thead> <tr> <th>DOI</th> @@ -29,12 +24,15 @@ {% endfor %} </tbody> </table> + </div> + </div> </div> {% endblock content %} {% block extrajs %} <script > - var tblRef = $('#tbleReference').DataTable( { - buttons: ['copy', 'excel', 'pdf', 'csv'] + var tblRef = $('#tblReference').DataTable( { + dom: 'Bfrtip', // Don't know what it's for + buttons: ['csv'] }); </script> {% endblock extrajs %} diff --git a/src/templates/top_nav.html b/src/templates/top_nav.html index 43d8e9a8..99489d0e 100644 --- a/src/templates/top_nav.html +++ b/src/templates/top_nav.html @@ -27,6 +27,14 @@ <li class="nav-item{% if request.path == "/" %} active{% endif %}"><a href="/">Home</a></li> {% if user.is_staff %} <li class="nav-item"><a href="{% url 'published_articles' %}">Statistics</a></li> + <li class="dropdown"> + <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Referencing <span class="caret"></span></a> + <ul class="dropdown-menu"> + <li><a href="{% url 'referencingView' 'CRPHYS'%}">CR Physique</a></li> + <li><a href="{% url 'referencingView' 'CRGEOS'%}">CR Geoscience</a></li> + <li><a href="{% url 'referencingView' 'CRMECA'%}">CR Mecanique</a></li> + </ul> + </li> <li class="nav-item"><a href="#" onclick="$('#RefModal').modal('toggle');">Referencing</a></li> {% endif %} {% comment %} @@ -68,7 +76,7 @@ <h4 class="modal-title" id="refModalLabel">Referencing</h4> </div> <div class="modal-body"> - <form id="frmReference" method="POST"> <!-- action="{% url 'referencingView' %}"> --> + <form id="frmReference" method="POST"> {% csrf_token %} <div class="form-group"> <input type="checkbox" name="collections" id="CRPHYS" value="CRPHYS"><label for="CRPHYS">Comptes rendus Physique</label> @@ -79,8 +87,7 @@ </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> - <button type="submit" value="view" form="frmReference" formaction="{% url 'referencingView' %}" class="btn btn-default">View</button> - <button type="submit" value="export" form="frmReference" formaction="{% url 'referencingExport' %}" class="btn btn-default">Download</button> + <button type="submit" value="view" form="frmReference" class="btn btn-default">View</button> </div> </div> </div> -- GitLab From 4251edb01850afd19b0bb6c698c37a5055fbd22d Mon Sep 17 00:00:00 2001 From: beaufilx <Est1tiam2y@24> Date: Tue, 4 Feb 2025 15:02:56 +0100 Subject: [PATCH 5/6] Changement nom de classe --- src/ptf_tools/indexingChecker.py | 4 ++-- src/ptf_tools/views/base_views.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ptf_tools/indexingChecker.py b/src/ptf_tools/indexingChecker.py index a1efce08..5976b352 100644 --- a/src/ptf_tools/indexingChecker.py +++ b/src/ptf_tools/indexingChecker.py @@ -2,7 +2,7 @@ from ptf import model_helpers from ptf.external.ads import AdsQuery, AdsArticle -class Comparator: +class ReferencingChecker: _journals = {} def __init__(self): @@ -10,7 +10,7 @@ class Comparator: self._journals['CRGEOS'] = Journal("comptes rendus geoscience", "CRGEOS") self._journals['CRMECA'] = Journal("comptes rendus mecanique", "CRMECA") - def compare(self, collect_id): + def check_references(self, collect_id): result = [] journal = self._journals.get(collect_id, None) if journal is None: diff --git a/src/ptf_tools/views/base_views.py b/src/ptf_tools/views/base_views.py index cd256675..8b124b6a 100644 --- a/src/ptf_tools/views/base_views.py +++ b/src/ptf_tools/views/base_views.py @@ -66,7 +66,7 @@ from history import models as history_models from history import views as history_views from ptf_tools.doaj import doaj_pid_register from ptf_tools.doi import get_or_create_doibatch, recordDOI -from ptf_tools.indexingChecker import Comparator +from ptf_tools.indexingChecker import ReferencingChecker from ptf_tools.forms import ( BibItemIdForm, CollectionForm, @@ -1539,8 +1539,8 @@ class ReferencingDashboardView(BaseMersenneDashboardView): def get(self, request, *args, **kwargs): colid = self.kwargs.get("colid", None) - comp = Comparator() - missings = comp.compare(colid) + comp = ReferencingChecker() + missings = comp.check_references(colid) return render(request, self.template_name, {'missings': missings}) -- GitLab From 58e11ce609d03bededc9746e173af4765d50772e Mon Sep 17 00:00:00 2001 From: beaufilx <Est1tiam2y@24> Date: Thu, 6 Feb 2025 09:24:10 +0100 Subject: [PATCH 6/6] Recherche par ISSN --- src/ptf_tools/indexingChecker.py | 19 ++++++++----------- src/ptf_tools/views/base_views.py | 4 ++-- src/templates/dashboard/referencing.html | 8 ++++---- src/templates/top_nav.html | 1 - 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/ptf_tools/indexingChecker.py b/src/ptf_tools/indexingChecker.py index 5976b352..dcdadd14 100644 --- a/src/ptf_tools/indexingChecker.py +++ b/src/ptf_tools/indexingChecker.py @@ -1,4 +1,5 @@ from ptf import model_helpers +from ptf.models import Article from ptf.external.ads import AdsQuery, AdsArticle @@ -11,15 +12,10 @@ class ReferencingChecker: self._journals['CRMECA'] = Journal("comptes rendus mecanique", "CRMECA") def check_references(self, collect_id): - result = [] - journal = self._journals.get(collect_id, None) - if journal is None: - return None - pub = journal.title() - query = AdsQuery() - present = query.query_referencing(pub) collection = model_helpers.get_collection(collect_id) print(collection) + query = AdsQuery() + present = query.query_referencing(collection.issn) volumes_collections = model_helpers.get_volumes_in_collection(collection) print(volumes_collections) sorted_issues = volumes_collections["sorted_issues"] @@ -33,18 +29,19 @@ class ReferencingChecker: found_article = present.get(article.doi, None) if not found_article: print(article.doi) - result.append(AdsArticle(article.doi, article.title_html, journal.title())) - return result + journal.articles().append(article) + return journal class Journal: _title: str _collection_pid: str - _articles: [] + _articles: [Article] def __init__(self, title, collection_pid): self._title = title self._collection_pid = collection_pid + self._articles = [] def collection_pid(self) -> str: return self._collection_pid @@ -52,6 +49,6 @@ class Journal: def title(self) -> str: return self._title - def articles(self) -> [AdsArticle]: + def articles(self) -> [Article]: return self._articles diff --git a/src/ptf_tools/views/base_views.py b/src/ptf_tools/views/base_views.py index 8b124b6a..50add964 100644 --- a/src/ptf_tools/views/base_views.py +++ b/src/ptf_tools/views/base_views.py @@ -1540,8 +1540,8 @@ class ReferencingDashboardView(BaseMersenneDashboardView): def get(self, request, *args, **kwargs): colid = self.kwargs.get("colid", None) comp = ReferencingChecker() - missings = comp.check_references(colid) - return render(request, self.template_name, {'missings': missings}) + journal = comp.check_references(colid) + return render(request, self.template_name, {'journal': journal}) class BaseCollectionView(TemplateView): diff --git a/src/templates/dashboard/referencing.html b/src/templates/dashboard/referencing.html index 7b8606bc..164794fd 100644 --- a/src/templates/dashboard/referencing.html +++ b/src/templates/dashboard/referencing.html @@ -4,7 +4,7 @@ {% block content %} <div class="right_col dashboard" role="main" dashboard="{{ dashboard.pk }}"> <div class="panel panel-default"> - <div class="panel-heading"> <h3 class="panel-title">Missing articles in ADS</h3></div> + <div class="panel-heading"> <h3 class="panel-title">Missing articles from {{journal.title}} in ADS</h3></div> <div class="panel-body"> <table id="tblReference" class="table table-striped table-bordered" style="width:100%"> <thead> @@ -15,11 +15,11 @@ </tr> </thead> <tbody> - {% for missing in missings %} + {% for missing in journal.articles %} <tr> <td>{{missing.doi}}</td> - <td>{{missing.title}}</td> - <td>{{missing.pub}}</td> + <td>{{missing.title_html}}</td> + <td>{{journal.title}}</td> </tr> {% endfor %} </tbody> diff --git a/src/templates/top_nav.html b/src/templates/top_nav.html index 99489d0e..9540058f 100644 --- a/src/templates/top_nav.html +++ b/src/templates/top_nav.html @@ -35,7 +35,6 @@ <li><a href="{% url 'referencingView' 'CRMECA'%}">CR Mecanique</a></li> </ul> </li> - <li class="nav-item"><a href="#" onclick="$('#RefModal').modal('toggle');">Referencing</a></li> {% endif %} {% comment %} Comments moderation. -- GitLab