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.parentis aForwardManyToOneDescriptorinstance.
- 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_typeandobject_idfields.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.parentis aForwardManyToOneDescriptorinstance.
- 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_typeandobject_idfields.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
- 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
Nonefor 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)