Changes between Version 8 and Version 9 of BluePrint/PrePopulate


Ignore:
Timestamp:
03/24/12 04:36:57 (10 years ago)
Author:
Michael Howden
Comment:

Moved to DeveloperGuidelines/PrePopulate

Legend:

Unmodified
Added
Removed
Modified
  • BluePrint/PrePopulate

    v8 v9  
    11[[TOC]]
    2 = Pre-Populate =
     2= !BluePrints: Pre-Populate =
    33
    4 == Introduction ==
    5 We need to be able to import data into a Sahana Eden instance for testing, demos and to help with getting up and running.
    6 
    7 == Types of Data ==
    8  * Item Catalogue
    9  * Organisation List
    10  * Assets
    11  * Warehouse Supplies
    12  * Human Resources (Staff & Volunteers)
    13  * Locations (Administrative Boundaries)
    14 
    15 == Methods ==
    16 === On First Run ===
    17 In models/000_config.py their is a deployment setting which is used to control prepopulate. This is a list of directory names and will import data from a number of CSV files. The directories must be in the private/prepopulate directory tree and must include a file called tasks.cfg.
    18 
    19 The prepopulate deployment setting can also be a number which will relate to a single directory, the numerical value is still supported because existing instances of Eden and their maintenance scripts use this number. The use of a number is discouraged in favour of the list of names because this new approach is clearer and more flexible.
    20 
    21 ==== Deployment setting examples ====
    22 Use the Shipment folder as the starting point for the prepopulate.
    23 {{{
    24 deployment_settings.base.prepopulate = ["Standard"]
    25 }}}
    26 The Standard folder is not in the root directory, which is private/prepopulate, rather it is in demo (private/prepopulate/demo) but this will be found automatically.
    27 
    28 Uses the roles to import some special roles and then the user directory which is a special directory which is external to the version control and so private data (potentially sensitive data - such as volunteer details) can be held and then imported.
    29 {{{
    30 deployment_settings.base.prepopulate = ["roles", "user"]
    31 }}}
    32 
    33 
    34 The tasks.cfg file comprises a list of import jobs. They can be of two distinct types:
    35  * Basic Importer Jobs
    36  * Special Import Jobs
    37 The tasks.cfg file supports the # character on the first column as a comment.
    38 ==== Basic Importer Jobs ====
    39 These will use the UI Importer to load in the data and requires the following information:
    40  * The controller
    41  * The function
    42  * The CSV
    43  * The XSL transform file
    44 
    45 For example:
    46 {{{
    47 "survey","question_list","questionnaire24H.csv","question_list.xsl"
    48 }}}
    49 Which will use the questionnaire24H.csv file, which in this case will be in the same directory as the tasks.cfg file, to import the data. Using the question_list.xsl transform file which will be the static/formats/s3csv/survey directory. The importer will then use the survey/question_list function to "manage" the import using any '''onvalidate''' or '''onaccept''' callbacks that are set up by this controller.
    50 
    51 The CSV file does not '''need''' to be in the same directory as the tasks.cfg file, if it is held in a different file then the full path needs to be given relative to the private/prepopulate directory.
    52 
    53 All transform files are stored in the static/formats/s3csv directory tree.
    54 ==== Special Import Jobs ====
    55 For some import jobs it is easier to create a purpose built import function rather than use the Importer. These are created by using a asterisk at the start of the line in the tasks.cfg file, as follows:
    56 {{{
    57 *,gis_set_default_location,defaultlocation.csv
    58 }}}
    59 This uses the csv file '''default_location.csv''' and the function '''gis_set_default_location''' to set, in this case, the default location. Another special function is import_role which is used to import user permissions (or roles) examples of the roles and what the csv looks like can be found in the private/prepopulate/roles directory.
    60 
    61 === URL Import ===
    62 Data can be imported using URL calls:
    63 {{{
    64 http://127.0.0.1:8000/eden/supply/item/create.s3csv
    65 ?filename=/home/web2py/applications/eden/static/formats/s3csv/eric.csv
    66 &transform=/home/web2py/applications/eden/static/formats/s3csv/eric.xsl
    67 }}}
    68 
    69 However this method isn't easily automated[[BR]]
    70 
    71 Also see: UserGuidelinesImporter
    72 === Python Script ===
    73 This offers us better options to automate the import of data.
    74 {{{
    75 # Function to handle conflicts
    76 s3mgr.configure("supply_item", deduplicate=response.s3.item_deduplicate)
    77 resource = s3mgr.define_resource("supply", "item")
    78 resource.import_xml(open("/home/web2py/applications/eden/static/formats/s3csv/eric.csv", "r"),
    79                     format="csv",
    80                     stylesheet="/home/web2py/applications/eden/static/formats/s3csv/eric.xls")
    81 }}}
    82 Should we have a wrapper function for this which is easily accessed from the CLI?
    83 
    84 
    85 
    86 Rational:
    87  * People could create their own "Deployment" pre-populate directories with unique (& contextual) data which could be used to easily create simulations. ( And be a great GCI task )
    88  * We should separate csv from xsl (xsl could very easily confuse semi-technical users)
    89  * CSV templates should be easily downloaded - prepopulate data should not (always) be
    90  * All XLS should be in trunk (even if it is for private data) and have a matching CSV Template
    91  * Then a configuration file can be created where you can just list the CSV file names which you want to be imported when Sahana Eden is initialized. Copies of this files could be saved in the private/prepopulate/<deployment>/ directory then a config setting could select which file to use, to make it easy to set up Sahana Eden to have different types of data in it.
    92 
    93  
     4----
     5See:
     6* DeveloperGuidelines/PrePopulate for the current prepopulate functionality