crotal.models.base.
Model
(**attributes)[source]¶This is the model of the data in crotal site. It is a simple ORM in which the database layer is replaced with static file reader. The pattern is designed to go with Django.
Example usage:
We have defined the max length of the title as 8, so the result is:
create
()[source]¶This function is called after the model has successfully load the documents from the folder indicated, it should be overridden if you want to do some extra operation on the data.
For example, if you want to convert the post content into markdown
format, then you should define it in the method create
under
Post
class.
to_db
(absolute_path)[source]¶Convert the data from object into crotal database format for data persistence and serialization.
load
(database, config)[source]¶This method loads the static files indicated by cls.PATH
of each
model, then parse them into objects.
None
classify_files
()[source]¶This method classifies the static files into 3 types: unmodified
,
modified
and removed
by comparing the last modified time of
the file read from file system with the last modified time stored in
database.
single_file_on_change
(file_path, event_type, config)[source]¶This method is called by the crotal server. If there is a file change when the server is running, the server will call this method to let the model responding to the change of file.
created
, modified
or deleted
.load_main_items
(config)[source]¶This method handles 3 types of source file differently, loads the fields of each source file, build objects and add them into the object manager.
If the file is unmodified
, then load it from crotal database;
If the field is modified
, then load it from the file system;
If the field is removed
, then remove it from the crotal database;
As unmodified
file is stored in crotal database which can be
accessed from memory, loading an unmodified
file can be much faster
than loading a modified
file from the file system(hard drive).
This is also known as incremental build, which makes Crotal fast.
load_extra_items
(config)[source]¶This method is called after all static files are load. If you want to load some other fields from the files in addition to the main fields, please override this function.
For more information please refer to the implementation of models.Post
load_single_file
(file_path, config)[source]¶This method is used to load a single file from the file_path
.
An object of the loaded file.
remove_single_file
(file_path)[source]¶This method is used to remove a single file from the object manager and the database.
from_db
(path, config, row)[source]¶This method is used to load a single object directly from the database.
An object of the designated file.
from_file
(file_path, config)[source]¶This method is used to load a single object from the file system.
An object of the loaded file.
from_text
(file_path, text, config)[source]¶This method is used to load a single object from a string.
The object of the loaded file.
parse_content
(file_path, content, config)[source]¶Parse the content from a string and return an model object.
parse_attributes
(file_path, config, attributes)[source]¶For each attributes read from the static file, find the corresponding
field and parse the attribute by the parse
method under the field.
None
get_file_list
(base_dir, path_list)[source]¶This method returns the list of all the source files in the directory indicated. Notice that there be multiple paths passed as a list and files started with '.' will be ignored.
None