API Reference#
This reference provides detailed information about the modules and classes in the django-help app.
Models#
Models for django_help.
- class django_help.models.ArticleUpload(*args, **kwargs)[source]#
Bases:
ModelStores uploaded files for articles.
- Parameters:
id (BigAutoField) – ID
upload (FileField) – upload
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- property extension#
Return the extension of the upload.
- property filename#
Return the filename of the upload.
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>#
- upload#
The descriptor for the file attribute on the model instance. Return a FieldFile when accessed so you can write code like:
>>> from myapp.models import MyModel >>> instance = MyModel.objects.get(pk=1) >>> instance.file.size
Assign a file object on assignment so you can do:
>>> with open('/path/to/hello.world') as f: ... instance.file = File(f)
- class django_help.models.DjangoHelpArticle(*args, **kwargs)[source]#
Bases:
ModelStores articles.
- Parameters:
id (BigAutoField) – ID
title_en (CharField) – The title of this article.
title_es (CharField) – The title of this article.
title_fr (CharField) – The title of this article.
subtitle_en (CharField) – A subtitle for this article.
subtitle_es (CharField) – A subtitle for this article.
subtitle_fr (CharField) – A subtitle for this article.
slug (SlugField) – A web address friendly version of the title.
category_id (ForeignKey) – The category this article belongs to, if any.
article_content_en (MarkdownxField) – The content of this article. Markdown is supported.
article_content_es (MarkdownxField) – The content of this article. Markdown is supported.
article_content_fr (MarkdownxField) – The content of this article. Markdown is supported.
views (PositiveIntegerField) – The number of times this article has been viewed.
icon (CharField) – The icon and text color to use for this article.
public (BooleanField) – Check this box to make this article public.
highlighted (BooleanField) – Check this box to highlight this article on the index page.
intended_entity_type (CharField) – The type of entity this article applies to.
created (DateTimeField) – created
modified (DateTimeField) – modified
tags (TaggableManager) – A comma-separated list of tags.
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- article_content#
- article_content_en#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- article_content_es#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- article_content_fr#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- category#
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.
- category_id#
- content_preview(length=100)[source]#
Return a preview of the content, truncated to the specified length.
- created#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_intended_entity_type_display(*, field=<django.db.models.fields.CharField: intended_entity_type>)#
- get_next_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=True, **kwargs)#
- get_next_by_modified(*, field=<django.db.models.fields.DateTimeField: modified>, is_next=True, **kwargs)#
- get_previous_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=False, **kwargs)#
- get_previous_by_modified(*, field=<django.db.models.fields.DateTimeField: modified>, is_next=False, **kwargs)#
- highlighted#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- icon#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- intended_entity_type#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- modified#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.DjangoHelpArticleManagerFromDjangoHelpArticleQuerySet object>#
- public#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- relevant_paths#
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- slug#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- subtitle#
- subtitle_en#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- subtitle_es#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- subtitle_fr#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- taggedarticles_set#
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- tags = <taggit.managers._TaggableManager object>#
- title#
- title_en#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- title_es#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- title_fr#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- views#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class django_help.models.DjangoHelpArticleManager(*args, **kwargs)[source]#
Bases:
ManagerManager for DjangoHelpArticle.
- class django_help.models.DjangoHelpArticleQuerySet(model=None, query=None, using=None, hints=None)[source]#
Bases:
QuerySetQuerySet for DjangoHelpArticle.
- get_for_category(category, multiple=False)[source]#
Return article(s) matching the specified category.
If single is True (default), return only the first article.
- Parameters:
category (str) –
- get_for_path(path, multiple=False)[source]#
Return article(s) matching the specified path.
If single is True (default), return only the first article.
- Parameters:
path (str | HttpRequest) –
- get_for_slug(slug, multiple=False)[source]#
Return article(s) matching the specified slug.
If single is True (default), return only the first article.
- Parameters:
slug (str) –
- get_for_tag(tag, multiple=False)[source]#
Return article(s) matching the specified tag.
If single is True (default), return only the first article.
- Parameters:
tag (str) –
- class django_help.models.DjangoHelpCategory(*args, **kwargs)[source]#
Bases:
ModelStores categories.
- Parameters:
id (BigAutoField) – ID
title_en (CharField) – The title of this category.
title_es (CharField) – The title of this category.
title_fr (CharField) – The title of this category.
subtitle_en (CharField) – A subtitle for this category.
subtitle_es (CharField) – A subtitle for this category.
subtitle_fr (CharField) – A subtitle for this category.
slug (SlugField) – A web address friendly version of the title.
description_en (CharField) – A description of this category.
description_es (CharField) – A description of this category.
description_fr (CharField) – A description of this category.
icon (CharField) – The icon and text color to use for this category.
public (BooleanField) – Check this box to make this category public.
intended_entity_type (CharField) – The type of entity this category applies to.
created (DateTimeField) – created
modified (DateTimeField) – modified
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- property article_count#
Return the number of article in this category.
- articles#
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- created#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- description#
- description_en#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- description_es#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- description_fr#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_intended_entity_type_display(*, field=<django.db.models.fields.CharField: intended_entity_type>)#
- get_next_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=True, **kwargs)#
- get_next_by_modified(*, field=<django.db.models.fields.DateTimeField: modified>, is_next=True, **kwargs)#
- get_previous_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=False, **kwargs)#
- get_previous_by_modified(*, field=<django.db.models.fields.DateTimeField: modified>, is_next=False, **kwargs)#
- icon#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- intended_entity_type#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- modified#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.DjangoHelpCategoryManagerFromDjangoHelpCategoryQuerySet object>#
- public#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- property short_description#
Return a short description of this category.
- slug#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- subtitle#
- subtitle_en#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- subtitle_es#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- subtitle_fr#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- title#
- title_en#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- title_es#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- title_fr#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class django_help.models.DjangoHelpCategoryManager(*args, **kwargs)[source]#
Bases:
ManagerManager for DjangoHelpCategory.
- class django_help.models.DjangoHelpCategoryQuerySet(model=None, query=None, using=None, hints=None)[source]#
Bases:
QuerySetQuerySet for DjangoHelpCategory.
- class django_help.models.RelevantPath(*args, **kwargs)[source]#
Bases:
ModelStores a relevant path for an article.
A relevant path is a path that is relevant to the article. For example, if the article is about creating a new provider, then the relevant path might be /providers/create.
Wildcards are supported. For example, if the article is about creating a new provider, then the relevant path might be /providers/*.
- Parameters:
id (BigAutoField) – ID
path (CharField) – The relevant path for this article. Wildcards are supported.
article_id (ForeignKey) – article
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- article#
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.
- article_id#
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- property is_wildcard#
Return True if the path is a wildcard path.
- objects = <django.db.models.manager.Manager object>#
- path#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class django_help.models.Tag(*args, **kwargs)[source]#
Bases:
TagBase,ModelCustomized Taggit Tag model.
- Parameters:
id (BigAutoField) – ID
name (CharField) – name
slug (SlugField) – slug
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- django_help_taggedarticles_items#
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- name#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- slug#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class django_help.models.TaggedArticles(*args, **kwargs)[source]#
Bases:
ItemBase,ModelStores tagged articles.
- Parameters:
id (BigAutoField) – ID
content_object_id (ForeignKey) – content object
tag_id (ForeignKey) – tag
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- content_object#
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.
- content_object_id#
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- tag#
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.
- tag_id#
Views#
Views for django_help.
- django_help.views.category(request, category_slug)#
The category page for django_help.
Provides: - a list of categories - a list of articles in the current category
- Parameters:
request (HttpRequest) –
category_slug (str) –
- Return type:
- django_help.views.get_articles(request, *, category=None, slug=None, tag=None)#
Fetches articles based on category, slug, or tag.
- Parameters:
- Return type:
- django_help.views.index(request)#
The main django_help page.
Provides: - a search box - an option for admins to create new articles - a list of popular articles - a list of highlighted articles, and - a list of recent articles.
- Parameters:
request (HttpRequest) –
- Return type:
Forms#
Forms for django_help.
- class django_help.forms.ArticleUploadForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)[source]#
Bases:
ModelFormForm for uploading articles in admin.
- class Meta[source]#
Bases:
objectMeta class for ArticleUploadForm.
- fields = ['upload']#
- model#
alias of
ArticleUpload
- base_fields = {'upload': <django.forms.fields.FileField object>}#
- declared_fields = {}#
- property media#
Return all media required to render the widgets on this form.
- class django_help.forms.DjangoHelpArticleForm(*args, **kwargs)[source]#
Bases:
ModelFormForm for creating and editing articles.
- class Meta[source]#
Bases:
objectMeta class for DjangoHelpArticleForm.
- fields = ('title_en', 'title_es', 'title_fr', 'subtitle_en', 'subtitle_es', 'subtitle_fr', 'category', 'article_content_en', 'article_content_es', 'article_content_fr', 'icon', 'public', 'highlighted', 'intended_entity_type', 'tags')#
- model#
alias of
DjangoHelpArticle
- widgets = {'article_content_en': <markdownx.widgets.MarkdownxWidget object>, 'article_content_es': <markdownx.widgets.MarkdownxWidget object>, 'article_content_fr': <markdownx.widgets.MarkdownxWidget object>}#
- base_fields = {'article_content_en': <markdownx.fields.MarkdownxFormField object>, 'article_content_es': <markdownx.fields.MarkdownxFormField object>, 'article_content_fr': <markdownx.fields.MarkdownxFormField object>, 'category': <django.forms.models.ModelChoiceField object>, 'highlighted': <django.forms.fields.BooleanField object>, 'icon': <django.forms.fields.CharField object>, 'intended_entity_type': <django.forms.fields.TypedChoiceField object>, 'public': <django.forms.fields.BooleanField object>, 'subtitle_en': <django.forms.fields.CharField object>, 'subtitle_es': <django.forms.fields.CharField object>, 'subtitle_fr': <django.forms.fields.CharField object>, 'tags': <taggit.forms.TagField object>, 'title_en': <django.forms.fields.CharField object>, 'title_es': <django.forms.fields.CharField object>, 'title_fr': <django.forms.fields.CharField object>}#
- declared_fields = {}#
- formfield_callback(**kwargs)#
- property media#
Return all media required to render the widgets on this form.
- class django_help.forms.RelevantPathForm(*args, **kwargs)[source]#
Bases:
ModelFormForm for creating RelevantPath instances.
- class Meta[source]#
Bases:
objectMeta class for RelevantPathForm.
- fields = ('path',)#
- model#
alias of
RelevantPath
- base_fields = {'path': <django.forms.fields.CharField object>}#
- declared_fields = {}#
- property media#
Return all media required to render the widgets on this form.
Admin#
Admin configuration for django_help.
- class django_help.admin.DjangoHelpArticleAdmin(model, admin_site)[source]#
Bases:
TranslatedFieldAdmin,MarkdownxModelAdminAdmin configuration for DjangoHelpArticle instances.
- actions = [<function export_articles>]#
- fieldsets = (('title', {'fields': ['title_en', 'title_es', 'title_fr']}), ('subtitle', {'fields': ['subtitle_en', 'subtitle_es', 'subtitle_fr']}), ('article_content', {'fields': ['article_content_en', 'article_content_es', 'article_content_fr']}), ('', {'fields': ['category', 'slug', 'icon', 'public', 'highlighted', 'intended_entity_type', 'tags']}))#
- inlines = [<class 'django_help.admin.RelevantPathInline'>]#
- list_display = ('title_en', 'slug', 'subtitle_en', 'category', 'icon', 'public', 'highlighted', 'intended_entity_type', 'views', 'tag_list', 'created', 'modified')#
- list_filter = ('public', 'category', 'intended_entity_type', 'highlighted')#
- property media#
- prepopulated_fields = {'slug': ('title_en',)}#
- readonly_fields = ('created', 'modified')#
- search_fields = ('title_en', 'title_es', 'title_fr', 'subtitle_en', 'subtitle_es', 'subtitle_fr', 'article_content_en', 'article_content_es', 'article_content_fr', 'slug', 'tags')#
- class django_help.admin.DjangoHelpCategoryAdmin(model, admin_site)[source]#
Bases:
TranslatedFieldAdmin,ModelAdminAdmin configuration for DjangoHelpCategory instances.
- fieldsets = (('title', {'fields': ['title_en', 'title_es', 'title_fr']}), ('subtitle', {'fields': ['subtitle_en', 'subtitle_es', 'subtitle_fr']}), ('description', {'fields': ['description_en', 'description_es', 'description_fr']}), ('', {'fields': ['slug', 'icon', 'intended_entity_type', 'public', 'created', 'modified']}))#
- list_display = ('title_en', 'slug', 'subtitle_en', 'icon', 'intended_entity_type', 'public', 'created', 'modified')#
- list_filter = ('public', 'intended_entity_type')#
- property media#
- prepopulated_fields = {'slug': ('title_en',)}#
- readonly_fields = ('created', 'modified')#
- search_fields = ('title_en', 'title_es', 'title_fr', 'subtitle_en', 'subtitle_es', 'subtitle_fr', 'description_en', 'description_es', 'description_fr', 'slug')#
- class django_help.admin.RelevantPathInline(parent_model, admin_site)[source]#
Bases:
TabularInlineInline for RelevantPath instances.
- extra = 0#
- property media#
- model#
alias of
RelevantPath
Utils#
Exporting#
Utility functions for exporting DjangoHelpArticle instances to Markdown or ZIP.
- django_help.utils.exporting.article_to_markdown(article)[source]#
Convert a DjangoHelpArticle instance to a Markdown string for each language.
- Parameters:
article (DjangoHelpArticle) –
- Return type:
Importing#
Utility functions for importing articles from Markdown files or ZIP archives.
- class django_help.utils.importing.ArticleManager[source]#
Bases:
objectClass to manage the creation and updating of DjangoHelpArticle instances from metadata and Markdown content.
- extract_language_contents(content)[source]#
Extract and map content to languages based on headers in the markdown.
- handle_zip_file(zip_file)[source]#
Extract and process each Markdown file in a ZIP archive.
- Parameters:
zip_file (str | SpooledTemporaryFile) –
- Return type:
None
- manage_categories(metadata, defaults)[source]#
Manage category creation or fetching.
Uses the primary language title to create or fetch the category, and then sets the category for the article.
- manage_relevant_paths(article, metadata)[source]#
Clear and update relevant paths.
- Parameters:
article (DjangoHelpArticle) –
metadata (Dict) –
- Return type:
None
- manage_tags(article, metadata)[source]#
Update article tags.
- Parameters:
article (DjangoHelpArticle) –
metadata (Dict) –
- Return type:
None
- process_markdown_metadata(markdown_content)[source]#
Parse markdown content and prepare metadata including language-specific content.
- process_md_file(markdown_file)[source]#
Process a markdown file and create or update a DjangoHelpArticle instance.
- Parameters:
markdown_file (str | SpooledTemporaryFile) –
- Return type:
- read_markdown_content(markdown_file)[source]#
Read markdown content from a file or file-like object.
- Parameters:
markdown_file (str | SpooledTemporaryFile) –
- Return type:
- django_help.utils.importing.upload_articles(request)[source]#
Insert upload handler before processing uploaded files.
We must ensure here that uploaded files are handled as temporary files See: https://docs.djangoproject.com/en/5.1/topics/http/file-uploads/#modifying-upload-handlers-on-the-fly
- Parameters:
request (HttpRequest) –
Queryset#
Queryset utilities for the Django Help app.
- django_help.utils.queryset.annotate_with_values_fields(queryset, values_fields)[source]#
Annotates the queryset with the values fields.
- For instance, if values_fields = [“title”], the queryset will be annotated with title=to_attribute(“title”),
ensuring the current language is used. e.g.: If the currentl language is ‘en’, the annotation will convert title_en to title.
- django_help.utils.queryset.filter_articles(request, category, slug, tag)[source]#
Filters articles based on user permissions and provided parameters.
Note: This is a helper function for get_articles.
- Parameters:
- Return type:
- django_help.utils.queryset.filter_user_can_view(request, articles_or_categories)[source]#
Filters QuerySet to return only public articles or categories based on the user’s entity context.
- Parameters:
request (HttpRequest) –
articles_or_categories (Union[DjangoHelpArticleQuerySet, DjangoHelpCategoryQuerySet]) –
- Return type:
Union[DjangoHelpArticleQuerySet, DjangoHelpCategoryQuerySet]
Regex#
Regex utilities for Django.
Validation#
Validation utilities for the Django Help app.
- django_help.utils.validation.user_authorized_to_view(request, article)[source]#
Raises a 404 error if the user is not allowed to view the article.
- Parameters:
request (HttpRequest) –
article (DjangoHelpArticle) –
- Return type:
Optional[Http404]
App Settings#
Settings for the django_help app.
Use the DJANGO_HELP_CONFIG setting to configure the app. For example:
DJANGO_HELP_CONFIG = {
"BASE_MANAGER": "myapp.models.MyManager",
"BASE_QUERYSET": "myapp.models.MyQuerySet",
"BASE_MODEL": "myapp.models.MyModel",
"BASE_FOREIGN_KEY": "myapp.models.MyForeignKey",
"EXTRA_LANGUAGES": {
"es": {"blank": False}, # Spanish fields must be filled out.
"fr": {"blank": True}, # French fields can be left blank.
},
"AUTHORIZE_USER_TO_VIEW_ARTICLE": "myapp.utils.authorize_user_to_view_article",
"INTENDED_ENTITY_TYPE": {
"PERSON": ("person", "Person"),
"ORGANIZATION": ("organization", "Organization"),
},
}
Choices#
This module contains the choices for the models in the django_help app.
URLs#
URLs for django_help.