Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Fix publishing of Author.content placeholder field, re #44
Browse files Browse the repository at this point in the history
The `Author.content` placeholder field was not being cloned to the
published copy when an author was published.

- don't assume all placeholder fields are named `placeholder_set` or
  `placeholders` because `Author.content` doesn't follow this pattern.
  Instead, interrogate the model fields to find placeholder
  relationship fields regardless of the name
- make placeholder field lookups for `cms.models`-flavoured versus
  `fluent_contents.models`-flavoured placeholder fields explicit.
  • Loading branch information
jmurty committed Nov 2, 2016
1 parent e90399c commit 984e6cf
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions icekit/publishing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ def is_dirty(self):
return True

# Get all placeholders + their plugins to find their modified date
for placeholder_field in self.get_placeholder_fields():
for placeholder_field in self.get_cms_placeholder_fields():
placeholder = getattr(self, placeholder_field)
for plugin in placeholder.get_plugins_list():
if plugin.changed_date \
> self.publishing_linked.publishing_modified_at:
return True

return False

@property
Expand Down Expand Up @@ -184,17 +183,18 @@ def get_field(self, field_name):
except models.fields.FieldDoesNotExist:
return None

def get_placeholder_fields(self, obj=None):
placeholder_fields = []

def get_cms_placeholder_fields(self, obj=None):
try:
from cms.models.placeholdermodel import Placeholder
return self.get_placeholder_fields(Placeholder, obj=obj)
except ImportError:
return placeholder_fields
return []

def get_placeholder_fields(self, placeholder_class, obj=None):
if obj is None:
obj = self

placeholder_fields = []
model_fields = obj.__class__._meta.get_all_field_names()
for field in model_fields:
if field in self.publishing_ignore_fields:
Expand All @@ -206,7 +206,6 @@ def get_placeholder_fields(self, obj=None):
placeholder_fields.append(field)
except (ObjectDoesNotExist, AttributeError):
continue

return placeholder_fields

@assert_draft
Expand Down Expand Up @@ -487,7 +486,8 @@ def clone(src_manager):

def has_placeholder_relationships(self):
return hasattr(self, 'placeholder_set') \
or hasattr(self, 'placeholders')
or hasattr(self, 'placeholders') \
or len(self.get_placeholder_fields(Placeholder)) > 0

@assert_draft
def patch_placeholders(self):
Expand Down

0 comments on commit 984e6cf

Please sign in to comment.