Skip to content

Commit

Permalink
Merge branch 'release/0.3.70' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jan 24, 2024
2 parents 38e4068 + fb53558 commit f50bb83
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Generated by Django 5.0 on 2024-01-24 18:10

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
(
"edc_action_item",
"0035_alter_actionitem_options_alter_actiontype_options_and_more",
),
("sites", "0002_alter_domain_unique"),
]

operations = [
migrations.AlterField(
model_name="actionitem",
name="priority",
field=models.CharField(
blank=True,
choices=[
("high", "High Priority"),
("medium", "Medium Priority"),
("low", "Low Priority"),
],
help_text="Leave blank to use default for this action type.",
max_length=25,
null=True,
),
),
migrations.AlterField(
model_name="actionitem",
name="site",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="sites.site",
),
),
migrations.AlterField(
model_name="actiontype",
name="priority",
field=models.CharField(
choices=[
("high", "High Priority"),
("medium", "Medium Priority"),
("low", "Low Priority"),
],
default="high",
max_length=25,
),
),
migrations.AlterField(
model_name="historicalactionitem",
name="priority",
field=models.CharField(
blank=True,
choices=[
("high", "High Priority"),
("medium", "Medium Priority"),
("low", "Low Priority"),
],
help_text="Leave blank to use default for this action type.",
max_length=25,
null=True,
),
),
migrations.AlterField(
model_name="historicalactionitem",
name="site",
field=models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
to="sites.site",
),
),
]
40 changes: 18 additions & 22 deletions edc_action_item/modelform_mixins/modelform_mixins.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from django import forms

from ..exceptions import ActionError

if TYPE_CHECKING:
from ..action import Action
from ..models import ActionItem


class ActionItemModelFormMixin:
def clean(self):
Expand All @@ -22,29 +30,17 @@ def clean(self):
return cleaned_data

@property
def action_cls(self):
try:
action_cls = self._meta.model.get_action_cls()
except AttributeError:
action_cls = None
return action_cls
def action_cls(self) -> Action:
return self._meta.model.get_action_cls()

@property
def action_identifier(self):
action_identifier = self.cleaned_data.get("action_identifier")
if not action_identifier:
try:
action_identifier = self.instance.action_identifier
except AttributeError:
action_identifier = None
return action_identifier
def action_identifier(self) -> str:
return self.cleaned_data.get("action_identifier") or getattr(
self.instance, "action_identifier", None
)

@property
def related_action_item(self):
related_action_item = self.cleaned_data.get("related_action_item")
if not related_action_item:
try:
related_action_item = self.instance.related_action_item
except AttributeError:
related_action_item = None
return related_action_item
def related_action_item(self) -> ActionItem:
return self.cleaned_data.get("related_action_item") or getattr(
self.instance, "related_action_item", None
)

0 comments on commit f50bb83

Please sign in to comment.