Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icf cpheapm70 deep clone study, study evaluation, bioassay, epiv2 #1117

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions hawc/apps/common/templates/common/fragments/error_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<ul>
{% for field, errors in err.error_dict.items %}
<li>
<strong>{% if field == '__all__' %}Overall{% else %}{{ field }}{% endif %}:</strong>
<ul>
{% for error in errors %}<li>{{ error.message }}</li>{% endfor %}
</ul>
</li>
{% empty %}
{% comment %} fall back to string if there is no error_dict {% endcomment %}
<li>{{err}}</li>
{% endfor %}
</ul>
5 changes: 5 additions & 0 deletions hawc/apps/common/templatetags/hawc.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,8 @@ def e_notation(value: str) -> str:
def label_htmx_url(item) -> str:
ct = ContentType.objects.get_for_model(item)
return reverse("assessment:label-item", args=(ct.id, item.id))


@register.simple_tag
def anchor_new_tab() -> str:
return 'rel="noopener noreferrer" target="_blank"'
23 changes: 16 additions & 7 deletions hawc/apps/common/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ def add_csrf(obj: dict, request: HttpRequest) -> dict:


def create_object_log(
verb: str, obj, assessment_id: int | None, user_id: int, log_message: str = ""
verb: str,
obj,
assessment_id: int | None,
user_id: int,
log_message: str = "",
use_reversion: bool = True,
):
"""
Create an object log for a given object and associate a reversion instance if it exists.
Expand All @@ -102,10 +107,11 @@ def create_object_log(
assessment_id (int|None): the object assessment id
user_id (int): the user id
log_message (str): override for custom message
use_reversion (bool): user reversion data for object log
"""
# Log action
meta = obj._meta
if not log_message:
meta = obj._meta
log_message = f'{verb} {meta.app_label}.{meta.model_name} #{obj.id}: "{obj}"'
log = Log.objects.create(
assessment_id=assessment_id,
Expand All @@ -114,11 +120,14 @@ def create_object_log(
content_object=obj,
)
# Associate log with reversion
comment = (
f"{reversion.get_comment()}, Log {log.id}" if reversion.get_comment() else f"Log {log.id}"
)
audit_logger.info(f"[{log.id}] assessment-{assessment_id} user-{user_id} {log_message}")
reversion.set_comment(comment)
if use_reversion:
comment = (
f"{reversion.get_comment()}, Log {log.id}"
if reversion.get_comment()
else f"Log {log.id}"
)
audit_logger.info(f"[{log.id}] assessment-{assessment_id} user-{user_id} {log_message}")
reversion.set_comment(comment)


def bulk_create_object_log(verb: str, obj_list: Iterable[Any], user_id: int):
Expand Down
7 changes: 6 additions & 1 deletion hawc/apps/riskofbias/actions/rob_approach.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def load_approach(assessment_id: int, approach: RobApproach, user_id: int | None
@transaction.atomic
def clone_approach(
dest_assessment: Assessment, src_assessment: Assessment, user_id: int | None = None
):
) -> dict[int, int]:
"""
Clone approach from one assessment to another.
"""
Expand All @@ -98,12 +98,17 @@ def clone_approach(
dest_rob_settings.save()

# copy domains and metrics to assessment
metric_map = {}
for domain in src_assessment.rob_domains.all():
metrics = list(domain.metrics.all()) # force evaluation
domain.id = None
domain.assessment = dest_assessment
domain.save()
for metric in metrics:
src_metric_id = metric.id
metric.id = None
metric.domain = domain
metric.save()
metric_map[src_metric_id] = metric.id

return metric_map
2 changes: 1 addition & 1 deletion hawc/apps/riskofbias/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def build_scores(self, assessment, study):
metric.build_score(riskofbias=self, is_default=True)
for metric in RiskOfBiasMetric.objects.get_required_metrics(study)
]
RiskOfBiasScore.objects.bulk_create(scores)
return RiskOfBiasScore.objects.bulk_create(scores)

def activate(self):
self.active = True
Expand Down
Loading