diff --git a/README.md b/README.md index 8639ec9d..a23922bd 100644 --- a/README.md +++ b/README.md @@ -17,13 +17,13 @@ To set up a development version on your local machine, you need to execute the f 1. Set up a virtualenv for the project with Python >=3.11 and activate it (e.g., `python3 -m venv venv` and `source venv/bin/activate`) 1. Install poetry (if not already installed): `curl -sSL https://install.python-poetry.org/ | python -` 1. Install dependencies with `poetry install` -1. Install bootstrap with `python tools/install_bootstrap.py` 1. Create env file by copying the `.env.example` file to `.env`, e.g. `cp .env.example .env` (Notice that for some functionality like OIDC some settings must be changed) 1. Migrate the database with `python manage.py migrate` -1. Compile translations with `python manage.py compilemessages` (does not work on Windows, recommended to skip this step or see [docs](https://docs.djangoproject.com/en/4.0/topics/i18n/translation/#gettext-on-windows)) +1. Install bootstrap with `python tools/install_bootstrap.py` +1. Optionally: Compile translations with `python manage.py compilemessages` (does not work on Windows, recommended to skip this step or see [docs](https://docs.djangoproject.com/en/4.0/topics/i18n/translation/#gettext-on-windows)) +1. Optionally: Create test data with `python manage.py create_test_data` 1. Create a local superuser with `python manage.py createsuperuser` 1. Start the development server with `python manage.py runserver` -1. Optionally: Create test data with `python tools/create_test_data.py` 1. Open your web browser, visit `http://localhost:8000/admin` and log in with the user you just created ### Tests diff --git a/tools/create_test_data.py b/myhpi/core/management/commands/create_test_data.py similarity index 92% rename from tools/create_test_data.py rename to myhpi/core/management/commands/create_test_data.py index 4e5286fc..e9bef6bf 100644 --- a/tools/create_test_data.py +++ b/myhpi/core/management/commands/create_test_data.py @@ -1,24 +1,11 @@ -import os -from datetime import date - -import django - -from myhpi.polls.models import PollList, RankedChoiceOption, RankedChoicePoll - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myhpi.settings") -django.setup() import random +from datetime import date -from django.contrib.auth.models import Group, Permission, User -from django.core.files import File -from django.db import IntegrityError -from wagtail.contrib.redirects.models import Redirect -from wagtail.documents.models import Document -from wagtail.models import Collection, GroupCollectionPermission +from django.contrib.auth.models import Group, User +from django.core.management import BaseCommand from myhpi.core.models import ( AbbreviationExplanation, - BasePage, FirstLevelMenuItem, InformationPage, Minutes, @@ -27,6 +14,7 @@ RootPage, SecondLevelMenuItem, ) +from myhpi.polls.models import PollList, RankedChoiceOption, RankedChoicePoll from myhpi.tests.core.setup import create_collections, create_documents @@ -354,14 +342,18 @@ def create_some_pages(users, groups, documents): slash_1999_poll.options.add(option_charlie) -def main(): - # Superuser is created manually via createsuperuser command - users, groups = create_users_and_groups() - collections = list(create_collections(groups)) - documents = create_documents([collections[1], collections[2]]) - create_abbreviation_explanations() - create_some_pages(users, groups, documents) - +class Command(BaseCommand): + help = "Creates test data (user, pages, etc.) for myHPI." -if __name__ == "__main__": - main() + def handle(self, *args, **options): + # Superuser is created manually via createsuperuser command + users, groups = create_users_and_groups() + collections = list(create_collections(groups)) + documents = create_documents([collections[1], collections[2]]) + create_abbreviation_explanations() + create_some_pages(users, groups, documents) + self.stdout.write( + self.style.SUCCESS( + 'Test data created succesfully. Remember that you need to create a superuser manually with "python manage.py createsuperuser".' + ) + )