django-publicmanager
The django-publicmanager application provides a custom queryset class and managers that handle the public availability of database objects. The classes provide a public method that filters by boolean is_public and date based pub_date fields.
Installation
All you need to install the django-publicmanager package is a simple sudo easy_install dango-publicmanager.
Usage
The package contains just two managers. The manager GenericPublicManager works exactly like django’s default manager except that it provides a public() method that returns only public available objects. The athor manager, PublicOnlyManager, returns public objects by default without calling any extra method.
It should be obvious that you will at least need a model to use one or both of these managers. The managers will use one or more of the following fields to determine if an object is public or not.
is_public: This must be a models.BooleanField and if it is set to True, it will be treated as public.
pub_date must be a models.DateTimeField or models.DateField. The date must be either in the past or equal to the current time to make the object public.
You can use a status field which holds information about the public availability of the object. To use it you must provide the status_attr and status_values attributes to the manager. The status_attr specifies the field name. If the field’s value is found in list status_values the object will be public. The most common use of this feature is to use it with choices. See the examples below.
An object is only public if all of these fields, if existent in the model, are evaluated to be public. This means if is_public is set to True but pub_date points to a date in the future the whole objects will be treated as not public.
Examples
Here is a pretty simple example using only the is_public and pub_date fields:
from django.db import models
from django_publicmanager.managers import GenericPublicManager, PublicOnlyManager
class Example(models.Model):
title = models.CharField(max_length=50)
is_public = models.BooleanField(default=True)
pub_date = models.DateTimeField()
objects = GenericPublicManager()
public = PublicOnlyManager()
Now you can access the objects like this:
>>> Example.objects.create(title='A', is_public=True, pub_date=datetime.now()) >>> Example.objects.create(title='B', is_public=True, pub_date=datetime.now() + timedelta(1)) >>> Example.objects.create(title='C', is_public=False, pub_date=datetime.now()) >>> Example.objects.create(title='D', is_public=True, pub_date=datetime.now() - timedelta(1)) >>> Example.objects.all() [<Example: A>, <Example: B>, <Example: C>, <Example: D>] >>> Example.objects.public() [<Example: A>, <Example: D>] >>> Example.public.all() [<Example: A>, <Example: D>] >>> Example.objects.public() [<Example: A>, <Example: D>] >>> Example.objects.filter(title='A').public() [<Example: A>]
You don’t have to name the fields exactly like above. But if you use athor names, you have to tell the managers the new names:
from django.db import models
from django_publicmanager.managers import GenericPublicManager, PublicOnlyManager
class Example(models.Model):
title = models.CharField(max_length=50)
online = models.BooleanField(default=True)
available_from = models.DateTimeField()
objects = GenericPublicManager(
is_public_attr='online',
pub_date_attr='available_from')
public = PublicOnlyManager(
is_public_attr='online',
pub_date_attr='available_from')
Last but not least, an example with the status field:
from django.db import models
from django_publicmanager.managers import GenericPublicManager, PublicOnlyManager
class Example(models.Model):
STATUS_CHOICES = (
(1, 'draft'),
(2, 'review'),
(3, 'public'),
(4, 'featured'),
)
title = models.CharField(max_length=50)
status = models.PositiveIntegerField(choices=STATUS_CHOICES)
objects = GenericPublicManager(
status_attr='status',
status_values=(3,4))
public = PublicOnlyManager(
status_attr='status',
status_values=(3,4))
Changelog
0.3.0 - 2009-12-30
First release on the python package index.
0.9.1 - 2010-02-04
Adding support for django current trunk which will be 1.2
0.9.2 - 2010-02-04
Fixing bug with clones of PublicQuerySet. It didn’t filter for public attributes.
Metadata
Release files for django-publicmanager 0.9.2
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 | |
|---|---|---|---|---|
| django-publicmanager-0.9.2.tar.gz | 5.2 kB | Without provenance | Details |
Release files / django-publicmanager-0.9.2.tar.gz
| Download URL | django-publicmanager-0.9.2.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
31429e09d04c6165b674fa94825b14cd32290b89461c419a4c73bf15b7b7ce89
|
|
BLAKE2b-256 checksum How to use checksums |
b66891681043b120d5bc5e01aad5df5501ed6aac155db919630d64c84033d1ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-publicmanager 0.9.2
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.