diff --git a/argocd/deployment.yaml b/argocd/deployment.yaml
index 5c7896f..4867ea6 100644
--- a/argocd/deployment.yaml
+++ b/argocd/deployment.yaml
@@ -18,7 +18,7 @@ spec:
fsGroupChangePolicy: "OnRootMismatch"
initContainers:
- name: loader
- image: git.baumann.gr/adebaumann/labhelper-data-loader:0.013
+ image: git.baumann.gr/adebaumann/labhelper-data-loader:0.014
securityContext:
runAsUser: 0
command: [ "sh","-c","if [ ! -f /data/db.sqlite3 ] || [ ! -s /data/db.sqlite3 ]; then cp preload/preload.sqlite3 /data/db.sqlite3 && echo 'Database copied from preload'; else echo 'Existing database preserved'; fi" ]
@@ -27,7 +27,7 @@ spec:
mountPath: /data
containers:
- name: web
- image: git.baumann.gr/adebaumann/labhelper:0.048
+ image: git.baumann.gr/adebaumann/labhelper:0.049
imagePullPolicy: Always
ports:
- containerPort: 8000
diff --git a/boxes/templates/boxes/box_detail.html b/boxes/templates/boxes/box_detail.html
index d0095e2..d55d41e 100644
--- a/boxes/templates/boxes/box_detail.html
+++ b/boxes/templates/boxes/box_detail.html
@@ -37,6 +37,7 @@
| Picture |
Name |
+ Tags |
Description |
@@ -55,6 +56,15 @@
{{ thing.name }}
|
+
+ {% if thing.tags.all %}
+ {% for tag in thing.tags.all %}
+ {{ tag.name }}
+ {% endfor %}
+ {% else %}
+ -
+ {% endif %}
+ |
{{ thing.description|default:"-" }} |
{% endfor %}
diff --git a/boxes/templates/boxes/search.html b/boxes/templates/boxes/search.html
index e0b66c4..b831c53 100644
--- a/boxes/templates/boxes/search.html
+++ b/boxes/templates/boxes/search.html
@@ -29,7 +29,7 @@
| Name |
- Type |
+ Tags |
Box |
Description |
@@ -85,9 +85,16 @@ function performSearch(query) {
const row = document.createElement('tr');
row.style.borderBottom = '1px solid #e0e0e0';
row.style.transition = 'background 0.2s';
+
+ let tagsHtml = thing.tags.length > 0
+ ? thing.tags.map(tag =>
+ '' + escapeHtml(tag.name) + ''
+ ).join('')
+ : '-';
+
row.innerHTML =
'' + escapeHtml(thing.name) + ' | ' +
- '' + escapeHtml(thing.type) + ' | ' +
+ '' + tagsHtml + ' | ' +
'' + escapeHtml(thing.box) + ' | ' +
'' + escapeHtml(thing.description) + ' | ';
diff --git a/boxes/tests.py b/boxes/tests.py
index 8b1b255..7c32a3b 100644
--- a/boxes/tests.py
+++ b/boxes/tests.py
@@ -706,12 +706,12 @@ class SearchApiTests(AuthTestCase):
results = response.json()['results']
self.assertEqual(len(results), 50)
- def test_search_api_includes_type_and_box(self):
- """Search API results should include type and box info."""
+ def test_search_api_includes_tags_and_box(self):
+ """Search API results should include tags and box info."""
response = self.client.get('/search/api/?q=ard')
self.assertEqual(response.status_code, 200)
results = response.json()['results']
- self.assertEqual(results[0]['type'], 'Electronics')
+ self.assertEqual(results[0]['tags'], [])
self.assertEqual(results[0]['box'], 'BOX001')
def test_search_api_requires_login(self):
diff --git a/boxes/views.py b/boxes/views.py
index b283a25..3f2a682 100644
--- a/boxes/views.py
+++ b/boxes/views.py
@@ -40,7 +40,7 @@ def index(request):
def box_detail(request, box_id):
"""Display contents of a box."""
box = get_object_or_404(Box, pk=box_id)
- things = box.things.all()
+ things = box.things.prefetch_related('tags').all()
return render(request, 'boxes/box_detail.html', {
'box': box,
'things': things,
@@ -179,7 +179,7 @@ def search_api(request):
things = Thing.objects.filter(
Q(tags__facet__name__icontains=facet_name) &
Q(tags__name__icontains=tag_name)
- ).prefetch_related('files', 'links').select_related('box').distinct()[:50]
+ ).prefetch_related('files', 'links', 'tags').select_related('box').distinct()[:50]
else:
# Normal search
things = Thing.objects.filter(
@@ -191,7 +191,7 @@ def search_api(request):
Q(links__url__icontains=query) |
Q(tags__name__icontains=query) |
Q(tags__facet__name__icontains=query)
- ).prefetch_related('files', 'links').select_related('box').distinct()[:50]
+ ).prefetch_related('files', 'links', 'tags').select_related('box').distinct()[:50]
results = [
{
@@ -199,6 +199,13 @@ def search_api(request):
'name': thing.name,
'box': thing.box.id,
'description': thing.description[:100] if thing.description else '',
+ 'tags': [
+ {
+ 'name': tag.name,
+ 'color': tag.facet.color,
+ }
+ for tag in thing.tags.all()
+ ],
'files': [
{
'title': f.title,
diff --git a/data-loader/preload.sqlite3 b/data-loader/preload.sqlite3
index 12b932d..cd70261 100644
Binary files a/data-loader/preload.sqlite3 and b/data-loader/preload.sqlite3 differ
diff --git a/labhelper/urls.py b/labhelper/urls.py
index e420228..09838e3 100644
--- a/labhelper/urls.py
+++ b/labhelper/urls.py
@@ -22,11 +22,14 @@ from django.contrib.auth import views as auth_views
from boxes.views import (
add_box,
+ add_box_type,
add_things,
box_detail,
box_management,
delete_box,
+ delete_box_type,
edit_box,
+ edit_box_type,
index,
search,
search_api,
@@ -38,6 +41,9 @@ urlpatterns = [
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
path('', index, name='index'),
path('box-management/', box_management, name='box_management'),
+ path('box-type/add/', add_box_type, name='add_box_type'),
+ path('box-type//edit/', edit_box_type, name='edit_box_type'),
+ path('box-type//delete/', delete_box_type, name='delete_box_type'),
path('box/add/', add_box, name='add_box'),
path('box//edit/', edit_box, name='edit_box'),
path('box//delete/', delete_box, name='delete_box'),