PostManager«
PostManager (StorageAdapter)
«
Main PostManager class used to manager all post operations.
index
property
readonly
«
Get meta data of all posts managed by this manager.
delete_post(self, post_id)
«
Remove post and all corresponding data from storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
post_id |
int |
ID of post to be deleted. |
required |
Returns:
Type | Description |
---|---|
None |
Raises PostManagerExecption on error. |
get_by_id(self, post_id)
«
Fetch an existing post from storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_index |
List |
New index list to be written to storage. |
required |
Returns:
Type | Description |
---|---|
Post |
Raises PostManagerException if not found. |
get_meta_data(self, post_id)
«
Get MetaData for corresponding post ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
post_id |
int |
ID of post to be deleted. |
required |
Returns:
Type | Description |
---|---|
MetaData |
Raises PostManagerExecption on error. |
get_post_content(self, post_id)
«
Get content of post with given id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
post_id |
int |
ID of the post. |
required |
Returns:
Type | Description |
---|---|
dict |
JSON content of post. |
new_meta_data(self, meta_dict)
«
Create new MetaData object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
meta_dict |
dict |
New post ID, used to create new post. |
required |
Returns:
Type | Description |
---|---|
MetaData |
New MetaData object to be used to create new post. |
new_post(self, post_meta, content='')
«
Create new Post object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
meta_dict |
dict |
MetaData object associated with this post. |
required |
content |
dict |
JSON parsable object or string. |
'' |
Returns:
Type | Description |
---|---|
Post |
New Post object. |
new_post_id(self)
«
Get the latest post ID which can be used for a new post.
Returns:
Type | Description |
---|---|
int |
New post ID, used to create new post. |
save_post(self, post)
«
Save new Post to storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
post |
Post |
New Post object intented to save. |
required |
Returns:
Type | Description |
---|---|
Post |
Post object just saved, raises PostManagerExecption on error. |
setup_local(template='post', client_config={}, testing=False)
staticmethod
«
Create new PostManager object for AWS S3 storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
template |
str |
Name of template of Post, used as root_dir configuration. |
'post' |
client_config |
dict |
Configuration used to configure local_client |
{} |
testing |
bool |
Weather testing is True will determine client type. |
False |
Returns:
Type | Description |
---|---|
PostManager |
New instance of PostManager, configured to use with local file storage. |
setup_s3(bucket_name, template='post', client_config={}, testing=False)
staticmethod
«
Create new PostManager object for AWS S3 storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bucket_name |
str |
Name of the S3 bucket to use as storage. |
required |
template |
str |
Name of template of Post, used as root_dir configuration. |
'post' |
client_config |
dict |
Configuration used to configure s3_client |
{} |
testing |
bool |
Weather testing is True will determine client type. |
False |
Returns:
Type | Description |
---|---|
PostManager |
New instance of PostManager, configured to use with AWS S3. |
setup_s3_with_event(event)
staticmethod
«
Create new PostManager object for S3 storage with an Event object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event |
Event |
Event object, usually created with Request event. |
required |
Returns:
Type | Description |
---|---|
PostManager |
New instance of PostManager, configured to use with AWS S3. |
title_to_id(self, title)
«
Get ID number of given post title.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title |
str |
Title of post. |
required |
Returns:
Type | Description |
---|---|
int |
Raises PostManagerException if not found. |
update_index(self, new_index)
«
Writes new index to storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_index |
List |
New index list to be written to storage. |
required |
Returns:
Type | Description |
---|---|
None |
No return value |