Skip to content

Commit

Permalink
add token list and token detail
Browse files Browse the repository at this point in the history
  • Loading branch information
quillcraftsman committed Nov 5, 2023
1 parent 48f3469 commit a624984
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 15 deletions.
51 changes: 51 additions & 0 deletions analysis/templates/analysis/text_token.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{% extends "base.html" %}
{% block main %}
{% with object as text %}
<table class="table border">
<tr>
<th>Name</th>
<th>Value</th>
</tr>
<tr>
<td>
<b>Text</b>
</td>
<td>
{{text.text}}
</td>
</tr>
<tr>
<td>
<b>Language</b>
</td>
<td>
{{text.language}}
</td>
</tr>
<tr>
<td>
<b>Remove Stop Words</b>
</td>
<td>
{{text.remove_stopwords}}
</td>
</tr>
</table>
{% endwith %}
{% endblock %}
{% block results %}

{% with object.token_set.all as items %}
<table class="table table-striped">
<tr>
<th>text</th>
</tr>
{% for item in items %}
<tr>
<td>{{item.value}}</td>
</tr>
{% endfor %}
</table>

{% endwith %}
{% endblock %}
38 changes: 38 additions & 0 deletions analysis/templates/analysis/text_token_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% extends "base.html" %}
{% block main %}
<h2>Text token list</h2>
{% endblock %}
{% block results %}
<table class="table">
<tr>
<th>Text</th>
<th>Language</th>
<th>Remove Stop Words</th>
<th>Created</th>
<th>Has Tokens</th>
<th>Detail</th>
</tr>
{% for text in object_list %}
<tr>
<td>
<a href="{% url 'analysis:text_token' pk=text.pk %}">
{{text.text}}
</a>
</td>
<td>{{text.language}}</td>
<td>{{text.remove_stopwords}}</td>
<td>
{{text.create}}
</td>
<td>
{{text.has_tokens}}
</td>
<td>
<a class="btn btn-info" href="{% url 'analysis:text_token' pk=text.pk %}">
Detail
</a>
</td>
</tr>
{% endfor %}
</table>
{% endblock %}
14 changes: 13 additions & 1 deletion analysis/tests/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from django.test import SimpleTestCase, TestCase
from django.urls import reverse
from django_find_similar.models import CheckResult
from django_find_similar.models import CheckResult, TextToken
from mixer.backend.django import mixer

from analysis.tests.data import get_2x2_training_data
Expand Down Expand Up @@ -44,6 +44,10 @@ def test_reverse(self):
'url': 'result_list',
'reverse': 'result-list/',
},
{
'url': 'text_token_list',
'reverse': 'text-token-list/',
},
]
for url in urls:
app_url = f'{app_name}:{url["url"]}'
Expand All @@ -65,6 +69,7 @@ def test_reverse(self):

training_data = get_2x2_training_data()
check_result = mixer.blend(CheckResult)
text_token = mixer.blend(TextToken)

app_name = 'analysis'
urls = [
Expand Down Expand Up @@ -96,6 +101,13 @@ def test_reverse(self):
},
'reverse': f'result/{check_result.pk}/',
},
{
'url': 'text_token',
'kwargs': {
'pk': text_token.pk
},
'reverse': f'text-token/{text_token.pk}/',
},
]
for url in urls:
app_url = f'{app_name}:{url["url"]}'
Expand Down
48 changes: 47 additions & 1 deletion analysis/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from django.core.files.uploadedfile import SimpleUploadedFile
from django.urls import reverse
from django_find_similar.models import CheckResult
from django_find_similar.models import CheckResult, TextToken
from dry_tests import (
TestCase,
SimpleTestCase,
Expand Down Expand Up @@ -566,3 +566,49 @@ def test_get(self):

current_response = request.get_response(self.client)
self.assertTrueResponse(current_response, true_response)


class TestTextTokenListView(TestCase):

def setUp(self):
self.url = reverse('analysis:text_token_list')

def test_get(self):
request = Request(
url=self.url,
)

true_response = TrueResponse(
status_code=200,
context=Context(
keys=['object_list']
)
)

current_response = request.get_response(self.client)

self.assertTrueResponse(current_response, true_response)


class TestTextTokenDetailView(TestCase):

def setUp(self):
self.text_token = mixer.blend(TextToken)
self.url = reverse('analysis:text_token', kwargs={'pk': self.text_token.pk})

def test_get(self):
request = Request(
url=self.url,
)

true_response = TrueResponse(
status_code=200,
context=Context(
items={
'object': self.text_token,
}
)
)

current_response = request.get_response(self.client)
self.assertTrueResponse(current_response, true_response)
2 changes: 2 additions & 0 deletions analysis/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
path('training-data-list/', views.TrainingDataListView.as_view(), name="training_data_list"),
path('result-list/', views.ResultListView.as_view(), name="result_list"),
path('result/<int:pk>/', views.ResultDetailView.as_view(), name="result"),
path('text-token-list/', views.TextTokenListView.as_view(), name="text_token_list"),
path('text-token/<int:pk>/', views.TextTokenDetailView.as_view(), name="text_token"),
]
11 changes: 11 additions & 0 deletions analysis/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,14 @@ class ResultListView(ListView):
class ResultDetailView(DetailView):
model = CheckResult
template_name = 'analysis/result.html'


class TextTokenListView(ListView):
model = TextToken
template_name = 'analysis/text_token_list.html'
ordering = ['-create']


class TextTokenDetailView(DetailView):
model = TextToken
template_name = 'analysis/text_token.html'
Binary file removed checklistexample.png
Binary file not shown.
60 changes: 47 additions & 13 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
<nav id="sidebarMenu" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
<div class="position-sticky pt-3">
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">
<span data-feather="home"></span>
Analysis
</a>
</li>
<h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
<span>Analysis</span>
<a class="link-secondary" href="#" aria-label="Add a new report">
<span data-feather="plus-circle"></span>
</a>
</h6>
<li class="nav-item">
<a class="nav-link" href="{% url 'analysis:tokenize_one' %}">
<span data-feather="file"></span>
Expand All @@ -74,7 +74,30 @@
Example frequency
</a>
</li>
<li class="nav-item">
</ul>

<h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
<span>Results</span>
<a class="link-secondary" href="#" aria-label="Add a new report">
<span data-feather="plus-circle"></span>
</a>
</h6>
<ul class="nav flex-column mb-2">
<li class="nav-item">
<a class="nav-link" href="{% url 'analysis:result_list' %}">
<span data-feather="file-text"></span>
Result List
</a>
</li>
</ul>
<h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
<span>Training data</span>
<a class="link-secondary" href="#" aria-label="Add a new report">
<span data-feather="plus-circle"></span>
</a>
</h6>
<ul class="nav flex-column mb-2">
<li class="nav-item">
<a class="nav-link" href="{% url 'analysis:load_training_data' %}">
<span data-feather="file"></span>
Load Training Data
Expand All @@ -86,19 +109,30 @@
Training Data List
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'analysis:text_token_list' %}">
<span data-feather="file"></span>
TextToken List
</a>
</li>
</ul>

<h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
<span>Saved reports</span>
<h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
<span>Admin</span>
<a class="link-secondary" href="#" aria-label="Add a new report">
<span data-feather="plus-circle"></span>
</a>
</h6>
<ul class="nav flex-column mb-2">
<li class="nav-item">
<a class="nav-link" href="{% url 'analysis:result_list' %}">
<span data-feather="file-text"></span>
Result List
<a class="nav-link" href="{% url 'analysis:load_training_data' %}">
<span data-feather="file"></span>
Admin page
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'analysis:training_data_list' %}">
<span data-feather="file"></span>
Create Superuser
</a>
</li>
</ul>
Expand Down

0 comments on commit a624984

Please sign in to comment.