Example #1
0
def create_group(group_name, articles, num_comments, clone_and_sample):
    """
    Create group from articles (sampling its comments)
    """
    try:
        group = Group.objects.get(name=group_name)
    except DoesNotExist:
        group = Group(name=group_name)

    if clone_and_sample:
        group.articles = [
            clone_and_sample_comments(art, num_comments) for art in articles
        ]
    else:
        group.articles = articles

    group.save()

    return group