Skip to content

admin

django_spire.knowledge.admin

TAG_ACTION_MAX_ROWS = 25 module-attribute

Collection

Bases: HistoryModelMixin, OrderingModelMixin, TagModelMixin, ActivityMixin

parent = models.ForeignKey('self', on_delete=models.CASCADE, related_name='children', related_query_name='child', null=True, blank=True) class-attribute instance-attribute

name = models.CharField(max_length=255) class-attribute instance-attribute

description = models.TextField() class-attribute instance-attribute

services = CollectionService() class-attribute instance-attribute

objects = CollectionQuerySet.as_manager() class-attribute instance-attribute

name_short property

top_level_parent property

Meta

verbose_name = 'Collection' class-attribute instance-attribute
verbose_name_plural = 'Collections' class-attribute instance-attribute
db_table = 'django_spire_knowledge_collection' class-attribute instance-attribute
permissions = [('can_access_all_collections', 'Can Access All Collections'), ('can_change_collection_groups', 'Can Change Collection Groups')] class-attribute instance-attribute
ordering = ['name'] class-attribute instance-attribute

__str__

Source code in django_spire/knowledge/collection/models.py
def __str__(self):
    return self.name

CollectionGroup

Bases: Model

collection = models.ForeignKey(Collection, on_delete=models.CASCADE, related_name='groups', related_query_name='group') class-attribute instance-attribute

auth_group = models.ForeignKey(AuthGroup, on_delete=models.CASCADE, related_name='collection_groups', related_query_name='collection_group') class-attribute instance-attribute

services = CollectionGroupService() class-attribute instance-attribute

__str__

Source code in django_spire/knowledge/collection/models.py
def __str__(self):
    return f'{self.collection.name} - {self.auth_group.name}'

CollectionAdmin

Bases: ModelAdmin

actions = ('set_tags_for_collections',) class-attribute instance-attribute

autocomplete_fields = ('parent',) class-attribute instance-attribute

list_display = ('id', 'name', 'parent', 'is_deleted', 'tag_count') class-attribute instance-attribute

list_filter = ('is_deleted', 'is_active') class-attribute instance-attribute

ordering = ('name',) class-attribute instance-attribute

search_fields = ('id', 'name', 'description', 'parent__name') class-attribute instance-attribute

get_queryset

Source code in django_spire/knowledge/collection/admin.py
def get_queryset(self, request: HttpRequest) -> QuerySet[Collection]:
    queryset = super().get_queryset(request)

    return queryset.annotate(_tag_count=Count('tags', distinct=True))

set_tags_for_collections

Source code in django_spire/knowledge/collection/admin.py
@admin.action(description='Set Tags for Collections (Allow 5 Seconds Per)')
def set_tags_for_collections(
    self,
    request: HttpRequest,
    queryset: QuerySet[Collection],
) -> None:
    if queryset.count() > TAG_ACTION_MAX_ROWS:
        message = (
            f'Select at most {TAG_ACTION_MAX_ROWS} collections at a time. '
            f'Tagging runs inline and will time out on larger selections.'
        )

        messages.error(request, message)
        return

    processed = 0

    for collection in queryset:
        collection.services.tag.process_and_set_tags()
        processed += 1

    messages.success(request, f'Successfully processed {processed} collections.')

tag_count

Source code in django_spire/knowledge/collection/admin.py
@admin.display(description='Tags', ordering='_tag_count')
def tag_count(self, collection: Collection) -> int:
    return collection._tag_count

CollectionGroupAdmin

Bases: ModelAdmin

list_display = ('id', 'collection', 'auth_group') class-attribute instance-attribute

search_fields = ('id', 'collection__name', 'auth_group__name') class-attribute instance-attribute

Entry

Bases: HistoryModelMixin, OrderingModelMixin, TagModelMixin, ActivityMixin

collection = models.ForeignKey(Collection, on_delete=models.CASCADE, related_name='entries', related_query_name='entry') class-attribute instance-attribute

current_version = models.OneToOneField(EntryVersion, on_delete=models.CASCADE, related_name='current_version', related_query_name='current_version', null=True, blank=True) class-attribute instance-attribute

name = models.CharField(max_length=255) class-attribute instance-attribute

objects = EntryQuerySet.as_manager() class-attribute instance-attribute

services = EntryService() class-attribute instance-attribute

name_short property

top_level_collection property

Meta

verbose_name = 'Entry' class-attribute instance-attribute
verbose_name_plural = 'Entries' class-attribute instance-attribute
db_table = 'django_spire_knowledge_entry' class-attribute instance-attribute
indexes = [GinIndex(fields=['_search_vector'], name='entry_search_vector_idx'), GinIndex(name='entry_name_trgm_idx', fields=['name'], opclasses=['gin_trgm_ops']), GinIndex(name='entry_search_text_trgm_idx', fields=['_search_text'], opclasses=['gin_trgm_ops'])] class-attribute instance-attribute

__str__

Source code in django_spire/knowledge/entry/models.py
def __str__(self):
    return self.name

EntryAdmin

Bases: ModelAdmin

actions = ('set_tags_for_entries',) class-attribute instance-attribute

autocomplete_fields = ('collection', 'current_version') class-attribute instance-attribute

list_display = ('name', 'current_version_link', 'collection', 'is_deleted', 'tag_count') class-attribute instance-attribute

list_filter = ('is_deleted', 'is_active') class-attribute instance-attribute

ordering = ('name',) class-attribute instance-attribute

search_fields = ('name', 'collection__name') class-attribute instance-attribute

Source code in django_spire/knowledge/entry/admin.py
@admin.display(description='Current Version')
def current_version_link(self, entry: Entry) -> str:
    url = admin_changelist_url(EntryVersion, entry_id=str(entry.id))

    return format_html('<a href="{}">View Versions</a>', url)

get_queryset

Source code in django_spire/knowledge/entry/admin.py
def get_queryset(self, request: HttpRequest) -> QuerySet[Entry]:
    queryset = super().get_queryset(request)

    return queryset.annotate(_tag_count=Count('tags', distinct=True))

set_tags_for_entries

Source code in django_spire/knowledge/entry/admin.py
@admin.action(description='Set Tags for Entries (Allow 5 Seconds Per)')
def set_tags_for_entries(self, request: HttpRequest, queryset: QuerySet[Entry]) -> None:
    if queryset.count() > TAG_ACTION_MAX_ROWS:
        message = (
            f'Select at most {TAG_ACTION_MAX_ROWS} entries at a time. '
            f'Tagging runs inline and will time out on larger selections.'
        )

        messages.error(request, message)
        return

    processed = 0

    for entry in queryset:
        entry.services.tag.process_and_set_tags()
        processed += 1

    messages.success(request, f'Successfully processed {processed} entries.')

tag_count

Source code in django_spire/knowledge/entry/admin.py
@admin.display(description='Tags', ordering='_tag_count')
def tag_count(self, entry: Entry) -> int:
    return entry._tag_count

EntryVersion

Bases: HistoryModelMixin

entry = models.ForeignKey('Entry', on_delete=models.CASCADE, related_name='versions', related_query_name='version') class-attribute instance-attribute

author = models.ForeignKey(AuthUser, on_delete=models.CASCADE, related_name='entry_versions', related_query_name='entry_version') class-attribute instance-attribute

published_datetime = models.DateTimeField(blank=True, null=True) class-attribute instance-attribute

last_edit_datetime = models.DateTimeField(default=now) class-attribute instance-attribute

status = models.CharField(max_length=32, choices=EntryVersionStatusChoices, default=EntryVersionStatusChoices.DRAFT) class-attribute instance-attribute

objects = EntryVersionQuerySet.as_manager() class-attribute instance-attribute

services = EntryVersionService() class-attribute instance-attribute

Meta

verbose_name = 'Entry Version' class-attribute instance-attribute
verbose_name_plural = 'Entry Versions' class-attribute instance-attribute
db_table = 'django_spire_knowledge_entry_version' class-attribute instance-attribute

is_published

Source code in django_spire/knowledge/entry/version/models.py
def is_published(self) -> bool:
    return self.status == EntryVersionStatusChoices.PUBLISHED

EntryVersionAdmin

Bases: ModelAdmin

list_display = ['entry__name', 'entry__collection', 'author', 'last_edit_datetime', 'published_datetime', 'is_deleted'] class-attribute instance-attribute

list_filter = ['status', 'is_deleted', 'is_active'] class-attribute instance-attribute

search_fields = ['entry__name', 'author__first_name', 'author__last_name'] class-attribute instance-attribute

ordering = ['-last_edit_datetime'] class-attribute instance-attribute

autocomplete_fields = ['entry', 'author'] class-attribute instance-attribute

EntryVersionBlock

Bases: HistoryModelMixin, OrderingModelMixin

version = models.ForeignKey(EntryVersion, on_delete=models.CASCADE, related_name='blocks', related_query_name='block') class-attribute instance-attribute

type = models.CharField(max_length=32, choices=BlockTypeChoices, default=BlockTypeChoices.TEXT) class-attribute instance-attribute

objects = EntryVersionBlockQuerySet.as_manager() class-attribute instance-attribute

services = EntryVersionBlockService() class-attribute instance-attribute

editor_js_block_data property writable

Meta

verbose_name = 'Block' class-attribute instance-attribute
verbose_name_plural = 'Blocks' class-attribute instance-attribute
db_table = 'django_spire_knowledge_entry_version_block' class-attribute instance-attribute

update_editor_js_block_data_from_dict

Source code in django_spire/knowledge/entry/version/block/models.py
def update_editor_js_block_data_from_dict(self, value: dict):
    self.editor_js_block_data = EDITOR_JS_BLOCK_DATA_MAP[self.type](**value)

render_to_text

Source code in django_spire/knowledge/entry/version/block/models.py
def render_to_text(self) -> str:
    return self.editor_js_block_data.render_to_text()

EntryVersionBlockAdmin

Bases: ModelAdmin

list_display = ['version__entry__name', 'type', '_block_data', 'is_deleted'] class-attribute instance-attribute

list_filter = ['type', 'is_deleted', 'is_active'] class-attribute instance-attribute

search_fields = ['version__entry__name'] class-attribute instance-attribute

ordering = ['-created_datetime'] class-attribute instance-attribute

autocomplete_fields = ['version'] class-attribute instance-attribute

admin_changelist_url

Source code in django_spire/contrib/admin/links.py
def admin_changelist_url(model_class: type[Model], **filters: str) -> str:
    meta = model_class._meta
    url = reverse(f'admin:{meta.app_label}_{meta.model_name}_changelist')

    if not filters:
        return url

    return f'{url}?{urlencode(filters)}'