Exemplo n.º 1
0
def test_setup(**kwargs):
    from random import choice
    from django.contrib.auth.models import User
    from snapboard.models import Thread, Post, Category, UserProfile
    from snapboard import sampledata

    if not settings.DEBUG:
        return 

    if Thread.objects.all().count() > 0:
        # return, since there seem to already be threads in the database.
        return
    
    # ask for permission to create the test
    msg = """
    You've installed SNAPboard with DEBUG=True, do you want to populate
    the board with random users/threads/posts to test-drive the application?
    (yes/no):
    """
    populate = raw_input(msg).strip()
    while not (populate == "yes" or populate == "no"):
        populate = raw_input("\nPlease type 'yes' or 'no': ").strip()
    if populate == "no":
        return

    # create 10 random users

    users = ('john', 'sally', 'susan', 'amanda', 'bob', 'tully', 'fran')
    for u in users:
        user = User.objects.get_or_create(username=u)
        profile = UserProfile.objects.get_or_create(user=user[0], website='abc.com')
        # user.is_staff = True

    cats = ('Random Topics',
            'Good Deals',
            'Skiing in the Vermont Area',
            'The Best Restaurants')
    for c in cats:
        cat = Category.objects.get_or_create(label=c)

    # create up to 30 posts
    tc = range(1, 50)
    for i in range(0, 35):
        print 'thread ', i, 'created'
        cat= choice(Category.objects.all())
        subj = choice(sampledata.objects.split('\n'))
        thread = Thread(subject=subj, category=cat)
        thread.save()

        for j in range(0, choice(tc)):
            text = '\n\n'.join([sampledata.sample_data() for x in range(0, choice(range(2, 5)))])
            # create a post
            post = Post(
                    user=choice(User.objects.all()),
                    thread=thread,
                    text=text,
                    ip='.'.join([str(choice(range(1,255))) for x in (1,2,3,4)]),
                    )
            # allows setting of arbitrary ip
            post.management_save()
Exemplo n.º 2
0
def test_setup(**kwargs):
    from random import choice
    from django.contrib.auth.models import User
    from snapboard.models import Thread, Post, Category
    from snapboard import sampledata

    if not settings.DEBUG:
        return 

    if Thread.objects.all().count() > 0:
        # return, since there seem to already be threads in the database.
        return
    
    # ask for permission to create the test
    msg = """
    You've installed SNAPboard with DEBUG=True, do you want to populate
    the board with random users/threads/posts to test-drive the application?
    (yes/no):
    """
    populate = raw_input(msg).strip()
    while not (populate == "yes" or populate == "no"):
        populate = raw_input("\nPlease type 'yes' or 'no': ").strip()
    if populate == "no":
        return

    # create 10 random users

    users = ('john', 'sally', 'susan', 'amanda', 'bob', 'tully', 'fran')
    for u in users:
        user = User.objects.get_or_create(username=u)
        # user.is_staff = True

    cats = ('Random Topics',
            'Good Deals',
            'Skiing in the Vermont Area',
            'The Best Restaurants')
    for c in cats:
        cat = Category.objects.get_or_create(label=c)

    # create up to 30 posts
    tc = range(1, 50)
    for i in range(0, 35):
        print 'thread ', i, 'created'
        cat= choice(Category.objects.all())
        subj = choice(sampledata.objects.split('\n'))
        thread = Thread(subject=subj, category=cat)
        thread.save()

        for j in range(0, choice(tc)):
            text = '\n\n'.join([sampledata.sample_data() for x in range(0, choice(range(2, 5)))])
            # create a post
            post = Post(
                    user=choice(User.objects.all()),
                    thread=thread,
                    text=text,
                    ip='.'.join([str(choice(range(1,255))) for x in (1,2,3,4)]),
                    )
            # allows setting of arbitrary ip
            post.management_save()
Exemplo n.º 3
0
def make_random_thread(nposts=100, cat=None, ratio=0.5, **kwargs):
    cat = Category.objects.get(pk=cat) if cat \
      else choice(Category.objects.all())
    subj = choice(sampledata.objects.split('\n'))
    thread = Thread(subject=subj, category=cat)
    thread.save()
    # Amount of posts in the whole tread tree
    npostsr = randrange(nposts // 2, nposts)
    make_random_post_tree(None, npostsr, thread, ratio=ratio)
Exemplo n.º 4
0
def _gen_threads_def():
    thtypes = (
      ("[wide]", 0.1),
      ("[e]", 0.5),
      ("[deep]", 0.98),
    )
    for i in xrange(3):
        cat = choice(Category.objects.all())
        subj = choice(sampledata.objects.split('\n')) + \
          " " + thtypes[i][0]
        thread = Thread(subject=subj, category=cat)
        thread.save()
        print 'thread ', i, 'created'
        make_random_post_tree(None, randrange(50, 100), thread,
          ratio=thtypes[i][1])
        print 'thread ', i, 'filled'
Exemplo n.º 5
0
def _make_testtrees(maxdepth=512, **kwargs):
    user = User.objects.all()[0]
    thr = Thread(subject="Test trees.", category=Category.objects.all()[0])
    thr.save()
    top_post = Post.add_root(user=user, thread=thr, text="subj.")
    try:
        post = top_post
        print "lin"
        for curn in xrange(2, maxdepth):
            post = post.add_child(text="#1 at %d (lin)" % curn, user=post.user, thread=post.thread)
            print curn
    except Exception:
        traceback.print_exc()

    try:
        post = top_post
        print "dbl"
        for curn in xrange(2, maxdepth):
            post1 = post.add_child(text="#1 at %d (dbl)" % curn, user=post.user, thread=post.thread)
            post2 = post.add_child(text="#2 at %d (dbl)" % curn, user=post.user, thread=post.thread)
            post = post1
            print curn
    except Exception:
        traceback.print_exc()

    try:
        post = top_post
        print "rnd"
        for curn in xrange(2, maxdepth):
            post1 = post.add_child(text="#1 at %d (rnd)" % curn, user=post.user, thread=post.thread)
            post2 = post.add_child(text="#2 at %d (rnd)" % curn, user=post.user, thread=post.thread)
            post1.save()
            post2.save()
            post = post1 if random.choice([True, False]) else post2
            print curn
    except Exception:
        traceback.print_exc()