Exemple #1
0
  def from_manifest(cls, manifest, credentials, save=True):
    """ Produce a MachineApp object from an app manifest.

    Manifests should correspond to SMART manifest format 
    (http://wiki.chip.org/smart-project/index.php/Developers_Documentation:_Packaging_Applications_via_SMART_Manifest),
    with one required Indivo specific extensions, namely:
    
    * *ui_app*: ``true`` or ``false``. Whether the machineapp is a UIApp ('chrome app').
    * *indivo_version*: Required version of Indivo for compatibility
    
    Credentials should be JSON objects with two keys:

    * *consumer_key*: The oAuth consumer key to use for the app
    * *consumer_secret*: The oAuth consumer secret to use for the app

    See :doc:`app-registration` for more details.

    """

    from indivo.views import _get_indivo_version
    parsed_manifest = simplejson.loads(manifest)
    parsed_credentials = simplejson.loads(credentials)
    kwargs = {
      'consumer_key': parsed_credentials['consumer_key'],
      'secret': parsed_credentials['consumer_secret'],
      'name': parsed_manifest['name'],
      'email': parsed_manifest['id'],
      'app_type': 'chrome' if parsed_manifest['ui_app'] else 'admin',
      'description': parsed_manifest.get('description', ''),
      'author': parsed_manifest.get('author', ''),
      'version': parsed_manifest.get('version', ''),
      'indivo_version':parsed_manifest['indivo_version'] if parsed_manifest.has_key('indivo_version') \
        else _get_indivo_version(parsed_manifest.get('smart_version', '')),
      }
    app = cls(**kwargs)
    if save:
      app.save()
    return app
Exemple #2
0
  def from_manifest(cls, manifest, credentials, save=True):
    """ Produce a PHA object from an app manifest.

    Manifests should correspond to SMART manifest format 
    (http://wiki.chip.org/smart-project/index.php/Developers_Documentation:_Packaging_Applications_via_SMART_Manifest),
    with some optional Indivo specific extensions, namely:

    * *oauth_callback_url*: A callback URL for Indivo-style oAuth access
    * *autonomous_reason*: An explanation for why the app requires offline access to patient records
    * *has_ui*: ``true`` or ``false``, whether the app can be displayed in a browser.
    * *frameable*: ``true`` or ``false``, whether the app should be loaded in an iframe in the Indivo UI.
    * *indivo_version*: Required version of Indivo for compatibility
    
    Credentials should be JSON objects with two keys:

    * *consumer_key*: The oAuth consumer key to use for the app
    * *consumer_secret*: The oAuth consumer secret to use for the app

    See :doc:`app-registration` for more details.

    """

    from indivo.views import _get_indivo_version
    parsed_manifest = simplejson.loads(manifest)
    parsed_credentials = simplejson.loads(credentials)

    # expand relative urls to be relative to the UI
    start_url = parsed_manifest.get('index', '')
    if start_url and start_url.find('://') < 0:
        start_url = "%s%s"%(settings.UI_SERVER_URL, start_url)

    callback_url = parsed_manifest.get('oauth_callback_url', '')
    if callback_url and callback_url.find('://') < 0:
        callback_url = "%s%s"%(settings.UI_SERVER_URL, callback_url)

    icon_url = parsed_manifest.get('icon', '')
    if icon_url and icon_url.find('://') < 0:
        icon_url = "%s%s"%(settings.UI_SERVER_URL, icon_url)

    kwargs = {
      'consumer_key': parsed_credentials['consumer_key'],
      'secret': parsed_credentials['consumer_secret'],
      'name': parsed_manifest['name'],
      'email': parsed_manifest['id'],
      'start_url_template': start_url,
      'callback_url': callback_url,
      'is_autonomous': parsed_manifest.get('mode', '') == 'background',
      'autonomous_reason': parsed_manifest.get('autonomous_reason', ''),
      'has_ui': parsed_manifest['has_ui'] if parsed_manifest.has_key('has_ui') \
          else parsed_manifest.has_key('index'), # This may not be perfect
      'frameable': parsed_manifest['frameable'] if parsed_manifest.has_key('frameable') \
          else parsed_manifest.has_key('index'),
      'description': parsed_manifest.get('description', ''),
      'author': parsed_manifest.get('author', ''),
      'version': parsed_manifest.get('version', ''),
      'icon_url': icon_url,
      'indivo_version': parsed_manifest['indivo_version'] if parsed_manifest.has_key('indivo_version') \
          else _get_indivo_version(parsed_manifest.get('smart_version', '')),
      'requirements': simplejson.dumps(parsed_manifest.get('requires', {})),
      }
    app = cls(**kwargs)
    if save:
      app.save()
    return app