Skip to content

link.group

GroupModel()

Bases: BipObject

Source code in client/bip/link/group.py
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
def __init__(self):
    super(GroupModel, self).__init__()
    self.uid: str = ""
    self.slug: str = ""

    self.name: str = ""
    self.type: str = ""
    self.local: bool = False
    self.root: str = ""

    self.plural: str = ""
    self.folder_name: str = ""
    self.code: str = ""
    self.unique_members: bool = True

    self.use_suffix: bool = False
    self.suffix_format: str = SUFFIX_NUM
    self.suffix_length: int = 0
    self.suffix_name_separator: str = ""
    self.suffix_folder_name_separator: str = ""
    self.default_suffix: str = ""

    self.folder_name_case_hint: str = ""
    self.name_case_hint: str = ""

    self.name_pattern: str = ""
    self.name_hint: str = ""
    self.force_name_pattern: str = ""

    self.folder_name_pattern: str = ""
    self.folder_name_hint: str = ""
    self.force_folder_name_pattern: str = ""

    self.ui_hints: list = []

    # Helpers
    self._project = None
    self._has_uniqueness_scope = False
    self._has_required_memberships = False
    self._has_optional_memberships = False
    self._has_limits = False

add_membership(group_model, required=True)

Adds a required or optional membership.

Tip

Required or optional memberships are GroupModel that any new Project created with the current ProjectModel must or can be member of in order to be saved.

Parameters:

Name Type Description Default
group_model GroupModel

GroupModel: GroupModel.

required
required

bool

True

Raises:

Type Description
ValueError

Failed validation.

TypeError

Failed validation.

Source code in client/bip/link/group.py
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
def add_membership(self, group_model: GroupModel, required=True):
    """Adds a required or optional membership.

    !!! tip
        Required or optional memberships are GroupModel that any new Project created with the current ProjectModel
        must or can be member of in order to be saved.

    Args:
      group_model: GroupModel: GroupModel.
      required: bool

    Raises:
        ValueError: Failed validation.
        TypeError: Failed validation.
    """
    if self.has_children:
        raise ValueError(
            "This GroupModel already has instances. You cannot modify its required memberships."
        )

    if not isinstance(group_model, GroupModel):
        raise TypeError("group_model must be a GroupModel object.")

    if group_model.is_floating:
        raise ValueError("group_model must be saved first.")

    if self.has_optional_memberships:
        optional_memberships = self.get_optional_memberships()
        if group_model in optional_memberships:
            raise ValueError(f"{group_model} is already an optional membership.")

    if self.has_required_memberships:
        required_memberships = self.get_required_memberships()
        if group_model in required_memberships:
            raise ValueError(f"{group_model} is already a required membership.")

    add_membership(self, group_model, required)

    if required:
        self._has_required_memberships = True
    else:
        self._has_optional_memberships = True

    self.save()