Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use django management commands for tools #526

Merged
merged 4 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -27,6 +14,7 @@
RootPage,
SecondLevelMenuItem,
)
from myhpi.polls.models import PollList, RankedChoiceOption, RankedChoicePoll
from myhpi.tests.core.setup import create_collections, create_documents


Expand Down Expand Up @@ -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()
jeriox marked this conversation as resolved.
Show resolved Hide resolved
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".'
)
)
Loading