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

Document ObjectRow for Plugins usage #287

Closed
edmondop opened this issue Mar 16, 2021 · 4 comments
Closed

Document ObjectRow for Plugins usage #287

edmondop opened this issue Mar 16, 2021 · 4 comments

Comments

@edmondop
Copy link

We are trying to implement a more complex use case than the summation plugin: we need to return a collection of objects that have their sum of field field_1 equal to a certain amount and the sum of field field_2 equal to another amount.

I imagine this can be done using a plugin that returns ObjectRow like so, but this is not clear nor documented, has anyone done anything like that?

https://gist.github.com/edmondo1984/d3219e93edb38b987fd927f274162a85

 

@prescod
Copy link
Contributor

prescod commented Mar 21, 2021

It's a bit hard for me to give you very crisp advice because your use case is still slightly fuzzy for me, but in general I'd say:

  1. Yes the plugin is stateful but you need to use attributes on the "self" variable to manipulate its state. So it would be more like self._index +=1

  2. There is another grouping object which is probably more appropriate than an ObjectRow, which is a PluginResult. You could return a small PluginResult subclass that has values total_field_1 and total_field_2.

  3. Actually you probably don't even need a subclass. There is a short-cut for making simple PluginResults.

return PluginResult({"a": "b"})

Then if you assign that object to __foo you can refer to __foo.a to get b.

Does that help?

I'll leave the issue open because there are still some gaps in documentation.

@edmondop
Copy link
Author

I am a little confused, how would I return a different element each time? Can you explain the difference between ObjectRow and PluginResult?

@prescod
Copy link
Contributor

prescod commented Mar 21, 2021

If you could write what you want as a Python program (not a plugin) that just prints out the values you want, then I could help you transform it into a plugin.

@prescod
Copy link
Contributor

prescod commented May 5, 2023

#777 feature might meet your needs.

@prescod prescod closed this as completed May 5, 2023
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

No branches or pull requests

2 participants