Skip to content

Commit

Permalink
migrate to Django 5.0.0 (#959)
Browse files Browse the repository at this point in the history
* update requirements.txt

* add changes from django-upgrade

* fix for assuming HTTPS in URL Field

* fix one more django warning

* add extra unrelated change from #962

---------

Co-authored-by: Andy Shapiro <shapiromatron@gmail.com>
  • Loading branch information
munnsmunns and shapiromatron committed Dec 19, 2023
1 parent 7f63938 commit ba75451
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 97 deletions.
4 changes: 1 addition & 3 deletions hawc/apps/animal/managers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from copy import deepcopy
from typing import Any

import numpy as np
Expand All @@ -20,13 +19,12 @@ class ExperimentManager(BaseManager):
assessment_relation = "study__assessment"

def get_type_choices(self, assessment_id: int):
choices = deepcopy(constants.ExperimentType.choices)
types = set(
self.model.objects.filter(study__assessment_id=assessment_id)
.values_list("type", flat=True)
.distinct()
)
return [c for c in choices if c[0] in types]
return [c for c in constants.ExperimentType.choices if c[0] in types]


class AnimalGroupManager(BaseManager):
Expand Down
28 changes: 14 additions & 14 deletions hawc/apps/animal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Experiment(models.Model):
)
type = models.CharField(
max_length=2,
choices=constants.ExperimentType.choices,
choices=constants.ExperimentType,
help_text="Type of study being performed; be as specific as possible",
)
has_multiple_generations = models.BooleanField(default=False)
Expand Down Expand Up @@ -84,7 +84,7 @@ class Experiment(models.Model):
purity_available = models.BooleanField(default=True, verbose_name="Chemical purity available?")
purity_qualifier = models.CharField(
max_length=1,
choices=constants.PurityQualifier.choices,
choices=constants.PurityQualifier,
blank=True,
default=constants.PurityQualifier.NA,
)
Expand Down Expand Up @@ -220,7 +220,7 @@ class AnimalGroup(models.Model):
help_text="When adding a new strain, put the stock in parenthesis, e.g., "
+ '"Sprague-Dawley (Harlan)."',
)
sex = models.CharField(max_length=1, choices=constants.Sex.choices)
sex = models.CharField(max_length=1, choices=constants.Sex)
animal_source = models.CharField(
max_length=128, help_text="Source from where animals were acquired", blank=True
)
Expand Down Expand Up @@ -250,7 +250,7 @@ class AnimalGroup(models.Model):
)
siblings = models.ForeignKey("self", blank=True, null=True, on_delete=models.SET_NULL)
generation = models.CharField(
blank=True, default="", max_length=2, choices=constants.Generation.choices
blank=True, default="", max_length=2, choices=constants.Generation
)
parents = models.ManyToManyField("self", related_name="children", symmetrical=False, blank=True)
dosing_regime = models.ForeignKey(
Expand Down Expand Up @@ -381,7 +381,7 @@ class DosingRegime(models.Model):
)
route_of_exposure = models.CharField(
max_length=2,
choices=constants.RouteExposure.choices,
choices=constants.RouteExposure,
help_text="Primary route of exposure. If multiple primary-exposures, describe in notes-field below",
)
duration_exposure = models.FloatField(
Expand Down Expand Up @@ -429,7 +429,7 @@ class DosingRegime(models.Model):
negative_control = models.CharField(
max_length=2,
default=constants.NegativeControl.VT,
choices=constants.NegativeControl.choices,
choices=constants.NegativeControl,
help_text="Description of negative-controls used",
)
description = models.TextField(
Expand Down Expand Up @@ -626,7 +626,7 @@ class Endpoint(BaseEndpoint):
)
litter_effects = models.CharField(
max_length=2,
choices=constants.LitterEffect.choices,
choices=constants.LitterEffect,
default=constants.LitterEffect.NA,
help_text='Type of controls used for litter-effects. The "No" response '
+ "will be infrequently used. More typically the information will be "
Expand All @@ -645,7 +645,7 @@ class Endpoint(BaseEndpoint):
"optional, should be recorded if the same effect was measured multiple times.",
)
observation_time_units = models.PositiveSmallIntegerField(
default=constants.ObservationTimeUnits.NR, choices=constants.ObservationTimeUnits.choices
default=constants.ObservationTimeUnits.NR, choices=constants.ObservationTimeUnits
)
observation_time_text = models.CharField(
max_length=64,
Expand All @@ -660,7 +660,7 @@ class Endpoint(BaseEndpoint):
'1 and Text, p.24")',
)
expected_adversity_direction = models.PositiveSmallIntegerField(
choices=constants.AdverseDirection.choices,
choices=constants.AdverseDirection,
default=constants.AdverseDirection.NR,
verbose_name="Expected response adversity direction",
help_text="Response direction which would be considered adverse",
Expand All @@ -673,12 +673,12 @@ class Endpoint(BaseEndpoint):
)
data_type = models.CharField(
max_length=2,
choices=constants.DataType.choices,
choices=constants.DataType,
default=constants.DataType.CONTINUOUS,
verbose_name="Dataset type",
)
variance_type = models.PositiveSmallIntegerField(
default=constants.VarianceType.SD, choices=constants.VarianceType.choices
default=constants.VarianceType.SD, choices=constants.VarianceType
)
confidence_interval = models.FloatField(
blank=True,
Expand Down Expand Up @@ -706,7 +706,7 @@ class Endpoint(BaseEndpoint):
help_text="Response values were estimated using a digital ruler or other methods",
)
monotonicity = models.PositiveSmallIntegerField(
default=constants.Monotonicity.NR, choices=constants.Monotonicity.choices
default=constants.Monotonicity.NR, choices=constants.Monotonicity
)
statistical_test = models.CharField(
max_length=256,
Expand All @@ -718,7 +718,7 @@ class Endpoint(BaseEndpoint):
null=True, blank=True, help_text="Numerical result for trend-test, if available"
)
trend_result = models.PositiveSmallIntegerField(
default=constants.TrendResult.NR, choices=constants.TrendResult.choices
default=constants.TrendResult.NR, choices=constants.TrendResult
)
diagnostic = models.TextField(
verbose_name="Diagnostic (as reported)",
Expand Down Expand Up @@ -1359,7 +1359,7 @@ class EndpointGroup(ConfidenceIntervalsMixin, models.Model):
null=True,
blank=True,
default=None,
choices=constants.TreatmentEffect.choices,
choices=constants.TreatmentEffect,
help_text="Expert judgement based report of treatment related effects (add direction if known). Use when statistical analysis not available. In results comments, indicate whether it was author judgment or assessment team judgement",
)

Expand Down
22 changes: 11 additions & 11 deletions hawc/apps/assessment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ def get_rob_name_default():
)
noel_name = models.PositiveSmallIntegerField(
default=get_noel_name_default,
choices=constants.NoelName.choices,
choices=constants.NoelName,
verbose_name="NEL/NOEL/NOAEL name",
help_text="What term should be used to refer to NEL/NOEL/NOAEL and LEL/LOEL/LOAEL?",
)
rob_name = models.PositiveSmallIntegerField(
default=get_rob_name_default,
choices=constants.RobName.choices,
choices=constants.RobName,
verbose_name="Risk of bias/Study evaluation name",
help_text="What term should be used to refer to risk of bias/study evaluation questions?",
)
Expand All @@ -288,7 +288,7 @@ def get_rob_name_default():
needed.""",
)
epi_version = models.PositiveSmallIntegerField(
choices=constants.EpiVersion.choices,
choices=constants.EpiVersion,
default=constants.EpiVersion.V2,
verbose_name="Epidemiology schema version",
help_text="Data extraction schema version used for epidemiology studies",
Expand Down Expand Up @@ -515,7 +515,7 @@ class AssessmentDetail(models.Model):
help_text="If part of a product line, the name of the project type",
)
project_status = models.PositiveSmallIntegerField(
choices=constants.Status.choices,
choices=constants.Status,
default=constants.Status.SCOPING,
help_text="High-level project management milestones for this assessment",
)
Expand All @@ -527,7 +527,7 @@ class AssessmentDetail(models.Model):
)
peer_review_status = models.PositiveSmallIntegerField(
verbose_name="Peer Review Status",
choices=constants.PeerReviewType.choices,
choices=constants.PeerReviewType,
help_text="Define the current status of peer review of this assessment, if any",
default=constants.PeerReviewType.NONE,
)
Expand Down Expand Up @@ -582,7 +582,7 @@ class AssessmentValue(models.Model):

assessment = models.ForeignKey(Assessment, models.CASCADE, related_name="values")
evaluation_type = models.PositiveSmallIntegerField(
choices=constants.EvaluationType.choices,
choices=constants.EvaluationType,
default=constants.EvaluationType.CANCER,
help_text="Substance evaluation conducted",
)
Expand All @@ -592,7 +592,7 @@ class AssessmentValue(models.Model):
help_text="Identify the health system of concern (e.g., Hepatic, Nervous, Reproductive)",
)
value_type = models.PositiveSmallIntegerField(
choices=constants.ValueType.choices,
choices=constants.ValueType,
help_text="Type of derived value",
)
value = models.FloatField(
Expand Down Expand Up @@ -640,7 +640,7 @@ class AssessmentValue(models.Model):
uncertainty = models.IntegerField(
blank=True,
null=True,
choices=constants.UncertaintyChoices.choices,
choices=constants.UncertaintyChoices,
verbose_name="Uncertainty factor",
help_text="Composite uncertainty factor applied to POD to derive the final value",
)
Expand Down Expand Up @@ -1121,10 +1121,10 @@ class Job(models.Model):
Assessment, blank=True, null=True, on_delete=models.CASCADE, related_name="jobs"
)
status = models.PositiveSmallIntegerField(
choices=constants.JobStatus.choices, default=constants.JobStatus.PENDING, editable=False
choices=constants.JobStatus, default=constants.JobStatus.PENDING, editable=False
)
job = models.PositiveSmallIntegerField(
choices=constants.JobType.choices, default=constants.JobType.TEST
choices=constants.JobType, default=constants.JobType.TEST
)

kwargs = models.JSONField(default=dict, blank=True, null=True)
Expand Down Expand Up @@ -1268,7 +1268,7 @@ class ContentTypeChoices(models.IntegerChoices):


class Content(models.Model):
content_type = models.PositiveIntegerField(choices=ContentTypeChoices.choices, unique=True)
content_type = models.PositiveIntegerField(choices=ContentTypeChoices, unique=True)
template = models.TextField()
created = models.DateTimeField(auto_now_add=True)
last_updated = models.DateTimeField(auto_now=True)
Expand Down
4 changes: 2 additions & 2 deletions hawc/apps/bmd/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AssessmentSettings(models.Model):
)
version = models.CharField(
max_length=10,
choices=constants.BmdsVersion.choices,
choices=constants.BmdsVersion,
default=constants.BmdsVersion.BMDS330,
help_text="Select the BMDS version to be used for dose-response modeling. Version 2 is no longer supported for execution; but results will be available for any version after execution is complete.",
)
Expand Down Expand Up @@ -56,7 +56,7 @@ class Session(models.Model):
dose_units = models.ForeignKey(
"assessment.DoseUnits", on_delete=models.CASCADE, related_name="bmd_sessions"
)
version = models.CharField(max_length=10, choices=constants.BmdsVersion.choices)
version = models.CharField(max_length=10, choices=constants.BmdsVersion)
inputs = models.JSONField(default=dict)
outputs = models.JSONField(default=dict)
errors = models.JSONField(default=dict)
Expand Down
6 changes: 3 additions & 3 deletions hawc/apps/eco/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __str__(self):

class NestedTerm(MP_Node):
name = models.CharField(max_length=128)
type = models.CharField(choices=TypeChoices.choices, max_length=2, default="CE")
type = models.CharField(choices=TypeChoices, max_length=2, default="CE")
created = models.DateTimeField(auto_now_add=True)
last_updated = models.DateTimeField(auto_now=True)
notes = models.TextField(blank=True)
Expand Down Expand Up @@ -66,7 +66,7 @@ def as_dataframe(cls) -> pd.DataFrame:


class Vocab(models.Model):
category = models.IntegerField(choices=VocabCategories.choices)
category = models.IntegerField(choices=VocabCategories)
value = models.CharField(max_length=128)
parent = models.ForeignKey(
"self",
Expand Down Expand Up @@ -408,7 +408,7 @@ class Result(models.Model):
default=0,
)
relationship_direction = models.IntegerField(
choices=ChangeTrajectory.choices,
choices=ChangeTrajectory,
verbose_name="Direction of relationship",
help_text="Direction of cause and effect relationship",
)
Expand Down

0 comments on commit ba75451

Please sign in to comment.