Saturday, June 8, 2013

File locations on azure

Spent the last few days getting everything working in azure with correct folder permissions and so on, leaning heavily on stack overflow for hints. First I found that the templates didn't work in azure because I hardcoded the template locations to c:\users\jafitzge…, had to figure out how to put a location that would work in both the dev and production environments

Then I got permissions errors trying to write my result files and debug files
[Errno 2] No such file or directory: 'SampleData2.csv'
[Errno 13] Permission denied: 'scheduledebug10.log'

I tried looking up azure debugging options to see if there was a standard location for log files, etc. is only about .net logging options apparently? is promising, how do I write to a file in python on azure? Answer leads to which talks about using the Azure Managed Library to access Local Resources. suggested I needed to change from writing to the current working directory, and instead write to the module directory.  Locally the file is at C:\Users\...\SimplySchedule which is PROJECT_PATH.

Finally fixed all the file permission issues by using the correct folders, and extracted the file path calculations to a couple functions so I could be sure I was doing it the same way everywhere.

Now working on serving the saved schedule file as a download, which seems like should be done using the MEDIA settings. Checking out the django docs again at means I should change the file save location from

import os.path
BASE = os.path.dirname(os.path.abspath(__file__))

>>> from import default_storage
>>> from django.core.files.base import ContentFile
>>> path ='/path/to/file', ContentFile('new content'))

This implies I should be saving my debug files to STATIC, not media - that makes sense!

Also looks interesting for when I create an actual model for all the data I'm throwing around: saving an uploaded file as a model:

Now I tried creating public facing 404 and 500 templates and setting Debug=False but it didn't seem to have taken hold when I deployed, although it was working as expected locally.  However when I went back to look at it again a couple hours later it was working as expected. Possibly just a caching issue. 

So, current state - I have all the functionality requested available,  although the site itself looks ugly as hell and super amateur. Still waiting for dad to go check it out and give some feedback, and until then it's time to get some PAX Aus app preparation done.