(request)
return data
Given a file of tags, return the post count for each.
Given a file of tags, return the post count for each.
Given a file of tags return the post count for each .
def tags_list(request):
    """
    Given a file of tags, return the post count for each.
    """
    # Get a file with all the tags.
    tags = request.FILES.get('tags')

    # How many months prior to look back
    months = request.POST.get('months', '6')

    try:
        months = int(months) if months.isalnum() else float(months)
    except Exception as exc:
        logger.error(exc)
        months = 6

    # Convert months to weeks
    weeks = months * 4

    delta = util.now() - timedelta(weeks=weeks)
    query = Post.objects.filter(lastedit_date__gt=delta)

    # Iterate over tags and collect counts.
    lines = tags.readlines() if tags else []

    data = {}

    for line in lines:
        tag = line.decode().lower().strip()
        if not tag:
            continue

        # Get posts with this tag, that have been answered
        posts = query.filter(tags__name=tag.lower(), is_toplevel=True)
        uids = posts.values_list('uid', flat=True)

        # Filter so the count is only 1 answer per questions
        answer_count = Post.objects.filter(uid__in=uids, answer_count__gte=1).count()
        comment_count = Post.objects.filter(uid__in=uids, comment_count__gte=1).count()
        total = len(uids)

        val = dict(total=total, answer_count=answer_count, comment_count=comment_count)
        data.setdefault(tag, {}).update(val)

    return data
def tags_list ( request ) : # Get a file with all the tags. tags = request . FILES . get ( 'tags' ) # How many months prior to look back months = request . POST . get ( 'months' , '6' ) try : months = int ( months ) if months . isalnum ( ) else float ( months ) except Exception as exc : logger . error ( exc ) months = 6 # Convert months to weeks weeks = months * 4 delta = util . now ( ) - timedelta ( weeks = weeks ) query = Post . objects . filter ( lastedit_date__gt = delta ) # Iterate over tags and collect counts. lines = tags . readlines ( ) if tags else [ ] data = { } for line in lines : tag = line . decode ( ) . lower ( ) . strip ( ) if not tag : continue # Get posts with this tag, that have been answered posts = query . filter ( tags__name = tag . lower ( ) , is_toplevel = True ) uids = posts . values_list ( 'uid' , flat = True ) # Filter so the count is only 1 answer per questions answer_count = Post . objects . filter ( uid__in = uids , answer_count__gte = 1 ) . count ( ) comment_count = Post . objects . filter ( uid__in = uids , comment_count__gte = 1 ) . count ( ) total = len ( uids ) val = dict ( total = total , answer_count = answer_count , comment_count = comment_count ) data . setdefault ( tag , { } ) . update ( val ) return data