Modules Reference¶
base¶
- class base.Relation(attr_fk, to_class, related_name=None)¶
Adds a relation to another object.
- get_property()¶
Returns the property in which the relation will be referenced.
- set_reversed_property(from_class)¶
Returns the property in which the backwards relation will be referenced.
- class base.MetaOjota(*args, **kwargs)¶
Metaclass for Ojota
- class base.Ojota(_pk=None, **kwargs)¶
Base class to create instances of serialized data in the source files.
- __eq__(other)¶
Compare the equality of two elements.
- __init__(_pk=None, **kwargs)¶
Constructor.
- __repr__()¶
String representation of the elements.
- __weakref__¶
list of weak references to the object (if defined)
- classmethod _filter(data, filters)¶
Applies filter to data.
- Arguments:
- data – an iterable containing the data filters – a dictionary with the filters
- classmethod _objetize(data)¶
Return the data into an element.
- classmethod _read_all_from_datasource()¶
Reads the data from the datasource, makes a dictionary with the key specified in the key parameter. Allows to filter by subdirectories when the data is not on the root according to the data path.
- classmethod _read_item_from_datasource(pk)¶
Reads the data form the datasource if support index search.
- classmethod _sort(data_list, order_fields)¶
Sort a list by a given field or field froups.
- Arguments:
- data_list – a list with the data order_fields – a string with the order fields
- classmethod _test_expression(expression, value, element_data)¶
Finds out if a value in a given field matches an expression.
Arguments: expression – a string with the comparison expression. If the expression is a field name it will be compared with equal. In case that the field has “__” and an operation appended the it is compared with the appended expression. The availiable expressions allowed are: “=”, “exact”, “iexact”, “contains”, “icontains”, “in”, “gt”, “gte”, “lt”, “lte”, “startswith”, “istartswith”, “endswith”, “iendswith”, “range” and “ne”
- dump_values(new_data=None, delete=False)¶
Saves the data into a file.
- classmethod many(**kargs)¶
Returns all the elements that match the conditions.
- classmethod one(pk=None, **kargs)¶
Returns the first element that matches the conditions.
- primary_key¶
Returns the primary key value.
- save()¶
Save function for an object.
- update(**kwargs)¶
Updates the given values.
sources¶
- class sources.Source(data_path=None, create_empty=True)¶
Base class for all the data sources.
- __init__(data_path=None, create_empty=True)¶
Constructor for the Source class.
Arguments: data_path – the path where the data is located.
- __weakref__¶
list of weak references to the object (if defined)
- _get_file_path(cls)¶
Builds the path where the data will be located.
- Arguments:
- cls – the class with the data.
- fetch_element(cls, pk)¶
Fetch the elements for a given element of a class.
- Arguments:
- cls - the class with the data. pk - the primary key of the given element.
- fetch_elements(cls)¶
Fetch the elements for a given class.
- Arguments:
- cls - the class with the data.
- save(cls, data)¶
Fetch the elements for a given element of a class.
- Arguments:
- cls - the class with the data. pk - the primary key of the given element.
- class sources.JSONSource(data_path=None, create_empty=True, indent=4)¶
Source class for the data stored with JSON format
- __init__(data_path=None, create_empty=True, indent=4)¶
Constructor for the Source class.
- Arguments:
- data_path – the path where the data is located. create_empty – if file in data_path is not found, create an empty one. indent – control the indentation of the JSON in the file.
- read_elements(cls, filepath)¶
Reads the elements form a JSON file. Returns a dictionary containing the read data.
- Arguments:
- filepath – the path for the json file.
- class sources.YAMLSource(data_path=None, create_empty=True)¶
Source class for the data stored with YAML format.
requires the PyYaml package to run.
- read_elements(cls, filepath)¶
Reads the elements form a JSON file. Returns a dictionary containing the read data.
- Arguments:
- filepath – the path for the json file.
- class sources.WebServiceSource(data_path=None, method='get', get_all_cmd='/all', get_cmd='/data', user=None, password=None, cert=None, custom_call=None)¶
Source class for the data stored with JSON format taken through a Web Service.
Requires the “requests” package to run. http://pypi.python.org/pypi/requests
- __init__(data_path=None, method='get', get_all_cmd='/all', get_cmd='/data', user=None, password=None, cert=None, custom_call=None)¶
Constructor for the WebServiceSource class.
- Arguments:
- data_path – the path where the data is located. method – the http method that will be used witht the web service. Defauts to “get”. get_all_cmd – the WS command to fetch all the data. Defaults to “/all”. get_cmd – the WS command to fetch one element. Defaults to “/data” user – the user name for the authentication. If not provided the request will not use authentication. password – the password for the authentication. If not provided the request will not use authentication.
- read_element(cls, url, pk)¶
Reads one element elements form a JSON file. Returns a dictionary containing the read data.
- Arguments:
- cls – the data class. url – the path for the WS. pk – the primary key.
- read_elements(cls, url)¶
Reads the elements form a WS request. Returns a dictionary containing the read data.
- Arguments:
- cls – the data class. url – the path for the WS.
cache¶
- class cache.Cache¶
The base Cache class. Stores the cached data in memory.
- __contains__(name)¶
Returns True if a given element is cached.
- Arguments:
- name – the cache name.
- __weakref__¶
list of weak references to the object (if defined)
- get(name)¶
Gets the data from cache.
- Arguments:
- name – the cache name.
- set(name, elems)¶
Sets the data into cache.
- Arguments:
- name – the cache name. elems – the data to cache.
- class cache.Memcache(cache_location='127.0.0.1', port=11211, expiration_time=None, debug=None)¶
Stores the cached data in memcache.
- __contains__(name)¶
Returns True if a given element is cached.
- Arguments:
- name – the cache name.
- __init__(cache_location='127.0.0.1', port=11211, expiration_time=None, debug=None)¶
Constructor for the Memcache class.
- Arguments:
- cache_location – memcached URI. defaults to 127.0.0.1 port – memcached port. Defaults to 11211 expiration_time – memcache expiration time debug – activate memcache debug. Defaults to None
- get(name)¶
Gets the data from cache.
- Arguments:
- name – the cache name.
- set(name, elems)¶
Sets the data into cache.
- Arguments:
- name – the cache name. elems – the data to cache.