Skip to content

Commit

Permalink
Merge branch 'main' into bulk-publish-labels
Browse files Browse the repository at this point in the history
  • Loading branch information
caseyhans authored Dec 4, 2024
2 parents 3668759 + c1c58ff commit dbdcc43
Show file tree
Hide file tree
Showing 45 changed files with 230 additions and 81 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
fi
coverage run -m pytest --record-mode=none
echo "# Python coverage report" >> $GITHUB_STEP_SUMMARY
coverage report --format=markdown >> $GITHUB_STEP_SUMMARY
coverage report --format=markdown -i >> $GITHUB_STEP_SUMMARY || true
coverage html -d coverage -i
- name: loc
run: |
Expand All @@ -99,7 +99,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
cache: 'yarn'
cache-dependency-path: 'frontend/yarn.lock'
- name: install
Expand Down
58 changes: 58 additions & 0 deletions client/hawc_client/literature.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pandas as pd
from requests import Response

from .client import BaseClient

Expand Down Expand Up @@ -303,3 +304,60 @@ def update_references_from_hero(self, assessment_id: int) -> None:
"""
url = f"{self.session.root_url}/lit/api/assessment/{assessment_id}/update-reference-metadata-from-hero/"
self.session.post(url)

def create_tag(self, data: dict) -> dict:
"""
Create a tag.
Args:
data (dict): required metadata for creation
Returns:
dict: The resulting object, if create was successful.
"""
url = f"{self.session.root_url}/lit/api/tags/"
response = self.session.post(url, data)
return response.json()

def update_tag(self, tag_id: int, data: dict) -> dict:
"""
Update an existing tag.
Args:
tag_id (int): Tag ID
data (dict): fields to update in tag
Returns:
dict: The resulting object, if update was successful.
"""
url = f"{self.session.root_url}/lit/api/tags/{tag_id}/"
response = self.session.patch(url, data)
return response.json()

def delete_tag(self, tag_id: int) -> Response:
"""
Delete a tag.
Args:
tag_id (int): Tag ID
Returns:
Response: The response object.
"""
url = f"{self.session.root_url}/lit/api/tags/{tag_id}/"
return self.session.delete(url)

def move_tag(self, tag_id: int, new_index: int) -> dict:
"""
Change the order of a tag within its tagtree.
Args:
tag_id (int): Tag ID
new_index: Index to place this tag in relation to its siblings in the tagtree
Returns:
Response: The response object.
"""
url = f"{self.session.root_url}/lit/api/tags/{tag_id}/move/"
body = {"newIndex": new_index}
return self.session.patch(url, body)
4 changes: 4 additions & 0 deletions docs/docs/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ Client tutorials for common operations are below:

### Changelog

#### NEXT (TBD)

* Added literature tag API {create, update, delete, move}

#### [2024-3](https://pypi.org/project/hawc-client/2024.3/) (October 2024)

* Update data pivot and visual output formats to return JSON
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ following applications installed on your local development system:

- [Git](https://git-scm.com/)
- [Python](https://www.python.org/) == 3.12
- [Node.js](https://nodejs.org)
- [Node.js](https://nodejs.org) LTS v22
- [Yarn](https://yarnpkg.com/) < 2
- [PostgreSQL](https://www.postgresql.org/) >= 16

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h2>{{object}}{% debug_badge object.id %}</h2>
{% endif %}
<a class="dropdown-item" href="{{ object.get_clear_cache_url }}">Clear assessment cache</a>
<a class="dropdown-item" href="{{ object.get_assessment_logs_url }}">View change logs</a>
<a class="dropdown-item" hx-get="{% url 'assessment:attachment-htmx' object.pk 'create' %}" hx-trigger="click" hx-target="#attach-tbody" hx-swap="beforeend" href="/">Add an attachment</a>
<a class="dropdown-item" hx-get="{% url 'assessment:attachment-htmx' object.pk 'create' %}" hx-trigger="click" hx-target=".attachment-edit-row.create-row" hx-swap="outerHTML" href="/">Add an attachment</a>
<a class="dropdown-item" href="{% url 'assessment:dataset_create' object.pk %}">Add a dataset</a>
<a class="dropdown-item" href="{% url 'assessment:values-create' object.pk %}">Add a value</a>
<a class="dropdown-item" href="{% url 'assessment:manage-labels' object.pk %}">Manage labels</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<tr hx-target="this" hx-swap="outerHTML" class="attachment-edit-row">
<tr hx-target="this" hx-swap="outerHTML" class="attachment-edit-row {% if form and not form.instance.id %} create-row {% endif %}">
{% if form %}
<td colspan="3" class="bg-lightblue">
<form class="attachment-form pad-form p-3" method="post" enctype="multipart/form-data">
Expand All @@ -24,7 +24,7 @@
</button>
<button class="btn btn-light"
type='button'
onclick="window.app.HAWCUtils.hideElement($(this).closest('.attachment-edit-row'), true)">
onclick="window.app.HAWCUtils.hideElement($(this).closest('.attachment-edit-row'), false)">
Cancel
</button>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="hide-empty-tbody">
<h2>Attachments</h2>
<table class="table table-sm table-striped">
{% if canEdit %}
{% if canEdit or permissions.edit %}
{% bs4_colgroup '25,50,25' %}
{% bs4_thead 'Attachment,Description,Editing' %}
{% else %}
Expand All @@ -12,6 +12,7 @@ <h2>Attachments</h2>
{% for object in object_list %}
{% include "assessment/fragments/attachment_row.html" %}
{% endfor %}
{% include "common/fragments/_create_row.html" with model="attachment" first=True %}
</tbody>
</table>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@
</td>
{% endif %}
</tr>
{% include "common/fragments/_create_row.html" %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<div hx-target="this" hx-swap="outerHTML" class="label-edit-row list-group-item d-flex {% if action == 'delete' %} bg-pink {% else %} bg-lightblue {% endif %}">
<div hx-target="this" hx-swap="outerHTML" class="label-edit-row list-group-item d-flex {% if action == 'delete' %} bg-pink {% else %} bg-lightblue {% endif %}{% if form and not form.instance.id %} create-row {% endif %}">
<form method="post" class="d-flex align-items-center p-1 w-100">
<div class="col-md-auto flex-fill pl-0 py-2">
{% crispy form %}
Expand Down Expand Up @@ -62,7 +62,7 @@
<button class="btn btn-light px-3 py-2 ml-2"
id="binding-cancel"
type='button'
onclick="window.app.HAWCUtils.hideElement($(this).closest('.label-edit-row'), true)">
onclick="window.app.HAWCUtils.hideElement($(this).closest('.label-edit-row'), false)">
Cancel
</button>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
</div>
</div>
</div>
{% if action == 'create' %}
<div class="create-row hidden"></div>
{% endif %}
5 changes: 3 additions & 2 deletions hawc/apps/assessment/templates/assessment/label_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<h2 class="mb-0">Labels</h2>
<button class="btn btn-primary ml-2 ml-auto align-self-start flex-shrink-0"
hx-get="{% url 'assessment:label-htmx' assessment.pk 'create' %}"
hx-target="#label-listgroup"
hx-swap="beforeend">
hx-target=".create-row"
hx-swap="outerHTML">
<i class="fa fa-fw fa-save"></i>&nbsp;
Create label
</button>
Expand All @@ -17,6 +17,7 @@ <h2 class="mb-0">Labels</h2>
{% include "assessment/fragments/label_row.html" with canEdit=True %}
{% endfor %}
<div class="alert alert-info text-center show-only-child my-0">No labels created (yet).</div>
<div class="create-row hidden"></div>
</div>
</div>
{% endblock content %}
Expand Down
7 changes: 4 additions & 3 deletions hawc/apps/common/autocomplete/registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.core.exceptions import BadRequest, FieldError, ValidationError
from django.core.exceptions import FieldError, ValidationError
from django.http import Http404
from django.http.response import HttpResponseBadRequest
from django.utils.encoding import force_str
from django.utils.module_loading import autodiscover_modules

Expand Down Expand Up @@ -50,8 +51,8 @@ def get_autocomplete(request, autocomplete_name):
raise Http404(f"Autocomplete {autocomplete_name} not found") from err
try:
return autocomplete_cls.as_view()(request)
except (ValueError, ValidationError, FieldError) as err:
raise BadRequest(str(err)) from None
except (ValueError, ValidationError, FieldError):
return HttpResponseBadRequest("Bad request.")


def autodiscover():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<h3 class="card-title">{{title}}
<button id="{{model}}-create" class="btn btn-sm btn-primary float-right" hx-get="{{hx_get}}" hx-target="{{hx_target}}" hx-swap="beforeend"><i class="fa fa-plus fa-fw"></i>&nbsp;{{btn_text}}</button>
<button id="{{model}}-create" class="btn btn-sm btn-primary float-right" hx-get="{{hx_get}}" hx-target="{{hx_target}}" hx-swap="outerHTML"><i class="fa fa-plus fa-fw"></i>&nbsp;{{btn_text}}</button>
</h3>
3 changes: 3 additions & 0 deletions hawc/apps/common/templates/common/fragments/_create_row.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% if action == 'create' or action == 'clone' or first == True %}
<tr class="{{model}}-edit-row create-row hidden"></tr>
{% endif %}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tr hx-target="this" hx-swap="outerHTML swap:0s" class="{{app}}-edit-row {{model}}-edit-row">
<tr hx-target="this" hx-swap="outerHTML swap:0s" class="{{app}}-edit-row {{model}}-edit-row {% if form and not form.instance.id %} create-row {% endif %}">
{% if form %}
<td colspan="100%" class="p-3">
<form method="post" class="border p-2 pb-4 edit-form-background rounded pad-form form-{{model}}">
Expand All @@ -18,7 +18,7 @@
Save
</button>
<button id="{{model}}-cancel" class="btn btn-sm btn-light mx-2 py-2" type='button' style="width: 8rem; padding: 0.7rem;"
onclick="window.app.HAWCUtils.hideElement($(this).closest('.{{app}}-edit-row'), true)"><i
onclick="window.app.HAWCUtils.hideElement($(this).closest('.{{app}}-edit-row'), false)"><i
class="fa fa-fw fa-times mr-1"></i>
Cancel</button>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<button id="{{model}}-delete" class="btn btn-sm btn-danger" hx-get="{% crud_url app model 'delete' object.pk %}">
<i class="fa fa-trash" aria-hidden="true"></i></button>
<button id="{{model}}-clone" class="btn btn-sm btn-secondary" hx-post="{% crud_url app model 'clone' object.pk %}"
hx-target="#{{model}}-tbody" hx-swap="beforeend">
hx-target=".{{model}}-edit-row.create-row" hx-swap="outerHTML">
<i class="fa fa-clone" aria-hidden="true"></i></button>
</td>
{% endif %}
15 changes: 9 additions & 6 deletions hawc/apps/eco/templates/eco/design_update.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ <h2 class="d-inline-block">{{object.name}}</h2>
<div class="card my-4 mx-2">
<div class="card-body">
{% url 'eco:cause-htmx' object.pk 'create' as cause_create %}
{% include "common/fragments/_create_card.html" with title="Causes" hx_get=cause_create hx_target="#cause-tbody" model="cause" btn_text="Create" %}
{% include "common/fragments/_create_card.html" with title="Causes" hx_get=cause_create hx_target=".cause-edit-row.create-row" model="cause" btn_text="Create" %}
<table class="table table-sm table-striped-invert">
{% bs4_colgroup '10,15,15,15,15,15,15' %}
{% bs4_thead 'Name,Term,Species,Level,Level Units,Comment,Edit' %}
<tbody id="cause-tbody">
{% include "common/fragments/_create_one.html" with text="No effects. Create one?" %}
{% for object in causes %}
{% include "eco/fragments/cause_row.html" %}
{% endfor %}
{% include "common/fragments/_create_one.html" with text="No causes. Create one?" %}
{% include "common/fragments/_create_row.html" with model="cause" first=True %}
</tbody>
</table>
</div>
Expand All @@ -30,15 +31,16 @@ <h2 class="d-inline-block">{{object.name}}</h2>
<div class="card my-4 mx-2">
<div class="card-body">
{% url 'eco:effect-htmx' object.pk 'create' as effect_create %}
{% include "common/fragments/_create_card.html" with title="Effects" hx_get=effect_create hx_target="#effect-tbody" model="effect" btn_text="Create" %}
{% include "common/fragments/_create_card.html" with title="Effects" hx_get=effect_create hx_target=".effect-edit-row.create-row" model="effect" btn_text="Create" %}
<table class="table table-sm table-striped-invert">
{% bs4_colgroup '10,15,15,15,15,15,15' %}
{% bs4_thead 'Name,Term,Species,Units,As Reported,Comment,Edit' %}
<tbody id="effect-tbody">
{% include "common/fragments/_create_one.html" with text="No effects. Create one?" %}
{% for object in effects %}
{% include "eco/fragments/effect_row.html" %}
{% endfor %}
{% include "common/fragments/_create_one.html" with text="No effects. Create one?" %}
{% include "common/fragments/_create_row.html" with model="effect" first=True %}
</tbody>
</table>
</div>
Expand All @@ -47,15 +49,16 @@ <h2 class="d-inline-block">{{object.name}}</h2>
<div class="card my-4 mx-2">
<div class="card-body">
{% url 'eco:result-htmx' object.pk 'create' as result_create %}
{% include "common/fragments/_create_card.html" with title="Results" hx_get=result_create hx_target="#result-tbody" model="result" btn_text="Create" %}
{% include "common/fragments/_create_card.html" with title="Results" hx_get=result_create hx_target=".result-edit-row.create-row" model="result" btn_text="Create" %}
<table class="table table-sm table-striped-invert">
{% bs4_colgroup '15,15,15,10,15,15,15' %}
{% bs4_thead 'Name,Cause,Effect,Relationship Direction,Modifying Factors,Value,Edit' %}
<tbody id="result-tbody">
{% include "common/fragments/_create_one.html" with text="No effects. Create one?" %}
{% for object in results %}
{% include "eco/fragments/result_row.html" %}
{% endfor %}
{% include "common/fragments/_create_one.html" with text="No results. Create one?" %}
{% include "common/fragments/_create_row.html" with model="result" first=True %}
</tbody>
</table>
</div>
Expand Down
1 change: 1 addition & 0 deletions hawc/apps/eco/templates/eco/fragments/cause_row.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
<td>{{object.comments }}</td>
{% include "common/fragments/_object_row.html" with app="eco" model="cause" %}
</tr>
{% include "common/fragments/_create_row.html" with model="cause" %}
1 change: 1 addition & 0 deletions hawc/apps/eco/templates/eco/fragments/effect_row.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
<td>{{object.comments }}</td>
{% include "common/fragments/_object_row.html" with app="eco" model="effect" %}
</tr>
{% include "common/fragments/_create_row.html" with model="effect" %}
1 change: 1 addition & 0 deletions hawc/apps/eco/templates/eco/fragments/result_row.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
<td>{{object.derived_value }}</td>
{% include "common/fragments/_object_row.html" with app="eco" model="result" %}
</tr>
{% include "common/fragments/_create_row.html" with model="result" %}
2 changes: 1 addition & 1 deletion hawc/apps/epi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def handle_dtxsid(self, request):
if dtxsid := request.data.get("dtxsid"):
try:
DSSTox.objects.get(dtxsid=dtxsid)
except DSSTox.DoesNotExist as err:
except (DSSTox.DoesNotExist, ValueError) as err:
raise ValidationError(f"{dtxsid} does not exist in HAWC") from err

@transaction.atomic
Expand Down
Loading

0 comments on commit dbdcc43

Please sign in to comment.