Esempio n. 1
0
def try_add_realm_default_custom_profile_field(
        realm: Realm, field_subtype: str) -> CustomProfileField:
    field_data = DEFAULT_EXTERNAL_ACCOUNTS[field_subtype]
    custom_profile_field = CustomProfileField(
        realm=realm,
        name=field_data["name"],
        field_type=CustomProfileField.EXTERNAL_ACCOUNT,
        hint=field_data["hint"],
        field_data=orjson.dumps(dict(subtype=field_subtype)).decode(),
    )
    custom_profile_field.save()
    custom_profile_field.order = custom_profile_field.id
    custom_profile_field.save(update_fields=["order"])
    notify_realm_custom_profile_fields(realm)
    return custom_profile_field
Esempio n. 2
0
def try_add_realm_custom_profile_field(
    realm: Realm,
    name: str,
    field_type: int,
    hint: str = "",
    field_data: Optional[ProfileFieldData] = None,
) -> CustomProfileField:
    custom_profile_field = CustomProfileField(realm=realm, name=name, field_type=field_type)
    custom_profile_field.hint = hint
    if (
        custom_profile_field.field_type == CustomProfileField.SELECT
        or custom_profile_field.field_type == CustomProfileField.EXTERNAL_ACCOUNT
    ):
        custom_profile_field.field_data = orjson.dumps(field_data or {}).decode()

    custom_profile_field.save()
    custom_profile_field.order = custom_profile_field.id
    custom_profile_field.save(update_fields=["order"])
    notify_realm_custom_profile_fields(realm)
    return custom_profile_field