Browse files

Resolving issue #25. Only files uploaded in a certain site shold be s…

…electable in that site.
  • Loading branch information...
1 parent 609adbb commit 16fdcc72525beccefd1698c390187e920793f622 @erlenddalen committed May 24, 2013
Showing with 5 additions and 4 deletions.
  1. +2 −2 media_tree/forms.py
  2. +3 −2 media_tree/models.py
View
4 media_tree/forms.py
@@ -13,7 +13,7 @@ class Meta:
model = FileNode
fieldsets = [
(_('Folder'), {
- 'fields': ['parent', 'name',]
+ 'fields': ['site', 'parent', 'name',]
}),
(_('Metadata'), {
'fields': ['title', 'description']
@@ -42,7 +42,7 @@ class Meta:
fieldsets = [
(_('File'), {
#'fields': ['name', 'file']
- 'fields': ['parent', 'file']
+ 'fields': ['site', 'parent', 'file']
}),
(_('Display'), {
'fields': ['published', 'preview_file', 'position', 'is_default'],
View
5 media_tree/models.py
@@ -62,7 +62,7 @@ def __init__(self, filter_args={}):
self.filter_args = filter_args
def get_query_set(self):
- return super(FileNodeManager, self).get_query_set().filter(**self.filter_args)
+ return super(FileNodeManager, self).get_query_set().filter(site=Site.objects.get_current()).filter(**self.filter_args)
def get_filter_args_with_path(self, for_self, **kwargs):
names = kwargs['path'].strip('/').split('/')
@@ -254,6 +254,7 @@ class FileNode(ModelBase):
extra_metadata = models.TextField(_('extra metadata'), editable=None)
""" Extra metadata """
+ site = models.ForeignKey(Site, null=True, blank=True, related_name='file')
is_ancestor_being_updated = False
@@ -507,7 +508,7 @@ def prevent_save(self):
self.save_prevented = True
def save(self, *args, **kwargs):
-
+ self.site = Site.objects.get_current()
if getattr(self, 'save_prevented', False):
from django.core.exceptions import ValidationError
raise ValidationError('Saving was presented for this FileNode object.')

0 comments on commit 16fdcc7

Please sign in to comment.