-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interval field #573
base: main
Are you sure you want to change the base?
Interval field #573
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi thank you for the PR, l left some few comments.
Also can we add a converter for Interval in sqlalchemy and timedelta for Odmantic
@@ -0,0 +1,33 @@ | |||
<div class="{% if error %}{{ field.error_class }}{% endif %}"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer a view like Dimension in this form https://starlette-admin-demo.jowilf.com/admin/mongoengine/product/create. You can copy form https://github.com/jowilf/starlette-admin/blob/main/starlette_admin/templates/forms/collection.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, I'm not sure what to do with these converters..what do they do? I just mimic'd the "Time" one:
@converts("Interval")
def conv_interval(self, *args: Any, **kwargs: Any) -> BaseField:
return IntervalField(
**self._field_common(*args, **kwargs),
)
Is that it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's it. The converter's role is to automatically find the appropriate field for each attribute. For SQLAlchemy, it uses the attribute type. Think of it as a map between the attribute type and the corresponding field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the pr.
# Conflicts: # starlette_admin/templates/displays/interval.html
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks good just some minor comments
@@ -18,10 +18,16 @@ | |||
Union, | |||
) | |||
|
|||
from babel.dates import format_timedelta |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to make this optional and require it only when using the Interval field. here is an example:
starlette-admin/starlette_admin/fields.py
Line 863 in 5b183e0
if not arrow: # pragma: no cover |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example is not clear to me. Is the arrow
package only imported when using the ArrowField
? Looks more like the user cannot use the arrow field if the import fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the user is not able to use it if the import fails, but they are required to install it before using the field. The idea is to make the arrow package optional, so users who don't want to use ArrowField are not forced to install it.
), | ||
granularity="second", | ||
threshold=1, | ||
locale="en", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function returns the current user locale
locale="en", | |
locale=get_locale(), |
def conv_bson_datetime(self, *args: Any, **kwargs: Any) -> BaseField: | ||
return IntervalField(**self._standard_type_common(**kwargs)) | ||
|
||
@converts(odmantic.bson) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@converts(odmantic.bson) | |
@converts(odmantic.bson._datetime) |
# Conflicts: # starlette_admin/fields.py
@converts("timedelta") | ||
def conv_bson_timedelta(self, *args: Any, **kwargs: Any) -> BaseField: | ||
return IntervalField(**self._standard_type_common(**kwargs)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems odmantic does not support timedelta art049/odmantic#120, we can remove this and just keep for sqlalchemy
@jowilf looks like the version of Either adding this to the - autorefs:
resolve_closest: false` or bumping the Lets build the docs but gives a bunch of warnings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR, @regisin. I'll look into the mkdocs issue later, as it’s not related to the changes you've made.
Handles #572