Permalink
Browse files

Issue #25: Filter on the current site

  • Loading branch information...
1 parent ee83f05 commit 7a40e8d59f9ad4e7df7599c58b3006cdbd17e0fd @erlenddalen committed May 27, 2013
@@ -11,7 +11,7 @@
# TODO: Ordering of tree by column (within parent) should be possible
# TODO: Refactor SWFUpload stuff as extension. This would require signals calls
# to be called in the FileNodeAdmin view methods.
-
+from django.contrib.sites.models import Site
from media_tree.fields import FileNodeChoiceField
from media_tree.models import FileNode
@@ -132,6 +132,10 @@ def __init__(self, *args, **kwargs):
# http://stackoverflow.com/questions/1618728/disable-link-to-edit-object-in-djangos-admin-display-list-only
self.list_display_links = (None, )
+ def queryset(self, request):
+ qs = super(FileNodeAdmin, self).queryset(request)
+ return qs.filter(site=Site.objects.get_current())
+
def formfield_for_dbfield(self, db_field, **kwargs):
if db_field.name == 'parent' and issubclass(db_field.rel.to, FileNode):
# overriding formfield_for_dbfield, thus bypassign both Django's and mptt's
@@ -1,3 +1,4 @@
+from django.contrib.sites.models import Site
from media_tree.contrib.cms_plugins.media_tree_image.models import MediaTreeImage
from media_tree.contrib.cms_plugins.forms import MediaTreePluginFormBase
from media_tree.contrib.views.detail.image import ImageNodeDetailMixin
@@ -9,9 +10,15 @@
from django.utils.translation import ugettext_lazy as _
# TODO: Solve image_detail with get_absolute_url()?
+from media_tree.models import FileNode
class MediaTreeImagePluginForm(MediaTreePluginFormBase):
+
+ def __init__(self, *args, **kwargs):
+ super(MediaTreeImagePluginForm, self).__init__(*args, **kwargs)
+ self.fields['node'].queryset = FileNode.objects.filter(site=Site.objects.get_current())
+
class Meta:
model = MediaTreeImage
@@ -1,3 +1,4 @@
+from django.contrib.sites.models import Site
from media_tree import media_types
from media_tree.contrib.cms_plugins import settings as plugins_settings
from media_tree.fields import FileNodeForeignKey, DimensionField
@@ -6,6 +7,11 @@
from django.utils.translation import ugettext_lazy as _
+class MediaTreeImageSiteManager(models.Manager):
+ def get_query_set(self):
+ return super(MediaTreeImageSiteManager, self).get_query_set().filter(node__site=Site.objects.get_current())
+
+
class MediaTreeImage(CMSPlugin):
node = FileNodeForeignKey(allowed_media_types=(media_types.SUPPORTED_IMAGE,), verbose_name=_('file'))
link_type = models.CharField(_('link type'), max_length=1, blank=True, null=True, default=plugins_settings.MEDIA_TREE_CMS_PLUGIN_LINK_TYPE_DEFAULT, choices=plugins_settings.MEDIA_TREE_CMS_PLUGIN_LINK_TYPE_CHOICES, help_text=_('Makes the image a clickable link.'))
@@ -16,5 +22,7 @@ class MediaTreeImage(CMSPlugin):
height = DimensionField(_('max. height'), null=True, blank=True, help_text=_('You can leave this empty to use an automatically determined image height.'))
render_template = models.CharField(_("template"), max_length=100, choices=None, blank=True, null=True, help_text=_('Template used to render the image.'))
+ objects = MediaTreeImageSiteManager()
+
def __unicode__(self):
return self.node.__unicode__()
@@ -1,3 +1,4 @@
+from django.contrib.sites.models import Site
from media_tree.models import FileNode
from media_tree.contrib.views.mixin_base import PluginMixin
from django.views.generic.detail import DetailView
@@ -75,6 +76,7 @@ def get_object(self, queryset=None):
def get_queryset(self, *args, **kwargs):
queryset = super(FileNodeDetailView, self).get_queryset(*args, **kwargs)
+ queryset = queryset.filter(node__site=Site.objects.get_current())
kwargs = {}
if self.filter_node_types:
kwargs['node_type__in'] = self.filter_node_types
View
@@ -31,7 +31,7 @@ def __init__(self, allowed_node_types=None, allowed_media_types=None, allowed_ex
self.allowed_node_types = allowed_node_types
self.allowed_media_types = allowed_media_types
self.allowed_extensions = allowed_extensions
- kwargs['level_indicator'] = level_indicator;
+ kwargs['level_indicator'] = level_indicator
if not kwargs.has_key('widget'):
kwargs['widget'] = self.widget
View
@@ -87,7 +87,7 @@ def filter(self, *args, **kwargs):
"""
if 'path' in kwargs:
kwargs = self.get_filter_args_with_path(False, **kwargs)
- return super(FileNodeManager, self).filter(*args, **kwargs)
+ return super(FileNodeManager, self).filter(site=Site.objects.get_current()).filter(*args, **kwargs)
def exclude(self, *args, **kwargs):
"""
@@ -98,7 +98,7 @@ def exclude(self, *args, **kwargs):
"""
if 'path' in kwargs:
kwargs = self.get_filter_args_with_path(False, **kwargs)
- return super(FileNodeManager, self).exclude(*args, **kwargs)
+ return super(FileNodeManager, self).filter(site=Site.objects.get_current()).exclude(*args, **kwargs)
def get(self, *args, **kwargs):
"""
@@ -316,7 +316,8 @@ def get_node_path(self):
return nodes
def get_folder_tree(self):
- return self._tree_manager.all().filter(node_type=FileNode.FOLDER)
+ return self._tree_manager.all().filter(node_type=FileNode.FOLDER,
+ site=Site.objects.get_current())
def get_default_file(self, media_types=None):
if self.node_type == FileNode.FOLDER:

0 comments on commit 7a40e8d

Please sign in to comment.