cattle_grid.extensions.examples.html_display ¶
The goal of this extension is to illustrate the mechanism how cattle_grid can be used to create a webpage displaying the public posts of its users. The focus is on providing a working solution to key problems than on providing the optimal solution.
An example of a feed is available at @release. The current scope is:
- Display actor and posts
- Correct redirecting behavior for easy use
- Display replies (todo)
- Export
- Import from compatible sources (todo)
This is not an independent solution. It relies on both the context and simple_storage extension of cattle_grid.
export_create_token
async
¶
export_create_token(
publishing_actor: PublishingActor,
session: CommittingSession,
publisher: AccountExchangePublisher,
config: Config,
)
Provides a token and download link for the export of stored objects
The response is of type cattle_grid.extensions.examples.html_display.types.ExportTokenResponse and
send to receive.NAME.response.trigger.
Source code in cattle_grid/extensions/examples/html_display/__init__.py
html_display_incoming_announce
async
¶
html_display_incoming_announce(
activity: ParsedActivity,
message: ActivityMessage,
session: CommittingSession,
)
Handles announces
Source code in cattle_grid/extensions/examples/html_display/__init__.py
html_display_incoming_create
async
¶
html_display_incoming_create(
embedded_object: ParsedEmbeddedObject,
session: CommittingSession,
)
Handles replies
Source code in cattle_grid/extensions/examples/html_display/__init__.py
html_display_incoming_like
async
¶
html_display_incoming_like(
activity: ParsedActivity,
message: ActivityMessage,
session: CommittingSession,
)
Handles likes
Source code in cattle_grid/extensions/examples/html_display/__init__.py
html_publish_object
async
¶
html_publish_object(
message: ActivityMessage,
session: CommittingSession,
publishing_actor: PublishingActor,
config: Config,
factories: FactoriesForActor,
activity_publisher: ActivityExchangePublisher,
)
Publishes an object
Source code in cattle_grid/extensions/examples/html_display/__init__.py
name_actor
async
¶
name_actor(
message: NameActorMessage,
publishing_actor: PublishingActor,
session: CommittingSession,
activity_publisher: ActivityExchangePublisher,
config: Config,
)
Sets the display name of the actor
Source code in cattle_grid/extensions/examples/html_display/__init__.py
outgoing_delete
async
¶
outgoing_delete(
message: ActivityMessage, session: SqlSession
)
Deletes the publishing actor, if they delete themself
Source code in cattle_grid/extensions/examples/html_display/__init__.py
config ¶
HtmlDisplayConfiguration ¶
Bases: BaseModel
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Path to use before the generated uuid. The protocol and domain will be extracted from the actor id. See determine_url_start. |
'/html_display/object/'
|
html_prefix
|
str
|
Prefix to use for the url pages |
'/@'
|
automatically_add_users_to_group
|
bool
|
Causes an actor that sends a html_display_name message to be added to the html_display group |
False
|
Source code in cattle_grid/extensions/examples/html_display/config.py
html_url ¶
html_url_start ¶
database ¶
Base ¶
Bases: AsyncAttrs, DeclarativeBase
Base model
ExportPermission ¶
Bases: Base
Records a one time token required to download the export
Source code in cattle_grid/extensions/examples/html_display/database.py
PublishedObject ¶
Bases: Base
HTML display object in the database
Source code in cattle_grid/extensions/examples/html_display/database.py
PublishedObjectInteraction ¶
Bases: Base
HTML display object in the database
Source code in cattle_grid/extensions/examples/html_display/database.py
dependencies ¶
fastapi_dependencies ¶
ActivityPubActor
module-attribute
¶
Returns the Actor from the database
ActorProfile
module-attribute
¶
Returns the actor profile
PublishedObjectForUUID
module-attribute
¶
PublishedObjectForUUID = Annotated[
PublishedObject, Depends(published_object)
]
Returns the published object
PublishedObjectWithInteractionsForUUID
module-attribute
¶
PublishedObjectWithInteractionsForUUID = Annotated[
PublishedObject,
Depends(published_object_With_interactions),
]
publisher ¶
Publisher
dataclass
¶
Class for manipulating objects being published
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
actor
|
PublishingActor
|
|
required |
config
|
HtmlDisplayConfiguration
|
|
required |
obj
|
dict[str, Any]
|
|
required |
uuid
|
UUID
|
UUID version 7 features a time-ordered value field derived from the widely implemented and well known Unix Epoch timestamp source, the number of milliseconds since midnight 1 Jan 1970 UTC, leap seconds excluded. As well as improved entropy characteristics over versions 1 or 6. Implementations SHOULD utilize UUID version 7 over UUID version 1 and 6 if possible. |
UUID('019a4555-5a71-7c7c-9fc9-41d84efcec6f')
|
Source code in cattle_grid/extensions/examples/html_display/publisher.py
router ¶
export_objects
async
¶
export_objects(
actor: PublishingActorForName,
token: str,
session: SqlSession,
)
Returns the export of user data, a token needs to be provided.
The token can be requested via the html_display_export method.
Source code in cattle_grid/extensions/examples/html_display/router.py
get_actor_html
async
¶
get_actor_html(
actor: PublishingActorForName,
profile: ActorProfile,
request: Request,
session: SqlSession,
should_serve: ShouldServe,
)
Returns the HTML representation of the actor
Source code in cattle_grid/extensions/examples/html_display/router.py
get_index
async
¶
get_object
async
¶
get_object(
obj: PublishedObjectForUUID,
ap_headers: ActivityPubHeaders,
session: SqlSession,
config: ConfigFastAPI,
)
Returns the stored object
Source code in cattle_grid/extensions/examples/html_display/router.py
get_object_html
async
¶
get_object_html(
actor: PublishingActorForName,
obj: PublishedObjectWithInteractionsForUUID,
request: Request,
should_serve: ShouldServe,
)
Returns the HTML representation for an object
Source code in cattle_grid/extensions/examples/html_display/router.py
get_object_interaction
async
¶
get_object_interaction(
obj: PublishedObjectWithInteractionsForUUID,
ap_headers: ActivityPubHeaders,
session: SqlSession,
interaction: InteractionType,
)
Returns the stored object
Source code in cattle_grid/extensions/examples/html_display/router.py
types ¶
ExportTokenResponse ¶
Bases: WithActor
Message containing the export information
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
actor
|
str
|
actor_id of the actor that received the message |
required |
token
|
str
|
One time token |
required |
export_url
|
str
|
Url including the token the export is located at |
required |