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

Created a function to get submission photo by its submission id #284

Merged
merged 4 commits into from
Aug 27, 2024

Conversation

Sujanadh
Copy link
Contributor

@Sujanadh Sujanadh commented Aug 9, 2024

Updates:

This PR updates the OdkCentral creating a new function getSubmissionPhoto to get the photo content from the individual submission.

  • it taskes parameters such as odk project id, submission id(instance id) , xform(form id), filename (name of photo file)
  • it fetches the media content in bytes which can be used directly to download or upload anywhere.

Copy link
Member

@spwoodcock spwoodcock left a comment

Choose a reason for hiding this comment

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

It would be really nice if this included a test too 😁

But not essential if it will take lots of time 👍

if result.status_code == 200:
log.debug(f"fetched {filename} from Central")
else:
status = eval(result._content)
Copy link
Member

Choose a reason for hiding this comment

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

It's generally a bad idea to use eval in Python - there is almost always a better way!

Also accessing a private method is generally bad too.

Can this be achieved using .json() or another method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In getMedia func too eval was used, so I thought to use the same, but you are right, eval is not always a safe option. will refactor for both functions.

@Sujanadh
Copy link
Contributor Author

It would be really nice if this included a test too 😁

But not essential if it will take lots of time 👍

how to use dummy submission photo?

@spwoodcock
Copy link
Member

spwoodcock commented Aug 12, 2024

It would be really nice if this included a test too 😁

But not essential if it will take lots of time 👍

how to use dummy submission photo?

You could possibly just upload some known bytes, not an actual photo:

b'fakephotodata'

I assume uploading this with a jpg extension would work and would be lightweight (unless Central has a check to see if it's an actual image!)

Then when you check the download data, assert photo_data == b'fakephotodata'

Of course, the alternative is to include an actual (lightweight) .jpg file in the testdata!

@spwoodcock
Copy link
Member

Tests aren't essential here, just a nice to have!

We can merge this - bump to remind myself!

@Sujanadh
Copy link
Contributor Author

thanks for reminding!

@spwoodcock
Copy link
Member

I'll merge this for the next release 👍

If we have tests in future, they don't need to be in a release, just present on main, so they can come later

osm_fieldwork/OdkCentral.py Outdated Show resolved Hide resolved
@spwoodcock spwoodcock merged commit b886e02 into main Aug 27, 2024
4 of 5 checks passed
@spwoodcock spwoodcock deleted the feat/getSubmissionPhoto branch August 27, 2024 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants