Djamo Document Implementation

To create document you should subclass the Document or any subclasses of that.

class djamo.document.Document(*args, **kwargs)

Djamo implementation of Document. Each document can have any number of key/value pairs as user want, there is no limit. But if user wants to provides some options and details about an specific key he/she should add a keys property to their subclass. keys is a dictionary object. Each key of keys property would be a document key and its value would be another dictionary with some specific key/value. for example:

class students (Document):
    fields = {
                "name": String(required=True, max_lenght=30),
                "age": Integer(min=5, max=40, default=20),
                "user": DjanogUser(required=True),
             }

Note

Remember that providing a fields attribute is optional

_deserialize_key(self, item)

de-serialize each key/value using a serializer.

_get_from_cache(self, serializer_name, raw_value, default=None)

Get the available value of specfied key in raw_value from serializer_name dictionary

_put_to_cache(self, cache_name, raw_value, value)

Put value for raw_value to cache_name cache.

_serialize_key(self, key)

Serialize each key/value and return a tuple like: (key, serialized_value)

_validate_value(self, key)

Validate a value of an specific key against user provided validator of the serializer class and current document validate_<key>

deserialize(self, data=None, validate=True, clear=True)

This method is responsible for de-serializing document data from database. If there was a serializer for a key it will call that otherwise simply treat the value like a python data type.

Parameters:
  • data – (optional) A dict-like data to de-serialize in current Document instance. If no data provided deserialize method will use current keys/values of docuemnt and serialize them in their place.
  • validate – (optional) de-serializer will validate de-serialized data after de-serializing process. default: True
  • clear – (optional) This argument cause all the current data of this Document instance clear before deserialization.
classmethod deserialize_item(item)

Deserialize a query that stored in item tuple like: (key, value)

serialize(self)

This method is responsible for serializing document data to put into database. The important thing to know here is that this method use serializer of each key to serialize and deserialize data. If no serializer sepcified, serialize method will treat data just like common python data types withou serialization.

This method will return a dictionary from serialized data.

classmethod serialize_item(item, args=None)

Serialize a query that stored in item tuple like: (key, value)

validate(self)

Validate the current document against provided validators of serializer and current document validate_<field> method for each field. The signature of each document level validator for a field should be like:

def validate_<field>(self, value):
    # Validation code goes here ....

Remember to replace <field> with your field name.

class djamo.document.DocumentMeta

Meta class for Document object. This class is responsible for creating Document instances.

Note

This class is for Djamo internal usage.

This Page