Source code for superdjango.contrib.support.models

# Imports

from django.conf import settings
# from django.contrib.auth.models import Group
from django.db import models
# from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _
from superdjango.db.audit.models import AddedByModel, ModifiedByModel
from superdjango.db.datetime.fields import AutoNowAddDateTimeField, AutoNowDateTimeField

# Exports

__all__ = (
    "HelpComment",
    "HelpRanking",
    "SearchCatalog",
    "SearchResult",
)

# Constants

AUTH_USER_MODEL = settings.AUTH_USER_MODEL

# Models


[docs]class HelpComment(AddedByModel, ModifiedByModel): """A user comment on a specific help page.""" body = models.TextField( _("body"), blank=True, help_text=_("The comment body."), null=True ) page = models.CharField( _("page"), help_text=_("The page identifier where the comment was made."), max_length=256 ) subject = models.CharField( _("subject"), help_text=_("The title, question, or subject of the comment."), max_length=128 ) class Meta: verbose_name = _("Help Comment") verbose_name_plural = _("Help Comments") def __str__(self): return self.subject
[docs]class HelpRanking(AddedByModel, ModifiedByModel): """A user ranking of the usefulness of a specific help page.""" page = models.CharField( _("page"), help_text=_("The page identifier where the ranking was made."), max_length=256 ) score = models.PositiveSmallIntegerField( _("score"), help_text=_("The score."), ) class Meta: verbose_name = _("Help Ranking") verbose_name_plural = _("Help Rankings") def __str__(self): return str(self.score)
[docs]class SearchCatalog(models.Model): """Stores search terms, source files, and URLs used to create search results.""" added_dt = AutoNowAddDateTimeField( _("added date/time"), help_text=_("Date and time the entry was created.") ) modified_dt = AutoNowDateTimeField( _("modified date/time"), help_text=_("Date and time the entry was last modified.") ) page = models.CharField( _("page"), help_text=_("The page identifier where the match was found."), max_length=256 ) source_file = models.CharField( _("source file"), help_text=_("The original source file/path where the search terms. Note this may change."), max_length=1024 ) terms = models.CharField( _("terms"), help_text=_("The matching search terms."), max_length=128 ) total_matches = models.PositiveSmallIntegerField( _("total matches"), help_text=_("The total number of matches on the page.") ) class Meta: unique_together = ["page", "terms"] verbose_name = _("Search Catalog Entry") verbose_name_plural = _("Search Catalog Entries") def __str__(self): return self.terms
[docs]class SearchResult(AddedByModel): """Optionally stores user search results. Useful for improving help and the search catalog.""" added_dt = AutoNowAddDateTimeField( _("added date/time"), help_text=_("Date and time the entry was created.") ) terms = models.CharField( _("terms"), help_text=_("The matching search terms."), max_length=128 ) total_matches = models.PositiveSmallIntegerField( _("total matches"), default=0, help_text=_("The total number of matches found for the search.") ) class Meta: verbose_name = _("Help Comment") verbose_name_plural = _("Help Comments") def __str__(self): return self.terms