API

Model

class dalec.models.FetchHistoryBase(*args, **kwargs)

Stores fetch queries history for a specific dalec’s app [+ channel [+ channel obj]]

last_fetch_dt

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

app

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

content_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

channel

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

channel_object

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class Meta
verbose_name = 'Content fetch history line'
verbose_name_plural = 'Content fetch history lines'
ordering = ('-last_fetch_dt',)
get_latest_by = 'last_fetch_dt'
abstract = False
_meta = <Options for FetchHistoryBase>
get_next_by_last_fetch_dt(*, field=<django.db.models.fields.DateTimeField: last_fetch_dt>, is_next=True, **kwargs)
get_previous_by_last_fetch_dt(*, field=<django.db.models.fields.DateTimeField: last_fetch_dt>, is_next=False, **kwargs)
class dalec.models.ContentBase(*args, **kwargs)

Stores generic contents retrieved from an external source

last_update_dt

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

creation_dt

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

app

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

content_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

channel

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

channel_object

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

dj_channel_content_type

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

dj_channel_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

dj_channel_obj

Provide a generic many-to-one relation through the content_type and object_id fields.

This class also doubles as an accessor to the related object (similar to ForwardManyToOneDescriptor) by adding itself as a model attribute.

dj_content_content_type

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

dj_content_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

dj_content_obj

Provide a generic many-to-one relation through the content_type and object_id fields.

This class also doubles as an accessor to the related object (similar to ForwardManyToOneDescriptor) by adding itself as a model attribute.

content_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

content_data

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class Meta
verbose_name = 'Content'
verbose_name_plural = 'Contents'
ordering = ('-last_update_dt',)
get_latest_by = 'last_update_dt'
abstract = False
indexes = [<Index: fields=['app', 'content_type', 'channel', 'channel_object']>]
_meta = <Options for ContentBase>
dj_channel_content_type_id
dj_content_content_type_id
get_next_by_creation_dt(*, field=<django.db.models.fields.DateTimeField: creation_dt>, is_next=True, **kwargs)
get_next_by_last_update_dt(*, field=<django.db.models.fields.DateTimeField: last_update_dt>, is_next=True, **kwargs)
get_previous_by_creation_dt(*, field=<django.db.models.fields.DateTimeField: creation_dt>, is_next=False, **kwargs)
get_previous_by_last_update_dt(*, field=<django.db.models.fields.DateTimeField: last_update_dt>, is_next=False, **kwargs)

Proxy

class dalec.proxy.ProxyPool

Pool to register / load dalec children proxies

_proxies: Dict[str, Proxy] = {}
classmethod unregister(app: str) Proxy | None

Remove from the pool the proxy registered for this app Return the removed proxy if it was existant or None

classmethod register(proxy: Proxy | Type[Proxy], override: bool = False) None

register a proxy instance into the pool if the proxy app is already registed, it will raise a ValueError unless you explicitely want to override it.

classmethod get(app: str, autoload: bool = True) Proxy

Return the proxy registered for the given app. If it does not exists, the default behaviour is to try to autoload it from the module dalec_<app>.proxy Raise a ValueError if proxy can not be retrieved from the pool (or autoloaded)

classmethod get_registered_apps() Tuple[str, ...]
class dalec.proxy.Proxy

Abstact Proxy Class that dalec’s children must inherit to define a proxy class specific for an app.

app: str | None = None
content_model

alias of Content

fetch_history_model

alias of FetchHistory

refresh(content_type: str, channel: str | None = None, channel_object: str | None = None, force: bool | None = False, dj_channel_obj: Model | None = None) Tuple[int, int, int] | Tuple[Literal[False], Literal[False], Literal[False]]

Fetch updated contents from the source and update/create it into the DB. Then, if some contents has been created, delete oldests contents which are not anymore required returns number of created, updated and deleted objects or False if cache not yet expired

create_content(content_type: str, channel: str, channel_object: str, content: dict, dj_channel_obj: Model | None = None) ContentBase

Create a new instance of content and return it

update_content(instance: ContentBase, new_content: dict) bool

Update an existing instance of content and returns True if it really needed update

_fetch(nb: int, content_type: str, channel: str, channel_object: str) Dict[str, dict]

Fetch updated contents from the source and return it as a dict of dict: main dict keys MUST be the app’s content id, and value must be the content representation with at least three required attrs:

  • id: ID of the content inside the external app

  • last_update_dt: last update datetime inside the external app

  • creation_dt: creation datetime inside the external app

get_contents_queryset(content_type: str, channel: str, channel_object: str) QuerySet
exterminate(content_type: str, channel: str, channel_object: str) int

deletes oldests entries (depending on setting DALEC_NB_CONTENTS_KEPT) returns number of entries deleted

set_last_fetch(content_type: str, channel: str, channel_object: str, last_fetch: FetchHistoryBase | Literal[False] | None = False) FetchHistoryBase

Uodate or create a FetchHistory instance to register the last fetch datetime and return this instance if last_fetch is False, we avoid to query it (because we alreay know it does not exists) if last_fetch is None, we will try to get it via get_last_fetch else, it must be the last_fetch instance.

get_last_fetch(content_type: str, channel: str, channel_object: str) FetchHistoryBase | None

Retrieve from the DB the last instance of FetchHistory for the current app, content_type, channel, channel_object or None if it does not exist

Views

class dalec.views.FetchContentView(**kwargs)
model

alias of Content

property dalec_app: str
property dalec_content_type: str
property dalec_channel: str | None
property ordered_by: str | None
property dalec_channel_objects: List[str]
dalec_template
get_paginate_by(queryset: QuerySet) int

Get the number of items to paginate by, or None for no pagination.

post(request: HttpRequest, *args: tuple, **kwargs: dict) HttpResponse
get(request: HttpRequest, *args: tuple, **kwargs: dict) HttpResponse

Return a TemplateResponse with HTML for the last X elements wanted or a 204 response if nothing need an update (cache used or still the same contents)

get_queryset(*args: tuple, **kwargs: dict) QuerySet

Return the queryset filtered by app + contentype and optionaly channel and channel object if it’s given

get_template_names(template_type: str = 'list') List

Return a list of valid templates names, ordered by priority.

get_item_template() str

Return the template name to use to display an item in the list, depending the custom template, app, content_type, channel and css_framework if used.

dispatch(request, *args, **kwargs)
get_context_data(**kwargs: dict) dict

Get the context for this view.

refresh_contents() bool

Asks to the proxy to refresh content and returns True if something has been or False if there are no new created/updated/deleted content (in this case this view will return a 204)