diff --git a/authors/migrations/0002_authorsorderable.py b/authors/migrations/0002_authorsorderable.py index b6565d7..a78ac72 100644 --- a/authors/migrations/0002_authorsorderable.py +++ b/authors/migrations/0002_authorsorderable.py @@ -8,7 +8,7 @@ class Migration(migrations.Migration): dependencies = [ - ('exhibit', '0002_exhibitpage_cover_image'), + ('exhibits', '0002_exhibitpage_cover_image'), ('authors', '0001_initial'), ] @@ -19,7 +19,7 @@ class Migration(migrations.Migration): ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('sort_order', models.IntegerField(blank=True, editable=False, null=True)), ('author', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='authors.author')), - ('page', modelcluster.fields.ParentalKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='authors', to='exhibit.exhibitpage')), + ('page', modelcluster.fields.ParentalKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='authors', to='exhibits.exhibitpage')), ], options={ 'ordering': ['sort_order'], diff --git a/authors/models.py b/authors/models.py index 1a4eced..9f334c3 100644 --- a/authors/models.py +++ b/authors/models.py @@ -9,7 +9,7 @@ class AuthorsOrderable(Orderable): - page = ParentalKey('exhibit.ExhibitPage', related_name='authors', null=True) + page = ParentalKey('exhibits.ExhibitPage', related_name='authors', null=True) author = models.ForeignKey( 'authors.Author', blank=True, diff --git a/exhibit/__init__.py b/exhibits/__init__.py similarity index 100% rename from exhibit/__init__.py rename to exhibits/__init__.py diff --git a/exhibit/admin.py b/exhibits/admin.py similarity index 100% rename from exhibit/admin.py rename to exhibits/admin.py diff --git a/exhibit/api.py b/exhibits/api.py similarity index 100% rename from exhibit/api.py rename to exhibits/api.py diff --git a/exhibit/apps.py b/exhibits/apps.py similarity index 62% rename from exhibit/apps.py rename to exhibits/apps.py index 6caaf51..d096e6a 100644 --- a/exhibit/apps.py +++ b/exhibits/apps.py @@ -1,6 +1,6 @@ from django.apps import AppConfig -class ExhibitConfig(AppConfig): +class ExhibitsConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' - name = 'exhibit' + name = 'exhibits' diff --git a/exhibits/management/commands/rename.py b/exhibits/management/commands/rename.py new file mode 100644 index 0000000..3137648 --- /dev/null +++ b/exhibits/management/commands/rename.py @@ -0,0 +1,29 @@ +"""Rename module +Shamelessly copied from https://gist.github.com/rafaponieman/201054ddf725cda1e60be3fe845850a5 +""" +import argparse + +from django.core.management.base import BaseCommand +from django.db import connection + + +class Command(BaseCommand): + help = 'Renames app. Usage rename_app [old_name] [new_name] [classes ...]' + + def add_arguments(self, parser): + # Positional arguments + parser.add_argument('old_name', nargs=1, type=str) + parser.add_argument('new_name', nargs=1, type=str) + parser.add_argument('models', nargs=argparse.REMAINDER, type=str) + + def handle(self, old_name, new_name, models, *args, **options): + with connection.cursor() as cursor: + # Rename model + old_name = old_name[0] + new_name = new_name[0] + cursor.execute("UPDATE django_content_type SET app_label='{}' WHERE app_label='{}'".format(new_name, old_name)) + cursor.execute("UPDATE django_migrations SET app='{}' WHERE app='{}'".format(new_name, old_name)) + + for model in models: + cursor.execute("ALTER TABLE {old_name}_{model_name} RENAME TO {new_name}_{model_name}".format( + old_name=old_name, new_name=new_name, model_name=model)) diff --git a/exhibit/migrations/0001_initial.py b/exhibits/migrations/0001_initial.py similarity index 100% rename from exhibit/migrations/0001_initial.py rename to exhibits/migrations/0001_initial.py diff --git a/exhibit/migrations/0002_exhibitpage_cover_image.py b/exhibits/migrations/0002_exhibitpage_cover_image.py similarity index 93% rename from exhibit/migrations/0002_exhibitpage_cover_image.py rename to exhibits/migrations/0002_exhibitpage_cover_image.py index e8b5f21..661825f 100644 --- a/exhibit/migrations/0002_exhibitpage_cover_image.py +++ b/exhibits/migrations/0002_exhibitpage_cover_image.py @@ -8,7 +8,7 @@ class Migration(migrations.Migration): dependencies = [ ('wagtailimages', '0023_add_choose_permissions'), - ('exhibit', '0001_initial'), + ('exhibits', '0001_initial'), ] operations = [ diff --git a/exhibit/migrations/0003_exhibitpage_hero_image.py b/exhibits/migrations/0003_exhibitpage_hero_image.py similarity index 90% rename from exhibit/migrations/0003_exhibitpage_hero_image.py rename to exhibits/migrations/0003_exhibitpage_hero_image.py index 3781418..b6c8255 100644 --- a/exhibit/migrations/0003_exhibitpage_hero_image.py +++ b/exhibits/migrations/0003_exhibitpage_hero_image.py @@ -8,7 +8,7 @@ class Migration(migrations.Migration): dependencies = [ ('wagtailimages', '0023_add_choose_permissions'), - ('exhibit', '0002_exhibitpage_cover_image'), + ('exhibits', '0002_exhibitpage_cover_image'), ] operations = [ diff --git a/exhibit/migrations/0004_exhibitsorderable.py b/exhibits/migrations/0004_exhibitsorderable.py similarity index 83% rename from exhibit/migrations/0004_exhibitsorderable.py rename to exhibits/migrations/0004_exhibitsorderable.py index 07f5834..573b20c 100644 --- a/exhibit/migrations/0004_exhibitsorderable.py +++ b/exhibits/migrations/0004_exhibitsorderable.py @@ -8,7 +8,7 @@ class Migration(migrations.Migration): dependencies = [ - ('exhibit', '0003_exhibitpage_hero_image'), + ('exhibits', '0003_exhibitpage_hero_image'), ] operations = [ @@ -17,8 +17,8 @@ class Migration(migrations.Migration): fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('sort_order', models.IntegerField(blank=True, editable=False, null=True)), - ('exhibit', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='exhibit.exhibitpage')), - ('page', modelcluster.fields.ParentalKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='other_exhibits', to='exhibit.exhibitpage')), + ('exhibit', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='exhibits.exhibitpage')), + ('page', modelcluster.fields.ParentalKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='other_exhibits', to='exhibits.exhibitpage')), ], options={ 'ordering': ['sort_order'], diff --git a/exhibit/migrations/__init__.py b/exhibits/migrations/__init__.py similarity index 100% rename from exhibit/migrations/__init__.py rename to exhibits/migrations/__init__.py diff --git a/exhibit/models.py b/exhibits/models.py similarity index 96% rename from exhibit/models.py rename to exhibits/models.py index c5c7ffd..71b554a 100644 --- a/exhibit/models.py +++ b/exhibits/models.py @@ -12,9 +12,9 @@ class ExhibitsOrderable(Orderable): - page = ParentalKey('exhibit.ExhibitPage', related_name='other_exhibits', null=True) + page = ParentalKey('exhibits.ExhibitPage', related_name='other_exhibits', null=True) exhibit = models.ForeignKey( - 'exhibit.ExhibitPage', + 'exhibits.ExhibitPage', blank=True, null=True, on_delete=models.CASCADE, diff --git a/exhibit/templates/exhibit/exhibit_page.html b/exhibits/templates/exhibit/exhibit_page.html similarity index 100% rename from exhibit/templates/exhibit/exhibit_page.html rename to exhibits/templates/exhibit/exhibit_page.html diff --git a/exhibit/tests/__init__.py b/exhibits/tests/__init__.py similarity index 100% rename from exhibit/tests/__init__.py rename to exhibits/tests/__init__.py diff --git a/exhibit/tests/factories.py b/exhibits/tests/factories.py similarity index 88% rename from exhibit/tests/factories.py rename to exhibits/tests/factories.py index 60dd6b0..6225a57 100644 --- a/exhibit/tests/factories.py +++ b/exhibits/tests/factories.py @@ -1,6 +1,6 @@ from factory import SubFactory from wagtail_factories import ImageChooserBlockFactory, PageFactory -from exhibit.models import ExhibitPage +from exhibits.models import ExhibitPage class ExhibitPageFactory(PageFactory): diff --git a/exhibit/tests/test_exhibit_page.py b/exhibits/tests/test_exhibit_page.py similarity index 100% rename from exhibit/tests/test_exhibit_page.py rename to exhibits/tests/test_exhibit_page.py diff --git a/exhibit/views.py b/exhibits/views.py similarity index 100% rename from exhibit/views.py rename to exhibits/views.py diff --git a/ov_wag/api.py b/ov_wag/api.py index dcbf7d1..8c434e1 100644 --- a/ov_wag/api.py +++ b/ov_wag/api.py @@ -3,7 +3,7 @@ from wagtail.images.api.v2.views import ImagesAPIViewSet from wagtail.documents.api.v2.views import DocumentsAPIViewSet from authors.api import AuthorsAPIViewSet -from exhibit.api import ExhibitAPIViewSet +from exhibits.api import ExhibitAPIViewSet # Create the router. "wagtailapi" is the URL namespace api_router = WagtailAPIRouter('wagtailapi') @@ -16,4 +16,4 @@ api_router.register_endpoint('images', ImagesAPIViewSet) api_router.register_endpoint('documents', DocumentsAPIViewSet) api_router.register_endpoint('authors', AuthorsAPIViewSet) -api_router.register_endpoint('exhibit', ExhibitAPIViewSet) +api_router.register_endpoint('exhibits', ExhibitAPIViewSet) diff --git a/ov_wag/settings/base.py b/ov_wag/settings/base.py index c26cedc..65e44ce 100644 --- a/ov_wag/settings/base.py +++ b/ov_wag/settings/base.py @@ -26,7 +26,7 @@ INSTALLED_APPS = [ 'home', 'search', - 'exhibit', + 'exhibits', 'authors', 'wagtail.contrib.forms', 'wagtail.contrib.modeladmin', diff --git a/ov_wag/tests/test_api.py b/ov_wag/tests/test_api.py index e7d96f2..db9cad7 100644 --- a/ov_wag/tests/test_api.py +++ b/ov_wag/tests/test_api.py @@ -2,8 +2,8 @@ from rest_framework.test import APITestCase from wagtail.core.models import Site import wagtail_factories -from exhibit.models import ExhibitPageApiSchema -from exhibit.tests.factories import ExhibitPageFactory +from exhibits.models import ExhibitPageApiSchema +from exhibits.tests.factories import ExhibitPageFactory class ApiTests(APITestCase): @@ -41,7 +41,7 @@ def test_exhibit_api_schema_single(self): Compare response against ExhibitSchema """ exhibit_page = ExhibitPageFactory.create(parent=self.__home_page()) - response = self.client.get(f'/api/v2/exhibit/{exhibit_page.id}/', format='json') + response = self.client.get(f'/api/v2/exhibits/{exhibit_page.id}/', format='json') json = response.json() self.assertValidSchema(json) @@ -52,7 +52,7 @@ def test_exhibit_api_schema_multiple(self): Compare response against ExhibitSchema """ exhibit_page = ExhibitPageFactory.create(parent=self.__home_page()) - response = self.client.get(f'/api/v2/exhibit/', format='json') + response = self.client.get(f'/api/v2/exhibits/', format='json') json = response.json() for item in json['items']: self.assertValidSchema(item) diff --git a/pytest.ini b/pytest.ini index 53596b2..ea18e49 100644 --- a/pytest.ini +++ b/pytest.ini @@ -3,5 +3,5 @@ DJANGO_SETTINGS_MODULE = ov_wag.settings.dev python_files = tests.py test_*.py *_tests.py testpaths = authors - exhibit + exhibits ov_wag