Skip to content

Commit

Permalink
adds taxonomy topics ui
Browse files Browse the repository at this point in the history
  • Loading branch information
actlikewill committed Jul 26, 2023
1 parent 68c1659 commit c3e747c
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 32 deletions.
4 changes: 0 additions & 4 deletions indigo/bulk_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,10 +937,6 @@ def link_taxonomy(self, row, model=VocabularyTopic, attr='taxonomies', attr_sing
except Task.DoesNotExist:
self.create_task(row.work, row, task_type='link-taxonomy')





def preview_task(self, row, task_type):
task_preview = task_type.replace('-', ' ')
if task_type == 'import-content':
Expand Down
21 changes: 21 additions & 0 deletions indigo_api/models/works.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from reversion.models import Version
from cobalt import FrbrUri, RepealEvent
from treebeard.mp_tree import MP_Node
from django.urls import reverse
from django.http import QueryDict

from indigo.plugins import plugins

Expand Down Expand Up @@ -117,6 +119,25 @@ def save(self, *args, **kwargs):
self.slug = (f"{parent.slug}-" if parent else "") + slugify(self.name)
super().save(*args, **kwargs)

@classmethod
def get_toc_tree(cls, query_dict):
# capture all preserve all filter parameters and add taxonomy_topic
new_query = query_dict.copy()
new_query.pop('taxonomy_topic', None)

def fix_up(item):
item["title"] = item["data"]["name"]
new_query.update({'taxonomy_topic': item['data']['slug']})
item["href"] = f"?{new_query.urlencode()}"
new_query.pop('taxonomy_topic', None)
for kid in item.get("children", []):
fix_up(kid)

tree = cls.dump_bulk()
for x in tree:
fix_up(x)
return tree


class WorkMixin(object):
""" Support methods that define behaviour for a work, independent of the database model.
Expand Down
5 changes: 0 additions & 5 deletions indigo_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,11 +635,6 @@ def get_taxonomy_topics(self, instance):
"name": t.name,
"slug": t.slug
})
for ancestor in t.get_ancestors():
taxonomies.append({
"name": ancestor.name,
"slug": ancestor.slug
})
return taxonomies


Expand Down
14 changes: 14 additions & 0 deletions indigo_app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ class TaskFilterForm(forms.Form):
submitted_by = forms.ModelMultipleChoiceField(queryset=User.objects)
type = forms.MultipleChoiceField(choices=Task.CODES)
country = forms.ModelMultipleChoiceField(queryset=Country.objects)
taxonomy_topic = forms.CharField()

def __init__(self, country, *args, **kwargs):
self.country = country
Expand Down Expand Up @@ -338,6 +339,11 @@ def filter_queryset(self, queryset):
queryset = queryset.filter(state__in=['pending_review', 'closed'])\
.filter(submitted_by_user__in=self.cleaned_data['submitted_by'])

if self.cleaned_data.get('taxonomy_topic'):
topic = TaxonomyTopic.objects.filter(slug=self.cleaned_data['taxonomy_topic']).first()
topics = [topic] + [t for t in topic.get_descendants()]
queryset = queryset.filter(work__taxonomy_topics__in=topics)

return queryset

def data_as_url(self):
Expand Down Expand Up @@ -380,6 +386,8 @@ class WorkFilterForm(forms.Form):
advanced_filters = ['assent', 'publication', 'repeal', 'amendment', 'commencement',
'primary_subsidiary', 'taxonomies', 'completeness', 'status']

taxonomy_topic = forms.CharField()

def __init__(self, country, *args, **kwargs):
self.country = country
super(WorkFilterForm, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -511,6 +519,12 @@ def filter_queryset(self, queryset):
end_date = self.cleaned_data['commencement_date_end']
queryset = queryset.filter(commencements__date__range=[start_date, end_date]).order_by('-commencements__date')

if self.cleaned_data.get('taxonomy_topic'):
topic = TaxonomyTopic.objects.filter(slug=self.cleaned_data['taxonomy_topic']).first()
if topic:
topics = [topic] + [t for t in topic.get_descendants()]
queryset = queryset.filter(taxonomy_topics__in=topics)

return queryset

def filter_document_queryset(self, queryset):
Expand Down
6 changes: 3 additions & 3 deletions indigo_app/static/javascript/indigo-app.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions indigo_app/templates/indigo_api/_task_filter_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,9 @@
</div>
</div>
{% endif %}

<!-- Hidden field to capture and preserve the taxonomy_topic parameter-->
<input type="hidden" name="taxonomy_topic" value="{{ request.GET.taxonomy_topic }}" />

</div>
</form>
3 changes: 3 additions & 0 deletions indigo_app/templates/indigo_api/_work_filter_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@
</div>
</div>

<!-- Hidden field to capture and preserve the taxonomy_topic filter parameter-->
<input type="hidden" name="taxonomy_topic" value="{{ request.GET.taxonomy_topic }}" />

<!-- Reset filters -->
<div class="text-right mt-3">
<a href="{{ request.path }}" class="btn btn-outline-danger mr-2">{% trans 'Clear filters' %}</a>
Expand Down
17 changes: 15 additions & 2 deletions indigo_app/templates/indigo_api/task_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@

{% block content %}

<div class="container mt-3">
<div class="card">
<div class="container-fluid px-5 mt-3">

<div class="row">
<div class="card col-md-3 p-3 mx-1 mb-1">
<la-table-of-contents-controller
items="{{ taxonomy_toc }}"
collapse-all-btn-classes="btn btn-sm btn-secondary"
expand-all-btn-classes="btn btn-sm btn-secondary"
title-filter-clear-btn-classes="btn btn-sm btn-secondary"
title-filter-input-classes="form-field"
></la-table-of-contents-controller>
</div>

<div class="card col-md mx-1 p-0">
<div class="card-header p-sticky-0">
<div>
<div class="d-flex">
Expand Down Expand Up @@ -39,4 +51,5 @@

</div>
</div>
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion indigo_app/templates/indigo_api/work_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ <h5 class="card-header">{% trans 'Classification' %}</h5>
</div>

<div class="form-group col-md-6">
<label for="taxonomy_topics">{% trans 'Taxonomy Topics' %}</label>
<label for="taxonomy_topics">{% trans 'Taxonomy topics' %}</label>
<select id="taxonomy_topics" name="work-taxonomy_topics" class="form-control selectpicker" data-live-search="true" multiple data-selected-text-format="count > 3">
{% for topic in form.fields.taxonomy_topics.queryset %}
<option {% if topic.pk in form.taxonomy_topics.value %}selected{% endif %} value="{{ topic.pk }}">{% for s in topic.range_space %} &nbsp; {% endfor %}{{ topic.name }}</option>
Expand Down
19 changes: 17 additions & 2 deletions indigo_app/templates/place/works.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% block view-id %}library-view{% endblock %}

{% block content %}
<div class="container mt-3 mb-5">
<div class="container-fluid px-5 mt-3 mb-5">

{% block content-header %}
<div class="text-right mb-3">
Expand All @@ -22,7 +22,19 @@
</div>
{% endblock %}

<div class="card">
<div class="row">

<div class="card col-md-3 p-3 mx-1 mb-1">
<la-table-of-contents-controller
items="{{ taxonomy_toc }}"
collapse-all-btn-classes="btn btn-sm btn-secondary"
expand-all-btn-classes="btn btn-sm btn-secondary"
title-filter-clear-btn-classes="btn btn-sm btn-secondary"
title-filter-input-classes="form-field"
></la-table-of-contents-controller>
</div>

<div class="card col-md mx-1 p-0">
<div class="card-header">
{% block filter-form %}
{% include 'indigo_api/_work_filter_form.html' with form=form %}
Expand Down Expand Up @@ -51,6 +63,8 @@
{% endif %}
</div>



{% for work in works %}
<div class="list-group-item list-group-item-action p-2" data-toggle="collapse" data-target="#work-detail-{{ work.pk }}">
<div class="d-flex">
Expand Down Expand Up @@ -153,6 +167,7 @@
</div>
{% endif %}
</div>
</div>

<div class="col-2">
{% if doc.n_annotations %}
Expand Down
4 changes: 2 additions & 2 deletions indigo_app/views/places.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from django.views.generic import ListView, TemplateView, UpdateView
from django.views.generic.list import MultipleObjectMixin

from indigo_api.models import Annotation, Country, Task, Work, Amendment, Subtype, Locality, TaskLabel, Document
from indigo_api.models import Annotation, Country, Task, Work, Amendment, Subtype, Locality, TaskLabel, Document, TaxonomyTopic
from indigo_api.views.documents import DocumentViewSet
from indigo_metrics.models import DailyWorkMetrics, WorkMetrics, DailyPlaceMetrics

Expand Down Expand Up @@ -422,7 +422,7 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['form'] = self.form
works = context['works']

context["taxonomy_toc"] = json.dumps(TaxonomyTopic.get_toc_tree(self.request.GET))
self.decorate_works(list(works))

# total works
Expand Down
4 changes: 3 additions & 1 deletion indigo_app/views/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from actstream import action
from django_fsm import has_transition_perm

from indigo_api.models import Annotation, Task, TaskLabel, User, Work, Workflow
from indigo_api.models import Annotation, Task, TaskLabel, User, Work, Workflow, TaxonomyTopic
from indigo_api.serializers import WorkSerializer, DocumentSerializer

from indigo_app.views.base import AbstractAuthedIndigoView, PlaceViewBase
Expand Down Expand Up @@ -90,6 +90,8 @@ def get_context_data(self, **kwargs):
context['frbr_uri'] = self.request.GET.get('frbr_uri')
context['task_groups'] = Task.task_columns(self.form.cleaned_data['state'], context['tasks'])

context["taxonomy_toc"] = json.dumps(TaxonomyTopic.get_toc_tree(self.request.GET))

# warn when submitting task on behalf of another user
Task.decorate_submission_message(context['tasks'], self)

Expand Down
6 changes: 2 additions & 4 deletions indigo_content_api/v2/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from itertools import groupby
from django.urls import reverse

from rest_framework import serializers

Expand Down Expand Up @@ -273,15 +274,12 @@ class Meta:

class TaxonomyTopicSerializer(serializers.ModelSerializer):
children = serializers.SerializerMethodField()

class Meta:
model = TaxonomyTopic
fields = ['name', 'slug', 'children']

def get_queryset(self):
return TaxonomyTopic.get_root_nodes()

def get_children(self, instance):
children = instance.get_children()
return TaxonomyTopicSerializer(children, many=True).data


14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@fortawesome/fontawesome-free": "^5.2.0",
"@lawsafrica/bluebell-monaco": "^4.7.3",
"@lawsafrica/indigo-akn": "^5.3.0",
"@lawsafrica/law-widgets": "^1.3.0",
"@lawsafrica/law-widgets": "^1.4.0",
"bootstrap": "^4.3.1",
"bootstrap-select": "^1.13.18",
"bower": "^1.8.8",
Expand Down

0 comments on commit c3e747c

Please sign in to comment.