piccolo_admin icon indicating copy to clipboard operation
piccolo_admin copied to clipboard

add enum support to custom forms

Open sinisaos opened this issue 10 months ago • 13 comments

An alternative approach to #434 . It uses Piccolo choices without complex parsing definitions in the Vue frontend.

sinisaos avatar Jan 25 '25 13:01 sinisaos

:warning: Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 94.24%. Comparing base (1157c12) to head (3cb1f9a). :warning: Report is 47 commits behind head on master. :exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #436      +/-   ##
==========================================
+ Coverage   93.42%   94.24%   +0.81%     
==========================================
  Files           5        6       +1     
  Lines         365      417      +52     
==========================================
+ Hits          341      393      +52     
  Misses         24       24              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov-commenter avatar Jan 25 '25 13:01 codecov-commenter

@Skelmis I can't add you as a reviewer, but I'm interested in your thoughts on this approach of using Python enums in custom forms. Thanks in advance.

sinisaos avatar Jan 27 '25 07:01 sinisaos

It looks like a much simpler implementation which I love. I'll try test it out within a week

Skelmis avatar Jan 28 '25 00:01 Skelmis

@Skelmis Great. Thanks

sinisaos avatar Jan 28 '25 06:01 sinisaos

@Skelmis Thank you for your time to try this out.

Do you think it'd be possible to try return Enum items as the relevant enum in this case? Or should users do the enum conversion themselves

Yes, you are right. I think the easiest way, as you say, is for users to do the enum conversion themselves. Something like this

def new_staff_endpoint(request: Request, data: NewStaffModel) -> str:
    # data.permissions = Permission(int(data.permissions)) # for int enum
    data.permissions = Permission(data.permissions) # for str enum
    print(type(data.permissions)) # prints correct type <enum 'Permission'>
    return "A new staff member has been successfully created."

sinisaos avatar Feb 01 '25 12:02 sinisaos

Seems reasonable for me. Thoughts @dantownsend ?

Skelmis avatar Feb 01 '25 12:02 Skelmis

Hrmm perhaps just realised we should likely add docs haha. Will see if I find time sometime to try write some up

Skelmis avatar Mar 26 '25 07:03 Skelmis

@Skelmis Yes, you are right, but I don't see the point of writing docs because PR is not reviewed or accepted. We can add a usage example to the docs later, if PR is accepted.

sinisaos avatar Mar 26 '25 07:03 sinisaos

Fair enough

Skelmis avatar Mar 26 '25 08:03 Skelmis

@dantownsend what's your view on this pr? Docs before pr, or pr then docs on approved content?

Either way keen to get this moving, would love this feature

Skelmis avatar Apr 04 '25 08:04 Skelmis

This PR has been marked as stale because it has been open for 30 days with no activity. Are there any blockers, or should this be closed?

github-actions[bot] avatar May 07 '25 02:05 github-actions[bot]

@dantownsend what's your view on this pr? Docs before pr, or pr then docs on approved content?

Either way keen to get this moving, would love this feature

@dantownsend waiting on your response to move this PR forward

Skelmis avatar May 07 '25 02:05 Skelmis

Sorry for the delay on this. I was torn about which approach to take:

  1. Should we make our front end understand the refs in the OpenAPI schema.
  2. Should we add the extra attributes (like this in this PR).

There was also some discussion about not using OpenAPI schemas any more to drive the front end (because Litestar doesn't allow the extra attributes).

This PR might be the best approach for now though.

dantownsend avatar May 22 '25 08:05 dantownsend

This PR has been marked as stale because it has been open for 30 days with no activity. Are there any blockers, or should this be closed?

github-actions[bot] avatar Jul 10 '25 03:07 github-actions[bot]

This PR has been marked as stale because it has been open for 30 days with no activity. Are there any blockers, or should this be closed?

github-actions[bot] avatar Aug 31 '25 02:08 github-actions[bot]

@dantownsend do you have any updates regarding this PR? Is it blocked as a result of technical basis or more so just personal time constraints

Skelmis avatar Sep 01 '25 04:09 Skelmis

This PR has been marked as stale because it has been open for 30 days with no activity. Are there any blockers, or should this be closed?

github-actions[bot] avatar Oct 07 '25 02:10 github-actions[bot]