Skip to content
Browse files

Issue #25

Also fixing the site issue for the other plugins and use limit_choice_to
to make admin pick up the limitations.
  • Loading branch information...
1 parent 7a40e8d commit 9179cfdf34dcefa2fe85b4d788a67e70764368d1 @erlenddalen committed
View
7 media_tree/admin/actions/core_actions.py
@@ -1,3 +1,4 @@
+from django.contrib.sites.models import Site
from media_tree.models import FileNode
from media_tree.admin.actions.utils import get_actions_context
from media_tree.admin.actions.forms import FileNodeActionsWithUserForm, MoveSelectedForm, CopySelectedForm, ChangeMetadataForSelectedForm
@@ -89,7 +90,8 @@ def copy_selected(modeladmin, request, queryset):
def expand_selected(modeladmin, request, queryset):
expanded_folders_pk = modeladmin.get_expanded_folders_pk(request)
- add_pks = [obj.pk for obj in queryset.filter(node_type=FileNode.FOLDER)]
+ add_pks = [obj.pk for obj in queryset.filter(node_type=FileNode.FOLDER,
+ site=Site.objects.get_current())]
expanded_folders_pk.extend(add_pks)
response = HttpResponseRedirect('')
modeladmin.set_expanded_folders_pk(response, expanded_folders_pk)
@@ -99,7 +101,8 @@ def expand_selected(modeladmin, request, queryset):
def collapse_selected(modeladmin, request, queryset):
expanded_folders_pk = modeladmin.get_expanded_folders_pk(request)
- remove_pks = [obj.pk for obj in queryset.filter(node_type=FileNode.FOLDER)]
+ remove_pks = [obj.pk for obj in queryset.filter(node_type=FileNode.FOLDER,
+ site=Site.objects.get_current())]
expanded_folders_pk = set(expanded_folders_pk).difference(set(remove_pks))
response = HttpResponseRedirect('')
modeladmin.set_expanded_folders_pk(response, expanded_folders_pk)
View
4 media_tree/admin/actions/forms.py
@@ -1,3 +1,4 @@
+from django.contrib.sites.models import Site
from media_tree.models import FileNode
from media_tree.fields import FileNodeChoiceField
from media_tree.forms import MetadataForm
@@ -19,7 +20,8 @@ class FileNodeActionsForm(forms.Form):
def __init__(self, queryset, *args, **kwargs):
self.success_count = 0
super(FileNodeActionsForm, self).__init__(*args, **kwargs)
- valid_targets = FileNode._tree_manager.filter(node_type=FileNode.FOLDER)
+ valid_targets = FileNode._tree_manager.filter(node_type=FileNode.FOLDER,
+ site=Site.objects.get_current())
self.selected_nodes = queryset
selected_nodes_pk = []
View
3 media_tree/contrib/cms_plugins/media_tree_gallery/models.py
@@ -1,3 +1,4 @@
+from django.contrib.sites.models import Site
from media_tree.contrib.cms_plugins.media_tree_listing.models import MediaTreeListingBase
from media_tree.contrib.cms_plugins.media_tree_slideshow.models import MediaTreeImageListingBase, MediaTreeImageItemBase
from media_tree.fields import FileNodeForeignKey
@@ -15,4 +16,4 @@ class MediaTreeGallery(MediaTreeImageListingBase):
class MediaTreeGalleryItem(MediaTreeImageItemBase):
list_plugin = models.ForeignKey(MediaTreeGallery, related_name='media_items')
- node = FileNodeForeignKey(verbose_name=_('folder/file'))
+ node = FileNodeForeignKey(verbose_name=_('folder/file'), limit_choices_to={"site": Site.objects.get_current()})
View
3 media_tree/contrib/cms_plugins/media_tree_image/models.py
@@ -13,7 +13,8 @@ def get_query_set(self):
class MediaTreeImage(CMSPlugin):
- node = FileNodeForeignKey(allowed_media_types=(media_types.SUPPORTED_IMAGE,), verbose_name=_('file'))
+ node = FileNodeForeignKey(allowed_media_types=(media_types.SUPPORTED_IMAGE,), verbose_name=_('file'),
+ limit_choices_to = {"site": Site.objects.get_current()})
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.'))
link_page = models.ForeignKey(Page, verbose_name=_("page"), null=True, blank=True, help_text=_('For link to page. Select any page from the list.'))
link_url = models.CharField(_("web address"), max_length=255, blank=True, null=True, help_text=_('For link to web address. Example: Enter "http://www.domain.com" to create an absolute link to an external site, or enter a relative URL like "/about/contact".'))
View
6 media_tree/contrib/cms_plugins/media_tree_listing/cms_plugins.py
@@ -1,3 +1,4 @@
+from django.contrib.sites.models import Site
from media_tree.contrib.cms_plugins.media_tree_listing.models import MediaTreeListing, MediaTreeListingItem
from media_tree.contrib.cms_plugins.forms import MediaTreePluginFormInlinePositioningBase
from media_tree.contrib.views.listing import FileNodeListingFilteredByFolderMixin
@@ -8,7 +9,7 @@
class MediaTreeListingPluginForm(MediaTreePluginFormInlinePositioningBase):
-
+
class Meta:
model = MediaTreeListing
@@ -36,7 +37,8 @@ class MediaTreeListingPlugin(CMSPluginBase, FileNodeListingFilteredByFolderMixin
filter_by_parent_folder = False
def render(self, context, instance, placeholder):
- selected_nodes = [item.node for item in instance.media_items.all()]
+ selected_nodes = [item.node for item in instance.media_items.filter(
+ node__site=Site.objects.get_current())]
if hasattr(instance, 'filter_supported') and not getattr(instance, 'filter_supported'):
self.list_filter_media_types = None
view = self.get_listing_view(context['request'], selected_nodes, opts=instance)
View
4 media_tree/contrib/cms_plugins/media_tree_listing/models.py
@@ -1,6 +1,6 @@
+from django.contrib.sites.models import Site
from media_tree import media_types
from media_tree.contrib.cms_plugins import settings as app_settings
-from media_tree.models import FileNode
from media_tree.fields import FileNodeForeignKey
from cms.models import CMSPlugin
from django.db import models
@@ -46,4 +46,4 @@ class MediaTreeListing(MediaTreeListingBase):
class MediaTreeListingItem(MediaTreeListingItemBase):
list_plugin = models.ForeignKey(MediaTreeListing, related_name='media_items')
- node = FileNodeForeignKey(verbose_name=_('folder/file'))
+ node = FileNodeForeignKey(verbose_name=_('folder/file'), limit_choices_to={"site": Site.objects.get_current()})
View
3 media_tree/contrib/cms_plugins/media_tree_slideshow/models.py
@@ -1,3 +1,4 @@
+from django.contrib.sites.models import Site
from media_tree.fields import DimensionField
from media_tree.contrib.cms_plugins.media_tree_slideshow import settings as app_settings
from media_tree.contrib.cms_plugins.media_tree_listing.models import MediaTreeListingBase, MediaTreeListingItemBase
@@ -42,4 +43,4 @@ class Meta:
class MediaTreeSlideshowItem(MediaTreeImageItemBase):
list_plugin = models.ForeignKey(MediaTreeSlideshow, related_name='media_items')
- node = FileNodeForeignKey(verbose_name=_('folder/file'))
+ node = FileNodeForeignKey(verbose_name=_('folder/file'), limit_choices_to={"site": Site.objects.get_current()})

0 comments on commit 9179cfd

Please sign in to comment.
Something went wrong with that request. Please try again.