Skip to content
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

[#4396] Objects API prefill plugin #4566

Closed
wants to merge 1 commit into from

Conversation

vaszig
Copy link
Contributor

@vaszig vaszig commented Jul 26, 2024

Closes #4396

Changes

Checklist

Check off the items that are completed or not relevant.

  • Impact on features

    • Checked copying a form
    • Checked import/export of a form
    • Config checks in the configuration overview admin page
    • Problem detection in the admin email digest is handled
  • Release management

    • I have labelled the PR as "needs-backport" accordingly
  • I have updated the translations assets (you do NOT need to provide translations)

    • Ran ./bin/makemessages_js.sh
    • Ran ./bin/compilemessages_js.sh
  • Commit hygiene

    • Commit messages refer to the relevant Github issue
    • Commit messages explain the "why" of change, not the how

@vaszig vaszig marked this pull request as draft July 26, 2024 14:07
@stevenbal stevenbal self-assigned this Jul 29, 2024
@stevenbal stevenbal removed their assignment Aug 22, 2024
@vaszig vaszig force-pushed the task/4396-objectsapi-prefill-plugin branch from 5ea6f6c to 31caea8 Compare August 22, 2024 14:42
@vaszig vaszig force-pushed the task/4396-objectsapi-prefill-plugin branch from 31caea8 to a912c98 Compare August 22, 2024 14:43
Copy link
Contributor

@stevenbal stevenbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vaszig looked over the code briefly, from what I can see I think it's going in the right direction 👍

Comment on lines +93 to +118
class PluginObjectsAPIObjecttypeListView(ListMixin, APIView):
"""
List the available prefill objecttypes for Objects API plugin.
"""

authentication_classes = (authentication.SessionAuthentication,)
permission_classes = (permissions.IsAdminUser,)
serializer_class = PrefillObjectsAPIObjecttypeSerializer

def get_objects(self) -> list[dict[str, Any]]:
input_serializer = ObjectsAPIGroupInputSerializer(
data=self.request.query_params
)
input_serializer.is_valid(raise_exception=True)

config_group = input_serializer.validated_data["objects_api_group"]

with get_objecttypes_client(config_group) as client:
return client.list_objecttypes()


@extend_schema_view(
get=extend_schema(summary=_("List available objecttype versions for Objects API")),
parameters=[OBJECTS_API_GROUP_QUERY_PARAMETER],
)
class PluginObjectsAPIObjecttypeVersionListView(ListMixin, APIView):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of these views do already seem to exist for registrations, so we might be able to use those instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I can use them as the base class and have the new one here for the different urls as well. I guess you mean I have to do the same for the serializers since some of them are the same with the ones in registrations.

permission_classes = (permissions.IsAdminUser,)
serializer_class = PrefillObjectsAPIAttributeSerializer

def get_objects(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method should return a list of tuples with each a label and value (e.g. choices)?

EDIT: I just saw parse_schema_properties and that returns a list of tuples, so I think that's right

from django.utils.translation import gettext_lazy as _


class ObjectsAPIAttributes(models.TextChoices):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we'll need this, this was probably from your initial changes that you made before? @vaszig

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, probably not

@vaszig
Copy link
Contributor Author

vaszig commented Aug 23, 2024

FYI @stevenbal , as we discussed with Sergei during standup, I will split this PR in order to be easier for you as well. So I will close this and I will create 2 new ones.

@vaszig vaszig closed this Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a prefill plugin to prefill with values from an external reference (initially only for Objects API)
2 participants