-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* start search form * basic search * continue * move url * write tests * add paginator * add paginator to search * search only published labels * add basic order by * add identifiers * add unpublished icon to unpublished labels * add boolean public property * add visual caption * reduce query count * add data pivot search * fix confusing logic * add loading icon, label tweaks * lint --------- Co-authored-by: casey1173 <[email protected]>
- Loading branch information
1 parent
ed2fc4c
commit 34a73ab
Showing
15 changed files
with
569 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.db.models import Q, QuerySet | ||
from django.db.models.base import ModelBase | ||
|
||
from ...myuser.models import HAWCUser | ||
from ...study.models import Study | ||
from ..models import Assessment, Label, LabeledItem | ||
|
||
|
||
def search_studies( | ||
query: str, | ||
all_public: bool = False, | ||
public: QuerySet[Assessment] | None = None, | ||
all_internal: bool = False, | ||
internal: QuerySet[Assessment] | None = None, | ||
user: HAWCUser | None = None, | ||
) -> QuerySet[Study]: | ||
filters = Q() | ||
|
||
if all_public or public: | ||
filters1 = dict( | ||
full_citation__icontains=query, | ||
published=True, | ||
assessment__public_on__isnull=False, | ||
assessment__hide_from_public_page=False, | ||
) | ||
if not all_public and public: | ||
filters1.update(assessment__in=public) | ||
filters |= Q(**filters1) | ||
|
||
if user and (all_internal or internal): | ||
internal_assessments = Assessment.objects.all().user_can_view(user) | ||
if not all_internal and internal: | ||
internal_assessments = internal_assessments.filter(id__in=internal) | ||
filters2 = dict( | ||
full_citation__icontains=query, | ||
assessment__in=internal_assessments, | ||
) | ||
filters |= Q(**filters2) | ||
|
||
if not bool(filters): | ||
return Study.objects.none() | ||
|
||
return Study.objects.filter(filters) | ||
|
||
|
||
def search_visuals( | ||
model_cls: ModelBase, | ||
query: str, | ||
all_public: bool = False, | ||
public: QuerySet[Assessment] | None = None, | ||
all_internal: bool = False, | ||
internal: QuerySet[Assessment] | None = None, | ||
user: HAWCUser | None = None, | ||
) -> QuerySet: | ||
filters = Q() | ||
|
||
ct = ContentType.objects.get_for_model(model_cls) | ||
|
||
if all_public or public: | ||
filters1 = dict( | ||
published=True, | ||
assessment__public_on__isnull=False, | ||
assessment__hide_from_public_page=False, | ||
) | ||
published_labeled_items = LabeledItem.objects.filter( | ||
label__in=Label.objects.filter(name__icontains=query, published=True), content_type=ct | ||
).values_list("object_id", flat=True) | ||
if not all_public and public: | ||
filters1.update(assessment__in=public) | ||
filters |= (Q(title__icontains=query) | Q(id__in=published_labeled_items)) & Q(**filters1) | ||
|
||
if user and (all_internal or internal): | ||
internal_assessments = Assessment.objects.all().user_can_view(user) | ||
if not all_internal and internal: | ||
internal_assessments = internal_assessments.filter(id__in=internal) | ||
filters2 = dict( | ||
assessment__in=internal_assessments, | ||
) | ||
labeled_items = LabeledItem.objects.filter( | ||
label__in=Label.objects.filter(name__icontains=query), content_type=ct | ||
).values_list("object_id", flat=True) | ||
filters |= (Q(title__icontains=query) | Q(id__in=labeled_items)) & Q(**filters2) | ||
|
||
if not bool(filters): | ||
return model_cls.objects.none() | ||
|
||
return model_cls.objects.filter(filters) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
hawc/apps/assessment/templates/assessment/fragments/label.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{% if anchor_tag %} | ||
<a class="{% if not big %} tny {% endif %} {{extra_classes}} label m-1" href="{{label.get_labelled_items_url}}" style="background-color: {{label.color}}; color: {{label.text_color}};" title="{{label.description}}">{{label.name}}</a> | ||
<a class="{% if not big %} tny {% endif %} {{extra_classes}} label m-1" href="{{label.get_labelled_items_url}}" style="background-color: {{label.color}}; color: {{label.text_color}};" title="{{label.description}}">{% if not label.published %}<i class="fa fa-eye-slash mr-1" title="Unpublished label (not be visible to the public)" aria-hidden="true"></i>{% endif %}{{label.name}}</a> | ||
{% else %} | ||
<div class="{% if not big %} tny {% endif %} {{extra_classes}} label m-1" label_url="{{label.get_labelled_items_url}}" style="background-color: {{label.color}}; color: {{label.text_color}};" title="{{label.description}}">{{label.name}}</div> | ||
<div class="{% if not big %} tny {% endif %} {{extra_classes}} label m-1" label_url="{{label.get_labelled_items_url}}" style="background-color: {{label.color}}; color: {{label.text_color}};" title="{{label.description}}">{% if not label.published %}<i class="fa fa-eye-slash mr-1" title="Unpublished label (not be visible to the public)" aria-hidden="true"></i>{% endif %}{{label.name}}</div> | ||
{% endif %} |
Oops, something went wrong.