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

Using 'raw' without using 'save' gives no output #8

Closed
sharifanani opened this issue May 22, 2018 · 6 comments
Closed

Using 'raw' without using 'save' gives no output #8

sharifanani opened this issue May 22, 2018 · 6 comments

Comments

@sharifanani
Copy link

sharifanani commented May 22, 2018

I think the title explains it all.

If I try to use .raw to server an SVG barcode without using .save first, I get an empty output...

Example:
Trying to serve this in my django project:

class APIBarcode(View):

    def get(self, request, *args, **kwargs):
        uuid = request.GET.get('uuid')
        C39 = barcode.get_barcode_class('code39')
        toserve = C39(uuid)
        toserve.save('c39code')
        return HttpResponse(toserve.raw, content_type="image/svg+xml")

Gives the following output:
image

But serving this:

class APIBarcode(View):

    def get(self, request, *args, **kwargs):
        uuid = request.GET.get('uuid')
        C39 = barcode.get_barcode_class('code39')
        toserve = C39(uuid)
        # toserve.save('c39code')
        return HttpResponse(toserve.raw, content_type="image/svg+xml")

Gives the following output:

image

If someone can point me to where I should be looking I would gladly attempt to fix it!

@WhyNotHugo
Copy link
Owner

WhyNotHugo commented May 22, 2018

You probably want the render method, rather than raw:

def get(self, request, *args, **kwargs):
    uuid = request.GET.get('uuid')
    C39 = barcode.get_barcode_class('code39')
    toserve = C39(uuid)
    return HttpResponse(toserve.render(), content_type="image/svg+xml")`

@sharifanani
Copy link
Author

sharifanani commented May 22, 2018

@WhyNotHugo .render() method 'requires' a positional argument (which I did not get how to specify from the docs), .render attribute gives the same empty result as I showed previously

UPDATE
Found the correct documentation here.

I did notice that the default should be None as shown in the declaration, but it doesn't seem to let the function execute correctly. Should I update the SVG writer to use {'compress: False} by default? I am a big fan of the library and would like to contribute

@WhyNotHugo
Copy link
Owner

raw is actually an ugly side effect of poor code (it's actually removed in the latest master, and was actually buggy).

I'm thinking about reintroducing a raw property, which returns the raw barcode properly (rather than write it) for situations like this.

@sharifanani
Copy link
Author

I can take a shot at that if you'd like!

@WhyNotHugo
Copy link
Owner

Give it a shot if you like; it'll be a while before I can address this myself.

@WhyNotHugo
Copy link
Owner

Given that render already returns the rendered barcode, and seems to suffer no limitations, I think it's okay to close this.

Don't hesitate to leave a reply if you consider there's something I might have overlooked here.

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