django-popularity-mixin
Simple integration between django-cacheback and django-hitcount
Authored by Basil Shubin
Requirements
You must have django-cacheback and django-hitcount both installed and configured, see the django-cacheback and django-hitcount documentation for details and setup instructions.
Installation
First install the module, preferably in a virtual environment. It can be installed from PyPI:
pip install django-popularity-mixin
Setup
Make sure the project is configured for django-cacheback and django-hitcount.
Then add the following settings:
INSTALLED_APPS += (
'popularity',
)
Usage
The popularity.views.PopularityMixin can be used to do the business-logic of counting the hits asynchronously by setting count_hit to True.
# views.py
from django.views.generic.detail import DetailView
from popularity.views import PopularityMixin
class CustomDetailView(PopularityMixin, DetailView):
count_hit = True # set to True if you want it to try and count the hit asynchronously
template_name = "template.html"
...
The popularity.viwes.PopularityMixin extends Django’s generic django.views.generic.detail.DetailView and injects an additional context variable hitcount.
<!-- template.html -->
{# the primary key for the hitcount object #}
{{ hitcount.pk }}
{# the total hits for the object #}
{{ hitcount.total_hits }}
For a more granular approach to viewing the hits for a related object you can use the get_hit_count template tag.
{# remember to load the tags first #}
{% load popularity_tags %}
{# Return total hits for an object: #}
{% get_hit_count for [object] %}
{# Get total hits for an object as a specified variable: #}
{% get_hit_count for [object] as [var] %}
{# Get total hits for an object over a certain time period: #}
{% get_hit_count for [object] within ["days=1,minutes=30"] %}
{# Get total hits for an object over a certain time period as a variable: #}
{% get_hit_count for [object] within ["days=1,minutes=30"] as [var] %}
Please see example application. This application is used to manually test the functionalities of this package. This also serves as good example…
You need Django 1.8.1 or above to run that. It might run on older versions but that is not tested.
Contributing
If you like this module, forked it, or would like to improve it, please let us know! Pull requests are welcome too. :-)
Metadata
Release files for django-popularity-mixin 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-popularity-mixin-0.1.8.tar.gz | 8.6 kB | Without provenance | Details for django-popularity-mixin-0.1.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_popularity_mixin-0.1.8-py3-none-any.whl | Python 3 | none | any | Details for django_popularity_mixin-0.1.8-py3-none-any.whl |
Total release size: 19.2 kB
Release files / django-popularity-mixin-0.1.8.tar.gz
| Download URL | django-popularity-mixin-0.1.8.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
be204bf21336e7c5e4bc5027027cfe22722402e49b6fc9e8a4dec8dc28de0eb4
|
|
BLAKE2b-256 checksum How to use checksums |
6ea76bcbe23af096726731f6cd14297b2156606b0137fa82aa33d8a89bb82bd7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.7
|
Release files / django_popularity_mixin-0.1.8-py3-none-any.whl
| Download URL | django_popularity_mixin-0.1.8-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5306df0cd588d57792af5961d6dd690b2823c949734332ce7e99d1bce234ffcc
|
|
BLAKE2b-256 checksum How to use checksums |
a0ecf7bae238b05ba154f6eabdf8d314a0fe1fb58e9b7a7e56df29e27805e6b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.7
|
Security for django-popularity-mixin 0.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.