Skip to content

Commit

Permalink
quick links for task and work views
Browse files Browse the repository at this point in the history
  • Loading branch information
longhotsummer committed Sep 6, 2024
1 parent 8f30657 commit 1dd5820
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 6 deletions.
4 changes: 3 additions & 1 deletion indigo_api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
from treebeard.forms import MoveNodeForm, movenodeform_factory
from background_task.admin import TaskAdmin

from .models import Document, Subtype, Colophon, Work, TaskLabel, TaxonomyTopic, CitationAlias
from .models import Document, Subtype, Colophon, Work, TaskLabel, TaxonomyTopic, CitationAlias, QuickLink


admin.site.register(Subtype)
admin.site.register(QuickLink)


class TaxonomyForm(MoveNodeForm):
Expand Down
27 changes: 27 additions & 0 deletions indigo_api/migrations/0043_quicklink.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.15 on 2024-09-06 11:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('indigo_api', '0042_backfill_task_comment_code'),
]

operations = [
migrations.CreateModel(
name='QuickLink',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, verbose_name='name')),
('scope', models.CharField(choices=[('tasks', 'Tasks'), ('works', 'Works')], verbose_name='scope')),
('querystring', models.CharField(max_length=2048, verbose_name='querystring')),
],
options={
'verbose_name': 'quick link',
'verbose_name_plural': 'quick links',
'ordering': ['name'],
},
),
]
1 change: 1 addition & 0 deletions indigo_api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
from .places import *
from .works import *
from .documents import *
from .quick_links import *
from .tasks import *
33 changes: 33 additions & 0 deletions indigo_api/models/quick_links.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django.db import models
from django.utils.translation import gettext_lazy as _


class QuickLink(models.Model):
SCOPES = {
"tasks": _("Tasks"),
"works": _("Works"),
}

name = models.CharField(_("name"), max_length=255)
scope = models.CharField(_("scope"), choices=SCOPES.items())
querystring = models.CharField(_("querystring"), max_length=2048)

class Meta:
verbose_name = _("quick link")
verbose_name_plural = _("quick links")
ordering = ["name"]

def save(self, *args, **kwargs):
if self.querystring.startswith("http"):
# just keep the querystring bit
if '?' in self.querystring:
self.querystring = self.querystring.split("?", 1)[1]
else:
self.querystring = "?"
if not self.querystring.startswith("?"):
self.querystring = "?" + self.querystring

super().save(*args, **kwargs)

def __str__(self):
return f"QuickLink<{self.name}: {self.SCOPES[self.scope]} - {self.querystring}>"
11 changes: 11 additions & 0 deletions indigo_app/templates/indigo_api/_quick_links.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% load i18n %}
<div class="dropdown">
<button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">
{% trans "Saved searches" %}
</button>
<ul class="dropdown-menu">
{% for link in quick_links %}
<li><a class="dropdown-item" href="{{ link.querystring }}">{{ link.name }}</a></li>
{% endfor %}
</ul>
</div>
6 changes: 6 additions & 0 deletions indigo_app/templates/indigo_api/_work_filter_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
</div>

<button type="submit" class="btn btn-primary">{% trans 'Apply' %}</button>

{% if quick_links %}
<div class="ms-3">
{% include 'indigo_api/_quick_links.html' %}
</div>
{% endif %}
</div>

<div class="collapse mt-2 {% if form.show_advanced_filters %}show{% endif %}" id="advancedFilters">
Expand Down
11 changes: 8 additions & 3 deletions indigo_app/templates/indigo_api/task_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
<div class="row justify-content-end mb-3">
<div class="col-md-9">
<div>
<div class="d-flex">
<div class="flex-grow-1">
<div class="d-flex align-items-start">
<div>
{% url 'tasks' place.place_code as form_url %}
{% include 'indigo_api/_task_filter_form.html' %}
</div>

<div class="ps-3 border-left">
<div class="btn-toolbar ms-auto">
{% if quick_links %}
<div class="pe-3">
{% include 'indigo_api/_quick_links.html' %}
</div>
{% endif %}
<a href="{% url 'create_task' place=place.place_code %}" class="btn btn-success">{% trans 'New task' %}</a>
</div>
</div>
Expand Down
9 changes: 8 additions & 1 deletion indigo_app/templates/indigo_app/tasks/all_tasks.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
<div class="container-fluid mt-3">
<div class="row">
<div class="col-md-9 offset-3 mb-3">
{% include 'indigo_api/_task_filter_form.html' %}
<div class="d-flex align-items-start">
{% include 'indigo_api/_task_filter_form.html' %}
{% if quick_links %}
<div class="ms-auto">
{% include 'indigo_api/_quick_links.html' %}
</div>
{% endif %}
</div>
</div>
</div>

Expand Down
4 changes: 3 additions & 1 deletion indigo_app/views/places.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from django_htmx.http import push_url
from lxml import etree

from indigo_api.models import Country, Task, Work, Subtype, Locality, TaskLabel, Document, TaxonomyTopic, AllPlace
from indigo_api.models import Country, Task, Work, Subtype, Locality, TaskLabel, Document, TaxonomyTopic, AllPlace, \
QuickLink
from indigo_api.timeline import describe_publication_event
from indigo_app.forms import WorkFilterForm, PlaceSettingsForm, PlaceUsersForm, ExplorerForm, WorkBulkActionsForm, \
WorkChooserForm, WorkBulkUpdateForm, WorkBulkApproveForm, WorkBulkUnapproveForm
Expand Down Expand Up @@ -561,6 +562,7 @@ def get_context_data(self, **kwargs):
qs = self.get_base_queryset()
context["work_facets"] = self.form.work_facets(qs, context['taxonomy_toc'], context.get('places_toc', []))
context["document_facets"] = self.form.document_facets(qs)
context["quick_links"] = QuickLink.objects.filter(scope="works").all()

return context

Expand Down
3 changes: 3 additions & 0 deletions indigo_app/views/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from django_htmx.http import push_url

from indigo_api.models import Annotation, Task, TaskLabel, User, Work, TaxonomyTopic, TaskFile
from indigo_api.models.quick_links import QuickLink
from indigo_api.serializers import WorkSerializer
from indigo_api.views.attachments import view_attachment
from indigo_app.forms import TaskForm, TaskFilterForm, BulkTaskUpdateForm, TaskEditLabelsForm, BulkTaskStateChangeForm
Expand Down Expand Up @@ -98,6 +99,7 @@ def get_context_data(self, **kwargs):
context["taxonomy_toc"] = TaxonomyTopic.get_toc_tree(self.request.GET)
context["work_facets"] = self.form.work_facets(self.form.works_queryset, context['taxonomy_toc'], [])
context["task_facets"] = self.form.task_facets(self.get_base_queryset(), [])
context["quick_links"] = QuickLink.objects.filter(scope="tasks").all()

# warn when submitting task on behalf of another user
Task.decorate_submission_message(context['tasks'], self)
Expand Down Expand Up @@ -652,6 +654,7 @@ def get_context_data(self, **kwargs):
context['total_tasks'] = self.get_base_queryset().count()
context["hide_assigned_to"] = False
context["place"] = True
context["quick_links"] = QuickLink.objects.filter(scope="tasks").all()
return context


Expand Down
1 change: 1 addition & 0 deletions indigo_social/default_badges.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class ContentManagerBadge(PermissionBadge):
permissions = (
'indigo_api.add_taxonomytopic', 'indigo_api.change_taxonomytopic', 'indigo_api.delete_taxonomytopic',
'indigo_api.add_tasklabel', 'indigo_api.change_tasklabel', 'indigo_api.delete_tasklabel',
'indigo_api.add_quicklink', 'indigo_api.change_quicklink', 'indigo_api.delete_quicklink',
)


Expand Down

0 comments on commit 1dd5820

Please sign in to comment.