Skip to content

Commit

Permalink
Update field_model_ifc_actor_select.py
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvianen committed Jan 19, 2025
1 parent 266c6be commit 1f4b786
Showing 1 changed file with 87 additions and 13 deletions.
100 changes: 87 additions & 13 deletions src/django_bim/fields/model/actor/field_model_ifc_actor_select.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,107 @@
# -*- coding: utf-8 -*-


# =============================================================================
# Docstring
# =============================================================================

"""
===================================
https://ifc43-docs.standards.buildingsmart.org/IFC/RELEASE/IFC4x3/HTML/lexical/IfcActorSelect.htm
"""


# =============================================================================
# Import
# =============================================================================

# Import | Standard Library
from typing import Literal

# Import | Libraries
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils.translation import gettext_lazy as _

# Import | Local Modules


# =============================================================================
# Classes
# =============================================================================


class IfcActorSelectField(models.Field):
description = _(
"A field that can refer to an IfcOrganization, IfcPerson, or IfcPersonAndOrganization"
"""
...
"""

description: str = _(
message="A field that can refer to an IfcOrganization, IfcPerson, or IfcPersonAndOrganization"
)

def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
"""
...
"""
super().__init__(*args, **kwargs)
self.object_id_field = 'object_id'
self.content_type_field = 'content_type'
self.object_id_field = "object_id"
self.content_type_field = "content_type"

def contribute_to_class(self, cls, name, private_only=False, **kwargs):
def contribute_to_class(
self,
cls,
name,
private_only=False,
**kwarg,
) -> None:
"""
...
"""
self.name = name
self.model = cls
ct_field = models.ForeignKey(ContentType, on_delete=models.CASCADE, limit_choices_to={
'model__in': ('ifcperson', 'ifcorganization', 'ifcpersonandorganization')
})
ct_field = models.ForeignKey(
ContentType,
on_delete=models.CASCADE,
limit_choices_to={
"model__in": (
"ifcperson",
"ifcorganization",
"ifcpersonandorganization",
),
},
)
fk_field = models.PositiveIntegerField()
cls.add_to_class(self.content_type_field, ct_field)
cls.add_to_class(self.object_id_field, fk_field)
actor = GenericForeignKey(self.content_type_field, self.object_id_field)
actor = GenericForeignKey(
ct_field=self.content_type_field, fk_field=self.object_id_field
)
cls.add_to_class(name, actor)

super().contribute_to_class(cls, name, private_only, **kwargs)
super().contribute_to_class(
cls=cls,
name=name,
private_only=private_only,
**kwargs,
)

def get_internal_type(self) -> Literal["IfcActorSelectField"]:
"""
...
"""
return "IfcActorSelectField"


# =============================================================================
# Export
# =============================================================================

def get_internal_type(self):
return 'IfcActorSelectField'
__all__: list[str] = [
"IfcActorSelectField",
]

0 comments on commit 1f4b786

Please sign in to comment.