Package: django-collect-offline
django-collect-offlineDeploy a Django app as a client on laptop that is offline and push the data to your server when you get back online.InstallationAdd the pattern for access to the REST API:urlpatterns=[url(r'^django-collect-offline/',include('django_collect_offline.urls')),)In settings.py:INSTALLED_APPS=[...'django_collect_offline.apps.AppConfig',...]Configure a model for offline-use:To include a model for offline-use declare the model withBaseUuidModelfromedc-base, define thenatural_keymethod and the model manager methodget_by_natural_keyand add theHistoricalRecordsmanager fromedc-base.For example the base class for all CRFs in a module might look like this:fromedc_model.modelsimportBaseUuidModel,HistoricalRecordsfrom.visitimportVisitclassCrfModel(BaseUuidModel):visit=models.OneToOneField(Visit)objects=CrfModelManager()history=HistoricalRecords()defnatural_key(self):return(self.visit.natural_key(),)natural_key.dependencies=['myapp.visit']Add a model to the site globalIn your app, add moduleoffline_models.py.# offline_models.pyfromdjango_collect_offline.site_offline_modelsimportsite_offline_modelsfromdjango_collect_offline.offline_modelimportOfflineModeloffline_models=['my_app.CrfModel',]site_offline_models.register(offline_models,OfflineModel)Settingsto disable offline-use add this to yoursettings.pyALLOW_MODEL_SERIALIZATION=False# (default: True)View models registered for synchronizationfromdjango_collect_offline.site_offline_modelsimportsite_offline_models# list all models in app 'bcpp_household' set for offline-usemodels=site_offline_models.site_models('bcpp_household',sync=True)# list all models in app 'bcpp_household' NOT set for offline-usemodels=site_offline_models.site_models('bcpp_household',offline=False)# list all models in app 'bcpp_household' not set for offline-use, excluding the "historical" modelsoffline_models=[m.model._meta.label_lowerforminmodelsif'historical'notinm.model_name]To create the model list for an appsoffline_models.py, open a shell and list all models not yet registered for offline-use:models=site_offline_models.site_models('bcpp_household',offline=False)[m.model._meta.label_lowerforminmodelsif'historical'notinm.model_name]About Offline-useThe offline model approach is limited and only transfers data one-way and always toward a central server or parent node.
Many client nodes may push data to their server node.Getting data from the fieldWe usedjango-collect-offlinein Django projects deployed to low-resourced remote communities where there is no reliable internet, public or private network. Our Research Assistants collect participant data in households, mobile tents and remote clinics. The Research Assistants enter data directly into their offline laptops. Once back online, data is pushed to thecommunity-serverand later to thecentral-server.Our research also involves collecting blood specimens that need to get to our community clinic within an hour or two from time of collection. Research Assistants stay out in the field on shift for 6 hours or more. So we send a driver to fetch specimens and data from the Research Assistant in the field. The driver has amiddlemanlaptop that pulls all pending data from the Research Assistant’s laptop. The driver and the Research Assistant then reconcile specimens and requisition data against themiddlemandata and the physical specimen. (Note: we requisition and label specimens in the field through the app). The driver then returns to the community clinic, pushes data onto thecommunity-serverand delivers all the specimens. The Lab Assistant then reconciles the specimens and requisition data against thecommunity-serverdata and the physical specimen.Data Flowdjango-collect-offlineuses either the REST API or FILE transfer:field client —REST—> community serverfield client —REST—> middleman (and modelre inspector) —REST—> community serversite server —FILE—> central server