Skip to main content

Collect data offline and push to the server later.

Project description

pypi travis coverage

django-collect-offline

Deploy a Django app as a client on laptop that is offline and push the data to your server when you get back online.

Installation

Add 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 with BaseUuidModel from edc-base, define the natural_key method and the model manager method get_by_natural_key and add the HistoricalRecords manager from edc-base.

For example the base class for all CRFs in a module might look like this:

from edc_base.model.models import BaseUuidModel, HistoricalRecords

from .visit import Visit

class CrfModel(BaseUuidModel):

    visit = models.OneToOneField(Visit)

    objects = CrfModelManager()

    history = HistoricalRecords()

    def natural_key(self):
        return (self.visit.natural_key(), )
    natural_key.dependencies = ['myapp.visit']

    class Meta:
        abstract = True

Add a model to the site global

In your app, add module offline_models.py.

# offline_models.py

from django_collect_offline.site_offline_models import site_offline_models
from django_collect_offline.offline_model import OfflineModel

offline_models = [
    'my_app.CrfModel',
]

site_offline_models.register(offline_models, OfflineModel)

Settings

to disable offline-use add this to your settings.py

ALLOW_MODEL_SERIALIZATION = False  # (default: True)

View models registered for synchronization

from django_collect_offline.site_offline_models import site_offline_models

# list all models in app 'bcpp_household' set for offline-use
models = site_offline_models.site_models('bcpp_household', sync=True)

# list all models in app 'bcpp_household' NOT set for offline-use
models = site_offline_models.site_models('bcpp_household', offline=False)

# list all models in app 'bcpp_household' not set for offline-use, excluding the "historical" models
offline_models = [m.model._meta.label_lower for m in models if 'historical' not in m.model_name]

To create the model list for an apps offline_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_lower for m in models if 'historical' not in m.model_name]

About Offline-use

The 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 field

We use django-collect-offline in 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 the community-server and later to the central-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 a middleman laptop that pulls all pending data from the Research Assistant’s laptop. The driver and the Research Assistant then reconcile specimens and requisition data against the middleman data 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 the community-server and delivers all the specimens. The Lab Assistant then reconciles the specimens and requisition data against the community-server data and the physical specimen.

Data Flow

django-collect-offline uses either the REST API or FILE transfer:

  • field client —REST—> community server

  • field client —REST—> middleman (and modelre inspector) —REST—> community server

  • site server —FILE—> central server

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

django_collect_offline-0.2.33-py3-none-any.whl (69.5 kB view details)

Uploaded Python 3

File details

Details for the file django-collect-offline-0.2.33.macosx-10.7-x86_64.tar.gz.

File metadata

  • Download URL: django-collect-offline-0.2.33.macosx-10.7-x86_64.tar.gz
  • Upload date:
  • Size: 74.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for django-collect-offline-0.2.33.macosx-10.7-x86_64.tar.gz
Algorithm Hash digest
SHA256 325a47e256fd547fe82b1c909516e552f40632f5053e84cbb09daa9e6d42573d
MD5 82f2d122b32b4cdec093b65a7330061c
BLAKE2b-256 906301a25915cd20c1f1ac612e449fe28d6777cdee09a61a1624d1579d836518

See more details on using hashes here.

File details

Details for the file django_collect_offline-0.2.33-py3-none-any.whl.

File metadata

  • Download URL: django_collect_offline-0.2.33-py3-none-any.whl
  • Upload date:
  • Size: 69.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for django_collect_offline-0.2.33-py3-none-any.whl
Algorithm Hash digest
SHA256 b05f8491c318d1d3bee24350472b5098f0cbfc90bd5a4dc1a88b94072cfc9e0a
MD5 69a720b713d87c903cf41d62929bb81a
BLAKE2b-256 d6725ba3e0af2daef88d028cadcd0f440df781e5169e82698e7d92e3c282104e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page