Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery Starbot ⭐ refactored ilyeshammadi/django-publishable #6

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions publishable/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ def select(instance):


def select_from_queryset(queryset):
if not DraftController.is_draft:
return queryset.filter(type=TYPES.PUBLISHED)
return queryset.filter(type=TYPES.DRAFT, is_deleted=False)
return (
queryset.filter(type=TYPES.DRAFT, is_deleted=False)
if DraftController.is_draft
else queryset.filter(type=TYPES.PUBLISHED)
)
Comment on lines -13 to +17
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function select_from_queryset refactored with the following changes:



class PublishableManager(models.Manager):
Expand Down
21 changes: 8 additions & 13 deletions publishable/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,7 @@ def publish(self):
# Create a copy of the wanted to publish instance
published = clone_model(self)

# Delete the previous published to save space
previous_published_id = None
if self.published:
previous_published_id = self.published.id

previous_published_id = self.published.id if self.published else None
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Publishable.publish refactored with the following changes:

This removes the following comments ( why? ):

# Delete the previous published to save space

self.published = published
self.save(broadcast_draft=False)

Expand All @@ -119,9 +115,8 @@ def delete(self, using=None, keep_parents=False, fake=True):
if self.type == TYPES.DRAFT:
if not fake:
return super(Publishable, self).delete(using, keep_parents)
else:
self.is_deleted = True
self.save()
self.is_deleted = True
self.save()
Comment on lines -122 to +119
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Publishable.delete refactored with the following changes:


def save(self, force_insert=False, force_update=False, using=None, update_fields=None, broadcast_draft=True):
super(Publishable, self).save(force_insert, force_update, using, update_fields)
Expand All @@ -135,8 +130,8 @@ def broadcast_need_to_published(self):
specific publisher
:return: Draft
"""
if Draft.objects.filter(object_id=self.id).exists():
draft = Draft.objects.get(object_id=self.id)
else:
draft = Draft.objects.create(content_object=self)
return draft
return (
Draft.objects.get(object_id=self.id)
if Draft.objects.filter(object_id=self.id).exists()
else Draft.objects.create(content_object=self)
)
Comment on lines -138 to +137
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Publishable.broadcast_need_to_published refactored with the following changes: