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

request MUST be declared for serializer #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

request MUST be declared for serializer #3

wants to merge 3 commits into from

Conversation

theromis
Copy link
Contributor

@theromis theromis commented Feb 3, 2016

No description provided.

@theromis
Copy link
Contributor Author

does anybody care about pull requests?

@dessibelle
Copy link
Owner

dessibelle commented Oct 19, 2016

Hi @theromis, I apologise for the monumental delay. And thanks for contributing!

Apart from being busy at work I've been putting off a few housekeeping tasks on this project such as tests and PyPI packaging for way too long, which is why I have not been able to focus on your PR until now.

I have a couple of minor questions regarding your changes, I'll add them in the code.

Also, If you like to elaborate a little on the use case for this that would be greatly appreciated as it's not 100% clear to me at this moment.

)

if self.uri_prefix:
return request.build_absolute_uri(self.uri_prefix + image.url)
Copy link
Owner

Choose a reason for hiding this comment

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

Is uri_prefix (and settings.URI_PREFIX) meant to for a path component or a complete URL, or both? I guess build_absolute_uri() would handle both.

I think I would prefer something like

from urllib.parse import urljoin
urljoin(self.uri_prefix, image.url)

or even os.path.join(self.uri_prefix, image.url) though.

except AttributeError: # NOQA
return super(HyperlinkedSorlImageField, self).to_native(image.url) # NOQA
request = self.context.get('request', None)
assert request is not None, (
Copy link
Owner

Choose a reason for hiding this comment

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

Not sure how this would fare with existing usage as the current implementation attempts to use FileField.to_representation() behaviour (i.e. relative path to image) as a fallback. Up until now I've let to_representation() fail silently (which admittedly is not always the best option) but this introduces a potential AssertionError.

While I'm not too afraid of breaking changes at this stage I think it's worth some consideration. Perhaps this behaviour should only be triggered by a specific option?

@@ -65,6 +66,7 @@ def __init__(self, geometry_string, options={}, *args, **kwargs):
""" # NOQA
self.geometry_string = geometry_string
self.options = options
self.uri_prefix = uri_prefix
Copy link
Owner

Choose a reason for hiding this comment

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

A corresponding entry in the Args: list above would be nice ☺️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean you don't like settings usage here?

Copy link
Owner

Choose a reason for hiding this comment

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

Sorry that's a bit unclear now that I read it myself. I just meant I'd like an the docstring above, under the Args heading.

@dessibelle dessibelle mentioned this pull request Nov 17, 2016
@theromis
Copy link
Contributor Author

theromis commented Nov 17, 2016

but what we will gonna do with this stuff?
here uri_prefix too, I have to get rid of them.

what do you think about the rest of this PR?

@dessibelle
Copy link
Owner

Copying some of the thoughts from #5 (comment), I think you could sum up my thoughts at the moment with:

As I mentioned here HyperlinkedSorlImageField attempts to handle to_representation() transparently, in the regard that it attempts to find a sorl generated thumbnail and builds the URL from that. In case it fails, it should fallback to the default rest_framework.serializers.ImageField behaviour. This PR appears to break that by requiring request if I interpret the code correctly.

In large part I don't really understand why request is needed, as explicitly requiring (and raising if it's missing) breaks the fallback to rest_framework.serializers.ImageField.to_representation() which doesn't
rely on request.build_absolute_uri(). This is by design and something I'm not willing to let go without discussion. The current implementation does in deed try to take advantage of request if available, but can still function without it.

The same goes for url_prefix kwarg/setting which I'm not convinced is within the scope of sorl-thumbnail-serializer-field. Off the top of my head I'd say URL settings is better handled by other parts of the Django stack, and should ideally just work given that the ImageField and its corresponding serialiser is correctly setup. Please add a clear and reproducible description of your use case and solution to the PR description, and I think it'll be clearer what the intention is.

Also, tests are failing and should probably be fixed before merging :)

@theromis
Copy link
Contributor Author

I will remove url_prefix in next commit.

You think having fqdn as an required output is wrong? I think the current logic should have something like parameter to choose full/partial URL to get, because you may expect that you will get fqdn but hard to understand why it gives you relative path, and the reason just because you forgot to pass the request how was in my case, I've spent couple hours debugging the reason.

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.

2 participants