Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Also fixing the site issue for the other plugins and use limit_choice_to
to make admin pick up the limitations.
  • Loading branch information
erlenddalen committed May 28, 2013
1 parent 7a40e8d commit 9179cfd
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.
7 changes: 5 additions & 2 deletions media_tree/admin/actions/core_actions.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion media_tree/admin/actions/forms.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = []
Expand Down
3 changes: 2 additions & 1 deletion media_tree/contrib/cms_plugins/media_tree_gallery/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()})
3 changes: 2 additions & 1 deletion media_tree/contrib/cms_plugins/media_tree_image/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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".'))
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -8,7 +9,7 @@


class MediaTreeListingPluginForm(MediaTreePluginFormInlinePositioningBase):

class Meta:
model = MediaTreeListing

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions media_tree/contrib/cms_plugins/media_tree_listing/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()})
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.