Skip to content

Commit

Permalink
Add support for "manualSort" field type in ORM
Browse files Browse the repository at this point in the history
  • Loading branch information
mesozoic committed Aug 16, 2024
1 parent 7bc92a3 commit aeee55c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
6 changes: 4 additions & 2 deletions docs/source/orm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ read `Field types and cell values <https://airtable.com/developers/web/api/field
links = re.findall(r"`.+? <.*?field-model.*?>`", cls.__doc__ or "")
ro = ' 🔒' if cls.readonly else ''
cog.outl(f" * - :class:`~pyairtable.orm.fields.{cls.__name__}`{ro}")
cog.outl(f" - {', '.join(f'{link}__' for link in links) if links else '(see docs)'}")
cog.outl(f" - {', '.join(f'{link}__' for link in links) if links else '(undocumented)'}")
classes = sorted(fields.ALL_FIELDS, key=attrgetter("__name__"))
optional = [cls for cls in classes if not cls.__name__.startswith("Required")]
Expand Down Expand Up @@ -185,6 +185,8 @@ read `Field types and cell values <https://airtable.com/developers/web/api/field
- `Link to another record <https://airtable.com/developers/web/api/field-model#foreignkey>`__
* - :class:`~pyairtable.orm.fields.LookupField` 🔒
- `Lookup <https://airtable.com/developers/web/api/field-model#lookup>`__
* - :class:`~pyairtable.orm.fields.ManualSortField` 🔒
- (undocumented)
* - :class:`~pyairtable.orm.fields.MultipleCollaboratorsField`
- `Multiple Collaborators <https://airtable.com/developers/web/api/field-model#multicollaborator>`__
* - :class:`~pyairtable.orm.fields.MultipleSelectField`
Expand Down Expand Up @@ -257,7 +259,7 @@ See :ref:`Required Values` for more details.
- `Single line text <https://airtable.com/developers/web/api/field-model#simpletext>`__, `Long text <https://airtable.com/developers/web/api/field-model#multilinetext>`__
* - :class:`~pyairtable.orm.fields.RequiredUrlField`
- `Url <https://airtable.com/developers/web/api/field-model#urltext>`__
.. [[[end]]] (checksum: 131138e1071ba71d4f46f05da4d57570)
.. [[[end]]] (checksum: 43c56200ca513d3a0603bb5a6ddbb1ef)
Formula, Rollup, and Lookup Fields
Expand Down
12 changes: 11 additions & 1 deletion pyairtable/orm/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,14 @@ class LookupField(Generic[T], _ListField[T, T]):
readonly = True


class ManualSortField(TextField):
"""
Field configuration for ``manualSort`` field type (not documented).
"""

readonly = True


class MultipleCollaboratorsField(_ValidatingListField[CollaboratorDict]):
"""
Accepts a list of dicts in the format detailed in
Expand Down Expand Up @@ -1072,6 +1080,7 @@ class UrlField(TextField):
"LastModifiedByField",
"LastModifiedTimeField",
"ExternalSyncSourceField",
"ManualSortField",
}:
continue
Expand Down Expand Up @@ -1487,6 +1496,7 @@ class CreatedTimeField(RequiredDatetimeField):
"LastModifiedTimeField",
"LinkField",
"LookupField",
"ManualSortField",
"MultipleCollaboratorsField",
"MultipleSelectField",
"NumberField",
Expand Down Expand Up @@ -1523,7 +1533,7 @@ class CreatedTimeField(RequiredDatetimeField):
"FIELD_CLASSES_TO_TYPES",
"LinkSelf",
]
# [[[end]]] (checksum: 21316c688401f32f59d597c496d48bf3)
# [[[end]]] (checksum: 3ea404fb3814f0d053b93d3479ab5e13)


# Delayed import to avoid circular dependency
Expand Down
4 changes: 2 additions & 2 deletions pyairtable/orm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def from_id(
memoize: |kwarg_orm_memoize|
"""
try:
instance = cast(SelfType, cls._memoized[record_id])
instance = cast(SelfType, cls._memoized[record_id]) # type: ignore[redundant-cast]
except KeyError:
instance = cls(id=record_id)
if fetch and not instance._fetched:
Expand Down Expand Up @@ -421,7 +421,7 @@ def from_ids(
if cls._memoized:
for record_id in record_ids:
try:
by_id[record_id] = cast(SelfType, cls._memoized[record_id])
by_id[record_id] = cast(SelfType, cls._memoized[record_id]) # type: ignore[redundant-cast]
except KeyError:
pass

Expand Down
2 changes: 2 additions & 0 deletions tests/test_orm_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class Container(Model):
(f.LookupField, ["any", "values"]),
(f.CreatedByField, fake_user()),
(f.LastModifiedByField, fake_user()),
(f.ManualSortField, "fcca"),
# If a 3-tuple, we should be able to convert API -> ORM values.
(f.CreatedTimeField, DATETIME_S, DATETIME_V),
(f.LastModifiedTimeField, DATETIME_S, DATETIME_V),
Expand Down Expand Up @@ -402,6 +403,7 @@ class T(Model):
f.LastModifiedByField,
f.LastModifiedTimeField,
f.LookupField,
f.ManualSortField,
f.MultipleCollaboratorsField,
f.MultipleSelectField,
f.NumberField,
Expand Down

0 comments on commit aeee55c

Please sign in to comment.