beaumartinez / osmosis

Osmosis is a simple Django application for importing files (e.g. CSVs) into a database on the Google AppEngine platform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Osmosis

Osmosis is a simple Django application for importing files (e.g. CSVs) into a database on the Google AppEngine platform

Basic usage

Settings

Add 'osmosis' to your INSTALLED_APPS

Model

In your project, subclass AbstractImportTask, add your forms, and other parameters if you need. Example::

from osmosis.models import AbstractImportTask, ModelImportTaskMixin

class ContactImportTask(ModelImportTaskMixin, AbstractImportTask):
    class Osmosis:
        forms = [
            'events.forms.ContactForm'  # This is standard django (model) form
        ]
        queue = deferred.deferred._DEFAULT_QUEUE
        generate_error_csv = True
        rows_per_shard = 100

Upload Form:

Create the form...

class ContactUploadForm(forms.ModelForm):
    class Meta:
        model = ContactImportTask

...and add it to the template with action parameter generated by

from google.appengine.ext.blobstore import create_upload_url
blobstore_upload_url = create_upload_url(reverse('my_app:upload'))  # use your view that will handle upload

HTML:

<form action="{{ blobstore_upload_url }}" method="POST" enctype="multipart/form-data">
	{% csrf_token %}
	{{ contact_upload_form }}
	<input type="submit" name="submit" value="Upload csv">
</form>

View:

This view is called after the file has been uploaded to blobstore. Very basic example:

def upload(request):
    if request.method == "POST":
        form = ContactUploadForm(request.POST, request.FILES)

        if form.is_valid():
            task = form.save(commit=False)

            task.start()
            return HttpResponse('Upload has started')
    else:
        return HttpResponse('Only POST please', status=400)

Installation dependencies

About

Osmosis is a simple Django application for importing files (e.g. CSVs) into a database on the Google AppEngine platform

License:MIT License


Languages

Language:Python 100.0%