4cd52f4905825f0107a4aa1497fe422e9c5566da
1 from django
.core
.management
.base
import BaseCommand
2 from optparse
import make_option
3 from mygpo
.api
.models
import Podcast
, PodcastGroup
4 from mygpo
.data
.models
import DirectoryEntry
5 from mygpo
.data
.directory
import get_source_weights
, get_weighted_tags
, get_weighted_group_tags
7 class Command(BaseCommand
):
9 def handle(self
, *args
, **options
):
11 source_weights
= get_source_weights()
14 podcasts
= Podcast
.objects
.filter(url__in
=args
)
17 podcasts
= Podcast
.objects
.filter(group
=None).order_by('id').only('id')
19 for podcast
in podcasts
.iterator():
22 DirectoryEntry
.objects
.filter(podcast
=podcast
).delete()
24 for tag
, weight
in get_weighted_tags(podcast
, source_weights
).iteritems():
28 DirectoryEntry
.objects
.create(podcast
=podcast
, tag
=tag
, ranking
=weight
)
30 groups
= PodcastGroup
.objects
.all().order_by('id').only('id')
31 for group
in groups
.iterator():
34 DirectoryEntry
.objects
.filter(podcast_group
=group
).delete()
36 for tag
, weight
in get_weighted_group_tags(group
, source_weights
).iteritems():
40 DirectoryEntry
.objects
.create(podcast_group
=group
, tag
=tag
, ranking
=weight
)