#django

/

      • newdimension has quit
      • netheranthem has quit
      • theology is now known as asceticism
      • brandonw has quit
      • srnagappan
        FunkyBob: thank you! it seems to work now. how do tell if the login was successful or rejected? it only sends back a template
      • FunkyBob
        srnagappan: well, either it sends a 200 to mean you failed, or a 301 to mean you succeeded
      • that's what an API-specific login is perferable
      • brandonw joined the channel
      • adamsilver
        Any idea why the file being downloaded is corrupt here: https://bpaste.net/show/680028f68fa1 ... I tried to update the answer here to Python 3: https://stackoverflow.com/questions/25364711/
      • jhfisc joined the channel
      • dang`r`us
        define corrupt? can you put it somewhere?
      • exaroth joined the channel
      • CAPITANOOO joined the channel
      • jhfisc has quit
      • adamsilver
      • srnagappan
        FunkyBob: how do i get the status code from the promise?
      • FunkyBob
      • bayman joined the channel
      • busla joined the channel
      • busla has quit
      • srnagappan
        does fetch work differently than promise.resolve(ajax)?
      • adamsilver
        dang`r`us: here it is with the imports https://bpaste.net/show/71dac266b995
      • srnagappan
        i get undefined for response.status
      • dang`r`us
        adamsilver, hm, that file is full of numbers. I have an idea ...
      • adamsilver
        yeah, not sure why
      • FunkyBob
        srnagappan: yes, yes it's different... since $.ajax is jquery... fetch is a native API
      • dang`r`us
        adamsilver, yeah, it looks like something is converting the bytes of your file to a decimal representation. at least it starts with the decimal number 31, which seems to indicate a gzip file when converted to binary
      • adamsilver, shot in the dark but try passing json_file instead of json_file.getvalue() to StreamingHttpResponse
      • bayman has quit
      • adamsilver
        dang`r`us: same problem but now the file inside is empty
      • dang`r`us
        adamsilver, probably need to seek it back to zero before streaming it out
      • stridebird has quit
      • I gotta say though, if you write the whole gzip beforehand anyway, a streaming response seems somewhat weird to me
      • adamsilver
        dang`r`us: now even the outer file is empty
      • dang`r`us
        adamsilver, show most current code?
      • adamsilver
      • rainierman joined the channel
      • rainierman
        hello everyone, pop quiz!
      • hamub has quit
      • b00tstr4p has quit
      • is there a way to set attrs to all fields in a form in one fell swoop? Not one by one?
      • dang`r`us
        adamsilver, hm ... my io knowledge is a bit rusty. what do you mean with outer file though?
      • wait ... file inside is empty means you got a working gzip?
      • let's take it from there.
      • adamsilver, can you go back one step and send me an empty but valid gzip file (if that's what your code did actually create?)
      • FunkyBob
        rainierman: nope.. just iterate over self.fields.items() in form.__init__
      • adamsilver
        dang`r`us: sorry, I meant the .cpgz inside is 0 bytes in size
      • rainierman
        that works! Thank you FunkyBob
      • dang`r`us
        adamsilver, what is a cpgz? and inside _what_?
      • jessamynsmith has quit
      • adamsilver
        dang`r`us: I get it when I extract the downloaded file and keep getting a new one when I try to extract it
      • dang`r`us: I think the problem is here gzip_handler.write(json_string) ... if I leave it like the original code in SO, I get: memoryview: a bytes-like object is required, not 'str'
      • FunkyBob
        py3?
      • dang`r`us
        adamsilver, yeah to get bytes you must encode
      • adamsilver
        yes
      • FunkyBob
        json_string.encode('utf-8')
      • dang`r`us
        your_string.encode()
      • yeah, being explicit about utf-8 is good.
      • adamsilver
        same issue
      • busla joined the channel
      • FunkyBob
        code and traceback, please?
      • busla has quit
      • XofP has quit
      • adamsilver
        +FunkyBob: https://bpaste.net/show/71dac266b995 -- no errors
      • the file is corrupted
      • dang`r`us
        adamsilver, anyway, when you implement my first change, you get a working gzip file but its content is bananas/empty, yes? can you upload such a file somewhere please?
      • FunkyBob
        what if you use a FileResponse instead?
      • adamsilver
        dang`r`us: the file gets downloaded with my code and after your changes as well but when extracted I get "activities.json.gz.cpgz" and when I click activities.json.gz.cpgz I get another activities.json.gz.cpgz and so one
      • dang`r`us
        adamsilver, I still want that file.also - like FunkyBob said and I hinted at earlier, a streaming response is not very useful here, try a FileResponse
      • or remove the .getvalue() at least
      • I think ...
      • also, where did that .cpgz come from? Not from your code snippet I take it
      • hamub joined the channel
      • FunkyBob
        so you explicitly want to send a compressed file... not rely on transport encoding?
      • adamsilver
        +FunkyBob: response = FileResponse(json_file) gives an empty response
      • dang`r`us
        good point FunkyBob
      • adamsilver, the plus is not part of FunkyBob's nickname
      • it indicates a certain permission status with respect to the channel
      • brandonw joined the channel
      • adamsilver
        Oh ok :)
      • FunkyBob: all I want is to send the gzipped file to the client without killing the server
      • I thought StreamingHttpResponse would help with that
      • FunkyBob
        it would if oyu had a streaming encoder
      • miz- joined the channel
      • dang`r`us
        adamsilver, if you create a huge blob before streaming it out (.getvalue()) it's not going to do much good
      • also what FunkyBob said
      • how huge are we talking here? is this an actual performance bottleneck or a guess?
      • FunkyBob
        IME BytesIO etc tend to be either readable or writable... so... HttpResponse(json_file.getvalue()....) is the way to go
      • bkxd_ has quit
      • adamsilver
      • just a guess
      • dang`r`us
        that is empty... also not a .cpgz file
      • wreed
        i just renamed an app (didnt have anything in my database yet so not worried about that) and renamed everything in settings and what not, but i am getting a ModuleNotFoundError on the apps file in the app i renamed
      • FunkyBob
        wreed: did you update the name in the AppConfig ?
      • dang`r`us
        wreed, any pyc files or similar around?
      • wreed
        error: ModuleNotFoundError: No module named 'profile.apps'; 'profile' is not a package
      • i updated AppConfig
      • what are pyc files?
      • __pycache__?
      • FunkyBob
        yes
      • what did you rename from and to?
      • Biwaa joined the channel
      • wreed
        renamed from userprofile to just profile
      • there is a __pycache__ folder in my app
      • should i delete that file?
      • dang`r`us
        wreed, hmm, seems the problem is you didn't rename it properly
      • wreed
        yeah i am trying to fix it
      • CAPITANOOO has quit
      • i definately renamed my installed apps and the stuff in the apps file
      • dang`r`us
        yeah maybe nuke __pycache__ then
      • busla joined the channel
      • there's a command for that I think
      • jtiai^ joined the channel
      • hm, not really.
      • wreed
        nuked it
      • dang`r`us
        wreed, go to your project root and type: find . -regex "\(.*__pycache__.*\|*.py[co]\)" -delete
      • wreed
        still the same thing hm
      • Biwaa has quit
      • i just used somethig similar
      • dang`r`us
        ok
      • wreed
        but still the same error
      • hamub has quit
      • where else could some information be cached?
      • dang`r`us
        wreed, check __init__.py
      • busla has quit
      • what's in there?
      • I mean, profile/__init__.py
      • wreed
        its blank
      • as are all my other __init__.py's
      • dang`r`us
        odd
      • wreed
        is it not supposed to be blank
      • ?
      • dang`r`us
        naw, should be fine
      • bkxd joined the channel
      • wreed
        https://dpaste.de/34HV full error if it makes a difference
      • jtiai^ has quit
      • dang`r`us
        and your directory is called profile?
      • wreed
        yes
      • dang`r`us
        no idea then.
      • FunkyBob
        can you import profile in a manage.py shell ?
      • I guess it errors out :/
      • wreed
        no i cannot do that
      • ye errors there
      • FunkyBob
        remove it from INSTALLED_APPS and try then
      • wreed
        ok so when doing that the console starts up fine but when importing it, it says: 'RuntimeError: Model class profile.models.Profile doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.'
      • FunkyBob
        expected... what did oyu import?
      • wreed
        a model from profile.models
      • FunkyBob
        what import line did you type in?
      • wreed
        from profile.models import Profile
      • FunkyBob
        what happens if you just do "import profile" ?