Package vita :: Package modules :: Package s3 :: Module s3xml :: Class S3XML
[hide private]
[frames] | no frames]

Class S3XML

source code

object --+
         |
        S3XML

XML toolkit for S3XRC

Instance Methods [hide private]
 
__init__(self, manager)
Constructor
source code
 
parse(self, source)
Parse an XML source into an element tree
source code
 
transform(self, tree, stylesheet_path, **args)
Transform an element tree with XSLT
source code
 
tree(self, elements, root=None, domain=None, url=None, start=None, limit=None, results=None)
Builds a S3XML tree from a list of elements
source code
 
export_uid(self, uid)
Exports UIDs with domain prefix
source code
 
import_uid(self, uid)
Imports UIDs with domain prefixes
source code
 
represent(self, table, f, v)
Get the representation of a field value
source code
 
rmap(self, table, record, fields)
Generates a reference map for a record
source code
 
add_references(self, element, rmap, show_ids=False)
Adds <reference> elements to a <resource>
source code
 
gis_encode(self, resource, record, rmap, download_url="", marker=None)
GIS-encodes location references
source code
 
resource(self, parent, table, record, fields=[], url=None)
Creates a <resource> element from a record
source code
 
lookahead(self, table, element, fields, tree=None, directory=None)
Resolves references in XML resources
source code
 
record(self, table, element, original=None, files=[], validate=None, skip=[])
Creates a record (Storage) from a <resource> element and validates it
source code
 
get_options(self, prefix, name, fields=None)
Get options of option fields in a table as <select>s
source code
 
get_fields(self, prefix, name, parent=None, options=False, references=False, labels=False)
Get fields in a table as <fields> element
source code
 
get_struct(self, prefix, name, parent=None, options=True, references=False)
Get the table structure as XML tree
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]
 
select_resources(cls, tree, tablename)
Selects resources from an element tree
source code
 
get_field_options(cls, table, fieldname, parent=None)
Get options of a field as <select>
source code
 
__json2element(cls, key, value, native=False)
Converts a data field from JSON into an element
source code
 
__obj2element(cls, tag, obj, native=False)
Converts a JSON object into an element
source code
 
json2tree(cls, source, format=None)
Converts JSON into an element tree
source code
 
__element2json(cls, element, native=False)
Converts an element into JSON
source code
 
tree2json(cls, tree, pretty_print=False)
Converts an element tree into JSON
source code
 
csv2tree(cls, source, resourcename=None, delimiter=",", quotechar='"')
Convert a table-form CSV source into an element tree, consisting of <table name="format">, <row> and <col field="fieldname"> elements.
source code
Static Methods [hide private]
 
tostring(tree, pretty_print=False)
Convert an element tree into XML as string
source code
 
xml_encode(s)
XML-escape a string
source code
 
xml_decode(s)
XML-unescape a string
source code
 
json_message(success=True, status_code="200", message=None, tree=None)
Provide a nicely-formatted JSON Message
source code
Class Variables [hide private]
  namespace = "sahana"
  CACHE_TTL = 5
  UID = "uuid"
  MCI = "mci"
  MTIME = "modified_on"
  Lat = "lat"
  Lon = "lon"
  IGNORE_FIELDS = ["deleted", "deleted_fk", "v_record_status", "...
  FIELDS_TO_ATTRIBUTES = ["id", "created_on", "modified_on", "cr...
  ATTRIBUTES_TO_FIELDS = ["admin", "mci"]
  TAG = Storage(root= "s3xml", resource= "resource", reference= ...
  ATTRIBUTE = Storage(id= "id", name= "name", table= "table", fi...
  ACTION = Storage(create= "create", read= "read", update= "upda...
  PREFIX = Storage(resource= "$", options= "$o", reference= "$k"...
  ISOFORMAT = "%Y-%m-%dT%H:%M:%SZ"
universal timestamp
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, manager)
(Constructor)

source code 

Constructor

Parameters:
  • manager - the S3ResourceController
Overrides: object.__init__

parse(self, source)

source code 

Parse an XML source into an element tree

Parameters:
  • source - the XML source, can be a file-like object, a filename or a URL

transform(self, tree, stylesheet_path, **args)

source code 

Transform an element tree with XSLT

Parameters:
  • tree - the element tree
  • stylesheet_path - pathname of the XSLT stylesheet
  • args - dict of arguments to pass to the stylesheet

tostring(tree, pretty_print=False)
Static Method

source code 

Convert an element tree into XML as string

Parameters:
  • tree - the element tree
  • pretty_print - provide pretty formatted output

tree(self, elements, root=None, domain=None, url=None, start=None, limit=None, results=None)

source code 

Builds a S3XML tree from a list of elements

Parameters:
  • elements - list of <resource> elements
  • root - the root element to link the tree to
  • domain - name of the current domain
  • url - url of the request
  • start - the start record (in server-side pagination)
  • limit - the page size (in server-side pagination)
  • results - number of total available results

xml_encode(s)
Static Method

source code 

XML-escape a string

Parameters:
  • s - the string

xml_decode(s)
Static Method

source code 

XML-unescape a string

Parameters:
  • s - the string

export_uid(self, uid)

source code 

Exports UIDs with domain prefix

Parameters:
  • uid - the UID

import_uid(self, uid)

source code 

Imports UIDs with domain prefixes

Parameters:
  • uid - the UID

represent(self, table, f, v)

source code 

Get the representation of a field value

Parameters:
  • table - the database table
  • f - the field name
  • v - the value

rmap(self, table, record, fields)

source code 

Generates a reference map for a record

Parameters:
  • table - the database table
  • record - the record
  • fields - list of reference field names in this table

add_references(self, element, rmap, show_ids=False)

source code 

Adds <reference> elements to a <resource>

Parameters:
  • element - the <resource> element
  • rmap - the reference map for the corresponding record
  • show_ids - insert the record ID as attribute in references

gis_encode(self, resource, record, rmap, download_url="", marker=None)

source code 

GIS-encodes location references

Parameters:
  • resource - the referencing resource
  • record - the particular record
  • rmap - list of references to encode
  • download_url - download URL of this instance
  • marker - filename to override filenames in marker URLs

resource(self, parent, table, record, fields=[], url=None)

source code 

Creates a <resource> element from a record

Parameters:
  • parent - the parent element in the document tree
  • table - the database table
  • record - the record
  • fields - list of field names to include
  • url - URL of the record

select_resources(cls, tree, tablename)
Class Method

source code 

Selects resources from an element tree

Parameters:
  • tree - the element tree
  • tablename - table name to search for

lookahead(self, table, element, fields, tree=None, directory=None)

source code 

Resolves references in XML resources

Parameters:
  • table - the database table
  • element - the element to resolve
  • fields - fields to check for references
  • tree - the element tree of the input source
  • directory - the resource directory of the input tree

record(self, table, element, original=None, files=[], validate=None, skip=[])

source code 

Creates a record (Storage) from a <resource> element and validates it

Parameters:
  • table - the database table
  • element - the element
  • original - the original record
  • files - list of attached upload files
  • validate - validate hook (function to validate fields)
  • skip - fields to skip

get_field_options(cls, table, fieldname, parent=None)
Class Method

source code 

Get options of a field as <select>

Parameters:
  • table - the table
  • fieldname - the fieldname
  • parent - the parent element in the tree

get_options(self, prefix, name, fields=None)

source code 

Get options of option fields in a table as <select>s

Parameters:
  • prefix - the application prefix
  • name - the resource name (without prefix)
  • fields - optional list of fieldnames

get_fields(self, prefix, name, parent=None, options=False, references=False, labels=False)

source code 

Get fields in a table as <fields> element

Parameters:
  • prefix - the application prefix
  • name - the resource name (without prefix)
  • parent - the parent element to append the tree to
  • options - include option lists in option fields
  • references - include option lists even in reference fields

get_struct(self, prefix, name, parent=None, options=True, references=False)

source code 

Get the table structure as XML tree

Parameters:
  • prefix - the application prefix
  • name - the tablename (without prefix)
  • parent - the parent element to append the tree to
  • options - include option lists in option fields
  • references - include option lists even in reference fields
Raises:
  • AttributeError - in case the table doesn't exist

__json2element(cls, key, value, native=False)
Class Method

source code 

Converts a data field from JSON into an element

Parameters:
  • key - key (field name)
  • value - value for the field
  • native (bool) - use native mode

__obj2element(cls, tag, obj, native=False)
Class Method

source code 

Converts a JSON object into an element

Parameters:
  • tag - tag name for the element
  • obj - the JSON object
  • native - use native mode for attributes

json2tree(cls, source, format=None)
Class Method

source code 

Converts JSON into an element tree

Parameters:
  • source - the JSON source
  • format - name of the XML root element

__element2json(cls, element, native=False)
Class Method

source code 

Converts an element into JSON

Parameters:
  • element - the element
  • native - use native mode for attributes

tree2json(cls, tree, pretty_print=False)
Class Method

source code 

Converts an element tree into JSON

Parameters:
  • tree - the element tree
  • pretty_print - provide pretty formatted output

csv2tree(cls, source, resourcename=None, delimiter=",", quotechar='"')
Class Method

source code 

Convert a table-form CSV source into an element tree, consisting of <table name="format">, <row> and <col field="fieldname"> elements.

Parameters:
  • source - the source (file-like object)
  • resourcename - the resource name
  • delimiter - delimiter for values
  • quotechar - quotation character

json_message(success=True, status_code="200", message=None, tree=None)
Static Method

source code 

Provide a nicely-formatted JSON Message

Parameters:
  • success - action succeeded or failed
  • status_code - the HTTP status code
  • message - the message text
  • tree - result tree to enclose (as JSON)

Class Variable Details [hide private]

namespace

Value:
"sahana"

CACHE_TTL

Value:
5

UID

Value:
"uuid"

MCI

Value:
"mci"

MTIME

Value:
"modified_on"

Lat

Value:
"lat"

Lon

Value:
"lon"

IGNORE_FIELDS

Value:
["deleted", "deleted_fk", "v_record_status", "v_duplicate_uid", "id", \
"owned_by_role", "owned_by_user"]

FIELDS_TO_ATTRIBUTES

Value:
["id", "created_on", "modified_on", "created_by", "modified_by", "uuid\
", "mci", "admin"]

ATTRIBUTES_TO_FIELDS

Value:
["admin", "mci"]

TAG

Value:
Storage(root= "s3xml", resource= "resource", reference= "reference", d\
ata= "data", list= "list", item= "item", object= "object", select= "se\
lect", field= "field", option= "option", options= "options", fields= "\
fields", table= "table", row= "row", col= "col")

ATTRIBUTE

Value:
Storage(id= "id", name= "name", table= "table", field= "field", value=\
 "value", resource= "resource", ref= "ref", domain= "domain", url= "ur\
l", filename= "filename", error= "error", start= "start", limit= "limi\
t", success= "success", results= "results", lat= "lat", latmin= "latmi\
n", latmax= "latmax", lon= "lon", lonmin= "lonmin", lonmax= "lonmax", \
marker= "marker", sym= "sym", type= "type", readable= "readable", writ\
able= "writable", has_options= "has_options", tuid= "tuid", label= "la\
bel", comment= "comment")

ACTION

Value:
Storage(create= "create", read= "read", update= "update", delete= "del\
ete")

PREFIX

Value:
Storage(resource= "$", options= "$o", reference= "$k", attribute= "@",\
 text= "$")

ISOFORMAT

universal timestamp

Value:
"%Y-%m-%dT%H:%M:%SZ"