Example #1
0
    def handle(self, *args, **options):

        if len(args) < 2:
            print """
Merges multiple categories into one by listing them as alternative spellings

Usage:
  ./manage.py category-merge-spellings <category> <spelling1> [<spelling2> ...]
"""
            return

        start_time = datetime.utcnow()
        cat_name = args[0]
        spellings = args[1:]

        print "Adding new spellings for %s ..." % cat_name
        category = category_for_tag(cat_name)

        if not category:
            print " creating new category %s" % cat_name
            category = Category()
            category.label = cat_name

        for spelling in spellings:
            new_cat = category_for_tag(spelling)

            if spelling == cat_name or (spelling in category.spellings):
                print " skipped %s: already in category" % spelling
                continue

            if not new_cat:
                #merged category doesn't yet exist
                category.spellings.append(spelling)

            elif new_cat and category._id == new_cat._id:
                print " set %s as new label" % cat_name
                category.spellings = list(set([x for x in category.spellings + [category.label] if x != cat_name]))
                category.label = cat_name

            else:
                print " add spelling %s" % spelling
                category.spellings = list(set(category.spellings + [new_cat.label] + new_cat.spellings))
                category.merge_podcasts(new_cat.podcasts)
                new_cat.delete()

            category.updated = start_time

            save_category(category)
Example #2
0
    def add_podcast_state(self, p_state, docs):
        docs.add(p_state._id)

        # Categories
        for tag in p_state.tags:
            c = category_for_tag(tag)
            if c:
                docs.add(c._id)
Example #3
0
def tag_podcasts(request, tag, count):
    count = parse_range(count, 1, 100, 100)
    category = category_for_tag(tag)
    if not category:
        return JsonResponse([])

    domain = RequestSite(request).domain
    query = category.get_podcasts(0, count)
    resp = map(lambda p: podcast_data(p, domain), query)
    return JsonResponse(resp)
Example #4
0
    def add_podcast(self, podcast, docs):
        docs.add(podcast._id)

        # if podcast is actually a PodcastGroup, we get the first podcast
        podcast=podcast.get_podcast()

        # Categories
        for s in podcast.tags:
            for tag in podcast.tags[s]:
                c = category_for_tag(tag)
                if c:
                    docs.add(c._id)
Example #5
0
File: views.py Project: fk-lx/mygpo
def category(request, category, page_size=20):
    category = category_for_tag(category)
    if not category:
        return HttpResponseNotFound()

    # Make sure page request is an int. If not, deliver first page.
    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1

    entries = category.get_podcasts( (page-1) * page_size, page*page_size )
    podcasts = filter(None, entries)
    num_pages = int(ceil(len(category.podcasts) / page_size))

    page_list = get_page_list(1, num_pages, page, 15)

    return render(request, 'category.html', {
        'entries': podcasts,
        'category': category.label,
        'page_list': page_list,
        })