-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented feature: Removes the tasks belonging to a deactivated par…
…ents
- Loading branch information
Andreu Vallbona
committed
Feb 23, 2018
1 parent
2f6b1df
commit e35e4ad
Showing
5 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
__author__ = 'Andreu Vallbona' | ||
__email__ = '[email protected]' | ||
__version__ = '0.3.3' | ||
__version__ = '0.3.4' | ||
|
||
default_app_config = 'transmanager.apps.TransManagerConfig' |
38 changes: 38 additions & 0 deletions
38
transmanager/management/commands/remove_tasks_for_disabled_parents.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- encoding: utf-8 -*- | ||
|
||
from django.core.management.base import BaseCommand | ||
from transmanager.models import TransModelLanguage | ||
from transmanager.settings import TM_DEFAULT_ENABLED_ATTRIBUTE_NAME | ||
from transmanager.tasks.tasks import delete_translations_for_item_and_its_children | ||
from transmanager.utils import has_field | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Removes the tasks belonging to a deactivated parents." | ||
|
||
def handle(self, *args, **options): | ||
|
||
filter_by = { | ||
TM_DEFAULT_ENABLED_ATTRIBUTE_NAME: False | ||
} | ||
|
||
whole_ids = [] | ||
|
||
self.stdout.write('Start') | ||
# generate the translations tasks for every record on the translatable models | ||
for model in TransModelLanguage.objects.all(): | ||
mc = model.get_model_class() | ||
if not has_field(mc, TM_DEFAULT_ENABLED_ATTRIBUTE_NAME): | ||
continue | ||
|
||
# if the model has the enabled attr, the we search the disabled items ids | ||
disabled_ids = list(mc.objects.filter(**filter_by).values_list('id', flat=True)) | ||
whole_ids += disabled_ids | ||
self.stdout.write('Model: {} has {} ids'.format(mc.__name__, len(disabled_ids))) | ||
if disabled_ids: | ||
for item_id in disabled_ids: | ||
delete_translations_for_item_and_its_children.delay(mc, item_id) | ||
|
||
self.stdout.write('{} ids will be processed'.format(len(whole_ids))) | ||
|
||
self.stdout.write('End') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters