0

I'm working on a project that's in the process of migrating from Django 1.3 to Node/Backbone.js

Consequently, I'm working with two sets of views. I have a function for validating and processing images to be uploaded via a form, written in Python using PIL, that was originally designed for use in the Django views; however, the view that handles forms has since been migrated to Backbone.

I don't expect it to be an optimal solution, but for the sake of expediency I wondered if there's a way to call this as a standalone Python script (just to do the image processing) within the Backbone form view?

The crux of the problem is that the new JavaScript view is updating the database via PUT, whereas the original Django code used POST. I'm trying to avoid using two separate views on the same form and commingling the two methods, since the JavaScript view is perfectly capable of handling the file upload itself; however, I would like to avoid having to rewrite the imaging script using a new library.

From looking at some other threads, it seems that making an AJAX request might be the way to go, e.g. something along these lines, but the only examples I've found use jQuery, whereas I feel like there should be a similar way of doing it using Backbone's built in AJAX functionality.

double-beep
  • 5,031
  • 17
  • 33
  • 41
  • It's a little hard to tell exactly what's going on from your description. But, I don't think you're going to be able to just call "python view.py" Assuming you are just going to move the processing code to a different file, then I would guess so. Assuming that you can create processes with JS (I don't know about that). If that's not possible you could probably set up a queue and have your JS just push it onto it and have python pull messages off and process the images that way. Again, you might want to give a bit more detail and someone a lot smarter than me can probably help you! :) – David S Jan 21 '13 at 00:52
  • Thanks for the feedback @DavidS. I went ahead and added a bit more detail, without subjecting people to the Frankenstein code I'm working with. I think I should be able to handle the process with JS using AJAX, but I'm curious as to your second suggestion. I'm not quite sure what such a queue-based implementation would look like. Could you possibly elaborate? – BaroqueEcstasy Jan 21 '13 at 02:12
  • I've reviewed your comments and edits. Thanks. Image processing and video encoding, etc are usually good candidates for setting up a queue. Basically, you would take the uploaded file and store it somewhere. A very AWS-centric solution might be to store the file on S3 and then push a message into a SQS queue. Very common to just use JSON as the datatype. But, you could make it as simple as just a string of the S3 bucket and keyname. Then have 1:n number of EC2 servers with your python script running pulling the work off the queue and process. Google "Python SQS Boto Examples". – David S Jan 21 '13 at 02:33
  • One more note about doing this with a Queue. These tend to be popular for "intensive" operations where you don't want to make your user wait... and of course, they scale well. Because if your queue is getting bigger, then just launch another few EC2 server instances to knock it back down. You don't say how CPU or memory intensive what you are doing here, or what kind of load you are under. But, it is a definite advantage. – David S Jan 21 '13 at 02:37

0 Answers0