From b31046238760a50bc96864706bd5b4f65f644998 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20K=C3=B6gl?= Date: Thu, 26 Jun 2014 18:18:05 +0200 Subject: [PATCH] [Migration] remove unused methods for unifying slugs Slugs now must be unique, so there is no point in unifying them anymore. --- mygpo/administration/tasks.py | 103 ++++++--------------- mygpo/administration/templates/admin/overview.html | 1 - .../templates/admin/unify-slugs-select.html | 28 ------ mygpo/administration/urls.py | 17 +--- mygpo/administration/views.py | 51 +--------- mygpo/core/slugs.py | 38 -------- mygpo/core/tests.py | 28 ------ 7 files changed, 31 insertions(+), 235 deletions(-) rewrite mygpo/administration/tasks.py (71%) delete mode 100644 mygpo/administration/templates/admin/unify-slugs-select.html diff --git a/mygpo/administration/tasks.py b/mygpo/administration/tasks.py dissimilarity index 71% index f7487d66..708ba67b 100644 --- a/mygpo/administration/tasks.py +++ b/mygpo/administration/tasks.py @@ -1,75 +1,28 @@ -from collections import Counter - -from mygpo.podcasts.models import Podcast -from mygpo.cel import celery -from mygpo.core.slugs import get_duplicate_slugs, EpisodeSlug -from mygpo.maintenance.merge import PodcastMerger - -from celery.utils.log import get_task_logger -logger = get_task_logger(__name__) - - -@celery.task -def merge_podcasts(podcast_ids, num_groups): - """ Task to merge some podcasts""" - - logger.info('merging podcast ids %s', podcast_ids) - - podcasts = Podcast.objects.filter(id__in=podcast_ids) - - logger.info('merging podcasts %s', podcasts) - - actions = Counter() - - pm = PodcastMerger(podcasts, actions, num_groups) - podcast = pm.merge() - - logger.info('merging result: %s', actions) - - return actions, podcast - - -@celery.task -def unify_slugs(podcast): - """ Removes duplicate slugs of a podcast's episodes """ - - logger.warn('unifying slugs for podcast %s', podcast) - episodes = podcast.episode_set.all() - logger.info('found %d episodes', len(episodes)) - - common_title = podcast.get_common_episode_title() - actions = Counter() - - # get episodes with duplicate slugs - for slug, dups in get_duplicate_slugs(episodes): - actions['dup-slugs'] += 1 - # and remove their slugs - logger.info('Found %d duplicates for slug %s', len(dups), slug) - for dup in dups: - actions['dup-episodes'] += 1 - - # check if we're removing the "main" slug - if dup.slug == slug: - - # if possible, replace it with a "merged" slug - if dup.merged_slugs: - dup.slug = dup.merged_slugs.pop() - actions['replaced-with-merged'] += 1 - logger.info('Replacing slug with merged slug %s', dup.slug) - - # try to find a new slug - else: - dup.slug = EpisodeSlug(dup, common_title, - override_existing=True).get_slug() - actions['replaced-with-new'] += 1 - logger.info('Replacing slug with new slug %s', dup.slug) - - # if the problematic slug is a merged one, remove it - if slug in dup.merged_slugs: - actions['removed-merged'] += 1 - logger.info('Removing merged slug %s', slug) - dup.merged_slugs.remove(slug) - - dup.save() - - return actions, podcast +from collections import Counter + +from mygpo.podcasts.models import Podcast +from mygpo.cel import celery +from mygpo.maintenance.merge import PodcastMerger + +from celery.utils.log import get_task_logger +logger = get_task_logger(__name__) + + +@celery.task +def merge_podcasts(podcast_ids, num_groups): + """ Task to merge some podcasts""" + + logger.info('merging podcast ids %s', podcast_ids) + + podcasts = Podcast.objects.filter(id__in=podcast_ids) + + logger.info('merging podcasts %s', podcasts) + + actions = Counter() + + pm = PodcastMerger(podcasts, actions, num_groups) + podcast = pm.merge() + + logger.info('merging result: %s', actions) + + return actions, podcast diff --git a/mygpo/administration/templates/admin/overview.html b/mygpo/administration/templates/admin/overview.html index a6272055..1c542533 100644 --- a/mygpo/administration/templates/admin/overview.html +++ b/mygpo/administration/templates/admin/overview.html @@ -16,7 +16,6 @@