Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/basic article search #71

Merged
merged 17 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Project/Wikode/Wikode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
'django.contrib.postgres',
'wikodeApp',
'crispy_forms',
'tsvector_field',
'django_tables2',
'dal',
'dal_select2',
'coverage',
]

MIDDLEWARE = [
Expand Down
3 changes: 2 additions & 1 deletion Project/Wikode/Wikode/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
"""
from django.contrib import admin
from django.urls import path, include
from wikodeApp.views import homePage, userLogout
from wikodeApp.views import homePage, userLogout, TagAutocomplete

urlpatterns = [
path('', homePage, name='home'),
path('wikode/', include('wikodeApp.urls')),
path('admin/', admin.site.urls),
path('logout/', userLogout, name='logout'),
path('tag-autocomplete/', TagAutocomplete.as_view(), name='tag-autocomplete'),
]
135 changes: 135 additions & 0 deletions Project/Wikode/templates/wikodeApp/articleDetail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{% extends 'wikodeApp/base.html' %}
{% load static %}

{% block body_block %}
{% load crispy_forms_tags %}
<div class="container py-4">

<div class="p-5 mb-4 bg-light border rounded-3 ">
<h3>{{ title }}</h3>
<p><span class="fw-bold">Authors: </span>
{% for item in authors %}
{% if forloop.last %}
{{ item.ForeName }} {{ item.LastName }}
{% else %}
{{ item.ForeName }} {{ item.LastName }},
{% endif %}
{% endfor %}
</p>
<div class="container">
<div class="row">
<div class="col">PMID: <a href="https://pubmed.ncbi.nlm.nih.gov/{{ pmid }}">{{ pmid }}</a></div>
</div>
</div>
<hr>
<p class="fw-bold">Abstract</p>
<p>{{ abstract }}</p>
<p class="fw-bold">Keywords</p>
<p>{{ keywords }}</p>
<hr>
<p class="fw-bold">Tags</p>
<table class="table table-striped">
<tr>
<th>ID</th>
<th>Q code</th>
<th>System Name</th>
<th>Label</th>
<th>Description</th>
<th>Remove</th>

</tr>
{% for item in tags %}
<tr>
<td><a href="{% url 'wikodeApp:articleDetail' item.id %}">{{ item.id }}</a></td>
<td><a href="https://www.wikidata.org/wiki/{{ item.WikiID }}">{{ item.WikiID }}</a></td>
<td>{{ item.TagName }}</td>
<td>{{ item.Label }}</td>
<td>{{ item.Description }}</td>
<td>
<form method="POST">
{% csrf_token %}
<input type="hidden" value="{{ item.id }}" name="tag_id">
<button class="confirm_action" type="Submit">X</button>
</form>
</td>
</tr>
{% endfor %}
</table>
<hr>
<div class="container-fluid py-4">
<form class="tagForm" method="post">
{% csrf_token %}
{{ tag_form|crispy }}
<div id="searchHelp" class="form-text">Search for wikidata entry using labels or Q codes</div>
<input class="register-button" type="submit" name="get_tag" value="Get Tag">

</form>
<hr>
{% if qid %}
{# Placeholder for Existing tags list#}
{# {% if existing_tags %}#}
{# <p>Click on an existing tag to use it.</p>#}
{# <table class="table table-striped">#}
{# <tr>#}
{# <th>Existing Tags</th>#}
{# </tr>#}
{# {% for item in existing_tags %}#}
{# <tr>#}
{# <td class="tag_name">{{ item.TagName }}</td>#}
{# </tr>#}
{# {% endfor %}#}
{# </table>#}
{# {% endif %}#}
<div class="container-fluid">
<form method="post">
{% csrf_token %}
<label for="tag_name">Tag Name:</label>
<input id="tag_name" type="text" name="tag_name" required>
<p></p>
<label for="qid">Entry ID:</label>
<input type="text" name="qid" value="{{ qid }}" readonly>
<p></p>
<label for="label">Label:</label>
<textarea type="text" name="label" cols="80" rows="1" readonly>{{ label }}</textarea>
<p></p>
<label for="description">Description:</label>
<textarea type="text" name="description" cols="80" rows="5"
readonly>{{ description }}</textarea>
<p></p>
<div id="searchHelp" class="form-text">Save and add tag</div>
<input class="register-button" type="submit" name="add_tag" value="Add Tag">

</form>
</div>

{% endif %}
</div>

<script type="text/javascript" src="{% static 'admin/js/vendor/jquery/jquery.js' %}"></script>

{{ tag_form.media }}

<script>
(function ($) {
$('#add-form').click(function () {
var index = $('#id_inline_test_models-TOTAL_FORMS').val()
var newTable = $('#id_inline_test_models-__prefix__-DELETE').parents('table').clone()
newTable.find(':input').each(function () {
for (attr of ['name', 'id'])
$(this).attr(
attr,
$(this).attr(attr).replace('__prefix__', index)
)
})
newTable.insertBefore($(this))
$('#id_inline_test_models-TOTAL_FORMS').val(
parseInt($('#id_inline_test_models-TOTAL_FORMS').val()) + 1
)
newTable.slideDown()
})
})($)
</script>
</div>
</div>

{% endblock %}
28 changes: 10 additions & 18 deletions Project/Wikode/templates/wikodeApp/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf"
crossorigin="anonymous"></script>

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css">


<!-- JQuery-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

Expand All @@ -33,6 +32,7 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.css"
integrity="sha256-aa0xaJgmK/X74WM224KMQeNQC2xYKwlAt08oZqjeF0E=" crossorigin="anonymous"/>


<!--Font Awesome library-->
<script src="https://kit.fontawesome.com/f405fd37c0.js" crossorigin="anonymous"></script>

Expand Down Expand Up @@ -60,21 +60,14 @@
<li>
<a class="nav-link" href="{% url 'logout' %}">Logout</a>
</li>
{% if user.is_superuser %}
<li>
<a class="nav-link" href="{% url 'wikodeApp:userList' %}">Users</a>
</li>
<li>
<a class="nav-link" href="{% url 'wikodeApp:getArticles' %}">Get Articles</a>
</li>
{% endif %}
{# Placeholder for upcoming page links #}
{# <li>#}
{# <a class="nav-link" href="{% url 'wikodeApp:userProfile' %}">Profile</a>#}
{# </li>#}
{# <li>#}
{# <a class="nav-link" href="{% url 'wikodeApp:tag_list' %}">Tags</a>#}
{# </li>#}
{% if user.is_superuser %}
<li>
<a class="nav-link" href="{% url 'wikodeApp:userList' %}">Users</a>
</li>
<li>
<a class="nav-link" href="{% url 'wikodeApp:getArticles' %}">Get Articles</a>
</li>
{% endif %}
{% else %}
<li>
<a class="nav-link" href="{% url 'wikodeApp:userLogin' %}">Login</a>
Expand All @@ -97,7 +90,6 @@
</div>
</footer>

{# scipts to be used for tagging and grids#}
<script src="{% static 'wikodeApp/js/bootstrap-tagsinput.js' %}"></script>
<script src="{% static 'wikodeApp/js/index.js' %}"></script>
</body>
Expand Down
78 changes: 78 additions & 0 deletions Project/Wikode/templates/wikodeApp/searchResults.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{% extends 'wikodeApp/base.html' %}
{% load static %}

{% block body_block %}

{% if date_labels %}
<div class="container">
<canvas id="myChart" width="100" height="30"></canvas>
</div>
{% endif %}
<div class="container">
<h3 class="lead">Search Results</h3>
<table class="table table-striped">
<tr>
<th>PMID</th>
<th>Title</th>
<th>Date</th>
</tr>
{% for item in results_list %}
<tr>
<td><a href="{% url 'wikodeApp:articleDetail' item.id %}">{{ item.id }}</a></td>
<td>{{ item.Title }}</td>
<td>{{ item.PublicationDate }}</td>
</tr>
{% endfor %}
</table>
{% if results_list.has_other_pages %}
<ul class="pagination">
{% if results_list.has_previous %}
<li class="page-item"><a class="page-link"
href="?page={{ results_list.previous_page_number }}&term={{ search_term }}">&laquo;</a>
</li>
{% else %}
<li class="disabled page-item"><span class="page-link">&laquo;</span></li>
{% endif %}
{% for i in results_list.paginator.page_range %}
{% if results_list.number == i %}
<li class="active page-item"><span class="page-link">{{ i }} <span
class="sr-only">(current)</span></span></li>
{% else %}
<li class="page-item"><a class="page-link"
href="?page={{ i }}&term={{ search_term }}">{{ i }}</a></li>
{% endif %}
{% endfor %}
{% if results_list.has_next %}
<li class="page-item"><a class="page-link"
href="?page={{ results_list.next_page_number }}&term={{ search_term }}">&raquo;</a>
</li>
{% else %}
<li class="disabled page-item"><span class="page-link">&raquo;</span></li>
{% endif %}
</ul>
{% endif %}
</div>
{% if date_labels %}
<script>
var ctx2 = document.getElementById('myChart');
var myChart = new Chart(ctx2, {
type: 'bar',
data: {
labels: [{% for item in date_labels %}'{{ item }}',{% endfor %}],
datasets: [{
label: '# of Articles',
data: [{% for item in data_values %}'{{ item }}',{% endfor %}],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
</script>
{% endif %}
{% endblock %}
8 changes: 8 additions & 0 deletions Project/Wikode/wikodeApp/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django import forms
from wikodeApp.models import RegistrationApplication
from dal import autocomplete


class ApplicationRegistrationForm(forms.ModelForm):
Expand All @@ -12,3 +13,10 @@ class Meta:
class GetArticleForm(forms.Form):
article_topic = forms.CharField(label='Topic', max_length=100)
volume = forms.CharField(label='# of Articles', max_length=100)


class TagForm(forms.Form):
wikiLabel = autocomplete.Select2ListChoiceField(
widget=autocomplete.ListSelect2(url='tag-autocomplete'),
label="Search Wikidata Entry"
)
8 changes: 1 addition & 7 deletions Project/Wikode/wikodeApp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class RegistrationApplication(models.Model):


class UserProfileInfo(models.Model):

user = models.OneToOneField(User, on_delete=models.CASCADE)
registrationApplication = models.ForeignKey(RegistrationApplication, on_delete=models.CASCADE)

Expand All @@ -29,7 +28,6 @@ def __str__(self):


class Journal(models.Model):

ISSN = models.CharField(max_length=16)
Title = models.CharField(max_length=256)
ISOAbbreviation = models.CharField(max_length=256)
Expand All @@ -39,7 +37,6 @@ def __str__(self):


class Author(models.Model):

LastName = models.CharField(max_length=128)
ForeName = models.CharField(max_length=128, null=True)
Initials = models.CharField(max_length=32)
Expand All @@ -49,15 +46,13 @@ def __str__(self):


class Keyword(models.Model):

KeywordText = models.TextField(max_length=64)

def __str__(self):
return self.KeywordText


class Article(models.Model):

PMID = models.CharField(max_length=16)
Title = models.TextField(max_length=512)
Abstract = models.TextField(max_length=5000, null=True)
Expand All @@ -68,7 +63,6 @@ class Article(models.Model):
Authors = models.ManyToManyField(Author)

Tokens = models.TextField(max_length=100000)

SearchIndex = SearchVectorField(null=True)

def createTSvector(self, *args, **kwargs):
Expand All @@ -81,4 +75,4 @@ def createTSvector(self, *args, **kwargs):
super().save(*args, **kwargs)

def __str__(self):
return self.Title
return self.Title
Loading