Spaces:
Sleeping
Sleeping
Commit
Β·
f4354cc
1
Parent(s):
4293c81
Refactor author detail and home templates for clarity; enhance user experience with author profile link and improve affiliation labeling.
Browse files- core/templates/author/detail.html +1 -1
- core/templates/base.html +2 -2
- core/templates/home.html +8 -0
- core/views.py +33 -2
core/templates/author/detail.html
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
{% block title %}{{ item.name }}{% endblock %}
|
3 |
{% block content %}
|
4 |
<h2>{{ item.name }}</h2>
|
5 |
-
<p><strong>
|
6 |
{% for affiliation in affiliations %}
|
7 |
<a href="https://duckduckgo.com/?q=!ducky+{{ affiliation|urlencode }}" target="_blank"> {{affiliation }}</a>
|
8 |
{% endfor %}
|
|
|
2 |
{% block title %}{{ item.name }}{% endblock %}
|
3 |
{% block content %}
|
4 |
<h2>{{ item.name }}</h2>
|
5 |
+
<p><strong>Related Institutions:</strong>
|
6 |
{% for affiliation in affiliations %}
|
7 |
<a href="https://duckduckgo.com/?q=!ducky+{{ affiliation|urlencode }}" target="_blank"> {{affiliation }}</a>
|
8 |
{% endfor %}
|
core/templates/base.html
CHANGED
@@ -36,11 +36,11 @@
|
|
36 |
<ul class="navbar-nav">
|
37 |
{% if user.is_authenticated %}
|
38 |
<li class="nav-item d-flex align-items-center text-white px-2">
|
39 |
-
|
40 |
</li>
|
41 |
|
42 |
<li class="nav-item">
|
43 |
-
<a class="nav-link" href="{% url 'logout' %}">Logout
|
44 |
</li>
|
45 |
{% else %}
|
46 |
<li class="nav-item">
|
|
|
36 |
<ul class="navbar-nav">
|
37 |
{% if user.is_authenticated %}
|
38 |
<li class="nav-item d-flex align-items-center text-white px-2">
|
39 |
+
Logged in as:<a href="#" class="nav-link d-inline px-1">{{ user.first_name }}</a>
|
40 |
</li>
|
41 |
|
42 |
<li class="nav-item">
|
43 |
+
<a class="nav-link" href="{% url 'logout' %}">Logout?</a>
|
44 |
</li>
|
45 |
{% else %}
|
46 |
<li class="nav-item">
|
core/templates/home.html
CHANGED
@@ -5,6 +5,14 @@
|
|
5 |
|
6 |
{% block content %}
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
<h2>Search Domains</h2>
|
9 |
<input type="text" id="search-input" placeholder="Type something..." autocomplete="off" />
|
10 |
<ul id="results-list"></ul>
|
|
|
5 |
|
6 |
{% block content %}
|
7 |
|
8 |
+
<h2>Welcome, {{ user.first_name }}!
|
9 |
+
{% if author %}
|
10 |
+
<a href="{% url 'author_detail' author.id %}" class="btn btn-primary">π§βπ¬ View Your Research Profile</a>
|
11 |
+
{% else %}
|
12 |
+
</h2>
|
13 |
+
{# <p>No matching author found for your profile.</p> #}
|
14 |
+
{% endif %}
|
15 |
+
<hr>
|
16 |
<h2>Search Domains</h2>
|
17 |
<input type="text" id="search-input" placeholder="Type something..." autocomplete="off" />
|
18 |
<ul id="results-list"></ul>
|
core/views.py
CHANGED
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
1 |
from django.shortcuts import render, get_object_or_404
|
2 |
# Import Author model
|
3 |
from .models import Domain, Field, Subfield, Topic, AuthorTopic, Author, Institution
|
@@ -5,13 +8,41 @@ from django.http import JsonResponse, HttpResponse
|
|
5 |
from django.db.models import Q
|
6 |
from django.core.management import call_command
|
7 |
from io import StringIO
|
|
|
|
|
8 |
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
|
12 |
def home_page(request):
|
13 |
if request.user.is_authenticated:
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
else:
|
16 |
return render(request, "must_login.html")
|
17 |
|
|
|
1 |
+
from BridgeMentor.utils import refresh_author_db
|
2 |
+
from django.db import transaction
|
3 |
+
from django.core.cache import cache
|
4 |
from django.shortcuts import render, get_object_or_404
|
5 |
# Import Author model
|
6 |
from .models import Domain, Field, Subfield, Topic, AuthorTopic, Author, Institution
|
|
|
8 |
from django.db.models import Q
|
9 |
from django.core.management import call_command
|
10 |
from io import StringIO
|
11 |
+
from difflib import get_close_matches
|
12 |
+
import unicodedata
|
13 |
|
14 |
+
|
15 |
+
def unaccent(text):
|
16 |
+
return ''.join(
|
17 |
+
c for c in unicodedata.normalize('NFKD', text)
|
18 |
+
if not unicodedata.combining(c)
|
19 |
+
)
|
20 |
+
|
21 |
+
|
22 |
+
with transaction.atomic():
|
23 |
+
author_data = cache.get('author_data')
|
24 |
+
if not author_data:
|
25 |
+
author_dict = {
|
26 |
+
unaccent(author.name.lower()): author for author in Author.objects.all()}
|
27 |
+
author_names = list(author_dict.keys())
|
28 |
+
cache.set('author_data', {'dict': author_dict,
|
29 |
+
'names': author_names}, timeout=None)
|
30 |
+
else:
|
31 |
+
author_dict, author_names = author_data['dict'], author_data['names']
|
32 |
|
33 |
|
34 |
def home_page(request):
|
35 |
if request.user.is_authenticated:
|
36 |
+
user_full_name = f"{request.user.first_name} {request.user.last_name}"
|
37 |
+
search_ascii = unaccent(user_full_name.lower())
|
38 |
+
best_match = get_close_matches(
|
39 |
+
search_ascii, author_names, n=5, cutoff=0.8)
|
40 |
+
print(f"Best match: {best_match}")
|
41 |
+
matched_author = None
|
42 |
+
if best_match:
|
43 |
+
matched_author = max(
|
44 |
+
(author_dict[name] for name in best_match), key=lambda a: a.cited_by_count)
|
45 |
+
return render(request, 'home.html', {"user": request.user, "author": matched_author})
|
46 |
else:
|
47 |
return render(request, "must_login.html")
|
48 |
|