<filename>backend/api/demo.py
from django.core import management
from django.contrib.auth.models import User
from api.models import Course, Post, Tag
from api.services import UserService


def setup():
    """
    Function that creates and saves elements to the database for demo purposes.
    Function assumes that the database starts out empty.
    For LOCAL DEV ONLY.
    """
    passwords = []

    # create example users
    passwords.append(UserService.generate_password())
    user1 = User.objects.create_user(
        "<EMAIL>",
        password=passwords[0],
        email="<EMAIL>",
        first_name="Josiah",
        last_name="Carberry",
    )
    user1.save()

    passwords.append(UserService.generate_password())
    user2 = User.objects.create_user(
        "<EMAIL>",
        password=passwords[1],
        email="<EMAIL>",
        first_name="Blueno",
    )
    user2.save()

    passwords.append(UserService.generate_password())
    user3 = User.objects.create_user(
        "<EMAIL>",
        password=passwords[2],
        email="<EMAIL>",
        first_name="Random",
        last_name="Person",
    )
    user3.save()

    # create course
    course1 = Course(name="Course 1")
    course1.save()
    course1.instructors.add(user1)
    course1.students.add(user2)
    course1.students.add(user3)
    course1.save()

    # create posts
    post1 = Post(
        author=user1,
        course=course1,
        title="I have a question",
        content="idk what im doing",
        anonymous=True,
        type=Post.Type.QUESTION,
        visibility=Post.Visibility.PUBLIC,
    )
    post1.save()

    post2 = Post(
        author=user1,
        course=course1,
        title="I also have a question",
        content="i really dont know what im doing",
        anonymous=False,
        type=Post.Type.NOTE,
        visibility=Post.Visibility.PRIVATE,
    )
    post2.save()

    post3 = Post(
        author=user3,
        course=course1,
        title="My code is broken",
        content="Hi you can see my name, Student answers welcomed!!",
        anonymous=False,
        type=Post.Type.NOTE,
        visibility=Post.Visibility.PUBLIC,
    )
    post3.save()

    post4 = Post(
        author=user2,
        course=course1,
        title="Could a TA help",
        content="Only TAs should be able to see this",
        anonymous=False,
        type=Post.Type.NOTE,
        visibility=Post.Visibility.PRIVATE,
    )
    post4.save()

    post5 = Post(
        author=user1,
        course=course1,
        title="TA Note about posting",
        content="Hours Changed from 11 to 2",
        anonymous=True,
        type=Post.Type.NOTE,
        visibility=Post.Visibility.PUBLIC,
    )
    post5.save()

    post6 = Post(
        author=user1,
        course=course1,
        title="Question to Students",
        content="TA asking for student replies ",
        anonymous=True,
        type=Post.Type.QUESTION,
        visibility=Post.Visibility.PUBLIC,
    )
    post6.save()
    # create tags
    tag1 = Tag(name="Tag 1", course=course1)
    tag1.save()
    tag2 = Tag(name="Tag 2", course=course1)
    tag2.save()

    post1.tags.add(tag1, tag2)
    post2.tags.add(tag2)
    post4.tags.add(tag1)
    post6.tags.add(tag1, tag2)

    print("setup successful!")
    print("user passwords in order: " + str(passwords))

<filename>backend/api/demo.py
from django.core import management
from django.contrib.auth.models import User
from api.models import Course, Post, Tag
from api.services import UserService


def setup():
    """
    Function that creates and saves elements to the database for demo purposes.
    Function assumes that the database starts out empty.
    For LOCAL DEV ONLY.
    """
    passwords = []

    # create example users
    passwords.append(UserService.generate_password())
    user1 = User.objects.create_user(
        "<EMAIL>",
        password=passwords[0],
        email="<EMAIL>",
        first_name="Josiah",
        last_name="Carberry",
    )
    user1.save()

    passwords.append(UserService.generate_password())
    user2 = User.objects.create_user(
        "<EMAIL>",
        password=passwords[1],
        email="<EMAIL>",
        first_name="Blueno",
    )
    user2.save()

    passwords.append(UserService.generate_password())
    user3 = User.objects.create_user(
        "<EMAIL>",
        password=passwords[2],
        email="<EMAIL>",
        first_name="Random",
        last_name="Person",
    )
    user3.save()

    # create course
    course1 = Course(name="Course 1")
    course1.save()
    course1.instructors.add(user1)
    course1.students.add(user2)
    course1.students.add(user3)
    course1.save()

    # create posts
    post1 = Post(
        author=user1,
        course=course1,
        title="I have a question",
        content="idk what im doing",
        anonymous=True,
        type=Post.Type.QUESTION,
        visibility=Post.Visibility.PUBLIC,
    )
    post1.save()

    post2 = Post(
        author=user1,
        course=course1,
        title="I also have a question",
        content="i really dont know what im doing",
        anonymous=False,
        type=Post.Type.NOTE,
        visibility=Post.Visibility.PRIVATE,
    )
    post2.save()

    post3 = Post(
        author=user3,
        course=course1,
        title="My code is broken",
        content="Hi you can see my name, Student answers welcomed!!",
        anonymous=False,
        type=Post.Type.NOTE,
        visibility=Post.Visibility.PUBLIC,
    )
    post3.save()

    post4 = Post(
        author=user2,
        course=course1,
        title="Could a TA help",
        content="Only TAs should be able to see this",
        anonymous=False,
        type=Post.Type.NOTE,
        visibility=Post.Visibility.PRIVATE,
    )
    post4.save()

    post5 = Post(
        author=user1,
        course=course1,
        title="TA Note about posting",
        content="Hours Changed from 11 to 2",
        anonymous=True,
        type=Post.Type.NOTE,
        visibility=Post.Visibility.PUBLIC,
    )
    post5.save()

    post6 = Post(
        author=user1,
        course=course1,
        title="Question to Students",
        content="TA asking for student replies ",
        anonymous=True,
        type=Post.Type.QUESTION,
        visibility=Post.Visibility.PUBLIC,
    )
    post6.save()
    # create tags
    tag1 = Tag(name="Tag 1", course=course1)
    tag1.save()
    tag2 = Tag(name="Tag 2", course=course1)
    tag2.save()

    post1.tags.add(tag1, tag2)
    post2.tags.add(tag2)
    post4.tags.add(tag1)
    post6.tags.add(tag1, tag2)

    print("setup successful!")
    print("user passwords in order: " + str(passwords))

Function that creates and saves elements to the database for demo purposes.     Function assumes that the database starts out empty.     For LOCAL DEV ONLY. # create example users # create course # create posts # create tags