Package: django-import-export-stomp
Django Import Export StompTLDR: Django plugin for file import/export on top ofdjango-import-exportusingdjango-stomp.Table of ContentsTable of ContentsAboutCodebaseThe stackEngineering standardsCommit hooksGetting StartedPrerequisitesRunning example application with DockerTesting the application with DockerDocumentationBasic installationRunning the consumerSetting up importsSetting up exportHow to use upload with aws s3 presigned urlPerforming an importPerforming an exportSettingsCreditsAboutDjango Import Export Stomp is a django plugin that usesdjango-stompto import/export models to spreadsheet-like files (csv, xlsx, etc.).CodebaseThe stackThis application uses  at leastPython 3.8with at leastDjango 3.2.Engineering standardsCommit hooksCurrently we're usingpre-commit.
To configure it simply use the commands below.pipinstallpre-commit
pre-commitinstallThis will automatically lint the staged files using our project standard linters.Getting StartedThis section provides a high-level requirement & quick start guide.Prerequisitesdockerdocker compose:warning:We do not recommend developing the application without docker!:warning:Running example application with DockerClone the repository viassh, ie.git clone git@github.com:juntossomosmais/django-import-export-stomp.git.Simply runningdocker compose up --build exampleis enough to start runningdjango-import-export-stompon a exmaple with Docker.Testing the application with DockerIf you want to run the tests run:docker compose run integration-tests.To run the sonar analysis locally you can usedocker compose up -d sonar-clientand thendocker compose up -d sonar-cliDocumentationBasic installationInstall package:pip install django-import-export-stompAddimport_export_stompto yourINSTALLED_APPSin yoursettings.pyAddauthor.middlewares.AuthorDefaultBackendMiddlewareto yourMIDDLEWARE_CLASSESin yoursettings.pySetupdjango-stompRunning the consumerRunpython manage.py import_export pubsubto start processing messages from the queues.Setting up importsOn your settings.py add aIMPORT_EXPORT_MODELSvariable:fromimport_export_stomp.resourcesimportresource_importerIMPORT_EXPORT_STOMP_MODELS={"Name of your import":{"app_label":"fake_app","model_name":"FakeModel","resource":resource_importer("tests.resources.fake_app.resources.FakeResource"),# optional}}By default a dry run of the import is initiated when the import object is created. To instead import the file immediately without a dry-run set theIMPORT_DRY_RUN_FIRST_TIMEtoFalse.IMPORT_DRY_RUN_FIRST_TIME = FalseSetting up exportAs with imports, a fully configured example project can be found in theexampledirectory.Add aexport_resource_classesclassmethod to the model you want to export.@classmethoddefexport_resource_classes(cls):return{'winners':('Winners resource',WinnersResource),'winners_all_caps':('Winners with all caps column resource',WinnersWithAllCapsResource),}This should return a dictionary of tuples. The keys should be unique unchanging strings, the tuples should consist of aresource <https://django-import-export.readthedocs.io/en/latest/getting_started.html#creating-import-export-resource>__ and a human friendly description of that resource.Add thecreate_export_job_actionto the model'sModelAdmin.fromdjango.contribimportadminfromimport_export.admin_actionsimportcreate_export_job_actionfrom.importmodels@admin.register(models.Winner)classWinnerAdmin(admin.ModelAdmin):list_display=('name',)actions=(create_export_job_action,)To customise export queryset you need to addget_export_querysetto theModelResource.classWinnersResource(ModelResource):classMeta:model=Winnerdefget_export_queryset(self):"""To customise the queryset of the model resource with annotation override"""returnself.Meta.model.objects.annotate(device_type=Subquery(FCMDevice.objects.filter(user=OuterRef("pk")).values("type")[:1])Done!How to use upload with aws s3 presigned urlHaveboto3anddjango-storagesinstalled in your project:pip install boto3 django-storagesSetupdjango-storagesvariables -AWS_STORAGE_BUCKET_NAMEis required.SetIMPORT_EXPORT_STOMP_USE_PRESIGNED_POSTtoTrue.Add urls fromimport_export_stomp.urlsto yoururls.pyfromimport_export_stomp.urlsimporturlpatternsasimport_export_stomp_urlpatternsurlpatterns=[...]# Your urlsurlpatterns+=import_export_stomp_urlpatternsDone!Performing an importYou will find an example django application that uses django-import-export-stomp for importing data. Once you have it running, you can perform an import with the following steps.Navigate to the example applications admin page:Navigate to the ImportJobs table:Create a new import job. There is an example import CSV file in the example/example-data directory. Select that file. Select csv as the file format. We'll be importing to the Winner's model table.Select "Save and continue editing" to save the import job and refresh until you see that a "Summary of changes made by this import" file has been created.You can view the summary if you want. Your import has NOT BEEN PERFORMED YET!Return to the import-jobs table, select the import job we just created, and select the "Perform import" action from the actions drop down.In a short time, your imported Winner object should show up in your Winners table.Performing an exportPerform the basic setup procedure described in the first section.Open up the object list for your model in django admin, select the objects you wish to export, and select theExport with stompadmin action.Select the file format and resource you want to use to export the data.Save the modelYou will receive an email when the export is done, click on the link in the emailClick on the link near the bottom of the page titledExported file.SettingsIMPORT_EXPORT_STOMP_MODELSRequiredDict containing all the models that will be imported.{"Name of your import":{"app_label":"fake_app","model_name":"FakeModel","resource":resource_importer("tests.resources.fake_app.resources.FakeResource"),# optional -if not present will auto-create}}IMPORT_EXPORT_STOMP_STORAGEStorage class which import/export file field will use. Defaults toNone.
Example:storages.backends.s3boto3.S3Boto3StorageIMPORT_EXPORT_STOMP_EXCLUDED_FORMATSList of formats to exclude from import/export. Defaults to[].
Example:["csv", "xlsx"]IMPORT_EXPORT_STOMP_PROCESSING_QUEUEName of the stomp queue that will be used to publish/consume the messages. Defaults to/queue/django-import-export-stomp-runnerIMPORT_EXPORT_STOMP_USE_PRESIGNED_POSTEnables upload using presigned post url. Usesboto3anddjango-storages. Defaults toFalse.IMPORT_EXPORT_STOMP_PRESIGNED_POST_EXPIRATIONSets signed url expiration time. Defaults to600IMPORT_EXPORT_STOMP_PRESIGNED_FOLDERPrepends a path to the s3 key. Defaults to""Creditsdjango-import-export-stompwas based ondjango-import-export-celerydeveloped by the Czech non-profitauto*mat z.s..