mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-05 05:37:50 +02:00
Add a custom manager to filter private and unpublished stuff (#39)
* Implement a customer manager for flatpages * Implement public manager for private objects * Add support for unpublished objects in roster and consist * Add support for unpublished objects in bookshelf * Update filtering on REST views * Use uuid in urls.py * Increment version
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from ram.utils import git_suffix
|
||||
|
||||
__version__ = "0.13.0"
|
||||
__version__ = "0.13.1"
|
||||
__version__ += git_suffix(__file__)
|
||||
|
19
ram/ram/managers.py
Normal file
19
ram/ram/managers.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from django.db import models
|
||||
from django.core.exceptions import FieldError
|
||||
|
||||
|
||||
class PublicManager(models.Manager):
|
||||
def get_published(self, user):
|
||||
if user.is_authenticated:
|
||||
return self.get_queryset()
|
||||
else:
|
||||
return self.get_queryset().filter(published=True)
|
||||
|
||||
def get_public(self, user):
|
||||
if user.is_authenticated:
|
||||
return self.get_queryset()
|
||||
else:
|
||||
try:
|
||||
return self.get_queryset().filter(private=False)
|
||||
except FieldError:
|
||||
return self.get_queryset().filter(property__private=False)
|
@@ -1,9 +1,25 @@
|
||||
import os
|
||||
from uuid import uuid4
|
||||
|
||||
from django.db import models
|
||||
from django.utils.safestring import mark_safe
|
||||
from tinymce import models as tinymce
|
||||
|
||||
from ram.utils import DeduplicatedStorage, get_image_preview
|
||||
from ram.managers import PublicManager
|
||||
|
||||
|
||||
class BaseModel(models.Model):
|
||||
uuid = models.UUIDField(primary_key=True, default=uuid4, editable=False)
|
||||
notes = tinymce.HTMLField(blank=True)
|
||||
creation_time = models.DateTimeField(auto_now_add=True)
|
||||
updated_time = models.DateTimeField(auto_now=True)
|
||||
published = models.BooleanField(default=True)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
objects = PublicManager()
|
||||
|
||||
|
||||
class Document(models.Model):
|
||||
@@ -28,6 +44,8 @@ class Document(models.Model):
|
||||
'<a href="{0}" target="_blank">Link</a>'.format(self.file.url)
|
||||
)
|
||||
|
||||
objects = PublicManager()
|
||||
|
||||
|
||||
class Image(models.Model):
|
||||
order = models.PositiveIntegerField(default=0, blank=False, null=False)
|
||||
@@ -48,6 +66,8 @@ class Image(models.Model):
|
||||
abstract = True
|
||||
ordering = ["order"]
|
||||
|
||||
objects = PublicManager()
|
||||
|
||||
|
||||
class PropertyInstance(models.Model):
|
||||
property = models.ForeignKey(
|
||||
@@ -62,3 +82,5 @@ class PropertyInstance(models.Model):
|
||||
class Meta:
|
||||
abstract = True
|
||||
verbose_name_plural = "Properties"
|
||||
|
||||
objects = PublicManager()
|
||||
|
Reference in New Issue
Block a user