FIXME created for quick tagging
All checks were successful
Build containers when image tags change / build-if-image-changed (data-loader, loader, initContainers, init-container, git.baumann.gr/adebaumann/labhelper-data-loader) (push) Successful in 3s
Build containers when image tags change / build-if-image-changed (., web, containers, main container, git.baumann.gr/adebaumann/labhelper) (push) Successful in 4s
All checks were successful
Build containers when image tags change / build-if-image-changed (data-loader, loader, initContainers, init-container, git.baumann.gr/adebaumann/labhelper-data-loader) (push) Successful in 3s
Build containers when image tags change / build-if-image-changed (., web, containers, main container, git.baumann.gr/adebaumann/labhelper) (push) Successful in 4s
This commit is contained in:
@@ -2,7 +2,7 @@ import bleach
|
||||
import markdown
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db.models import Q
|
||||
from django.db.models import Q, Prefetch
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
|
||||
@@ -402,3 +402,49 @@ def resources_list(request):
|
||||
return render(request, 'boxes/resources_list.html', {
|
||||
'resources': resources,
|
||||
})
|
||||
|
||||
|
||||
@login_required
|
||||
def fixme(request):
|
||||
"""Page to find and fix things missing tags for specific facets."""
|
||||
facets = Facet.objects.all().prefetch_related('tags')
|
||||
|
||||
selected_facet = None
|
||||
missing_things = []
|
||||
|
||||
if request.method == 'GET' and 'facet_id' in request.GET:
|
||||
try:
|
||||
selected_facet = Facet.objects.get(pk=request.GET['facet_id'])
|
||||
# Find things that don't have any tag from this facet
|
||||
missing_things = Thing.objects.exclude(
|
||||
tags__facet=selected_facet
|
||||
).select_related('box', 'box__box_type').prefetch_related('tags')
|
||||
except Facet.DoesNotExist:
|
||||
selected_facet = None
|
||||
|
||||
elif request.method == 'POST':
|
||||
facet_id = request.POST.get('facet_id')
|
||||
tag_ids = request.POST.getlist('tag_ids')
|
||||
thing_ids = request.POST.getlist('thing_ids')
|
||||
|
||||
if facet_id and tag_ids and thing_ids:
|
||||
facet = get_object_or_404(Facet, pk=facet_id)
|
||||
tags = Tag.objects.filter(id__in=tag_ids, facet=facet)
|
||||
things = Thing.objects.filter(id__in=thing_ids)
|
||||
|
||||
for thing in things:
|
||||
if facet.cardinality == Facet.Cardinality.SINGLE:
|
||||
# Remove existing tags from this facet
|
||||
thing.tags.remove(*thing.tags.filter(facet=facet))
|
||||
# Add new tags
|
||||
for tag in tags:
|
||||
if tag.facet == facet:
|
||||
thing.tags.add(tag)
|
||||
|
||||
return redirect('fixme')
|
||||
|
||||
return render(request, 'boxes/fixme.html', {
|
||||
'facets': facets,
|
||||
'selected_facet': selected_facet,
|
||||
'missing_things': missing_things,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user