diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | config/settings/base.py | 1 | ||||
-rw-r--r-- | config/urls.py | 1 | ||||
-rw-r--r-- | ctrack/conftest.py | 8 | ||||
-rw-r--r-- | ctrack/organisations/__init__.py | 0 | ||||
-rw-r--r-- | ctrack/organisations/admin.py | 6 | ||||
-rw-r--r-- | ctrack/organisations/apps.py | 5 | ||||
-rw-r--r-- | ctrack/organisations/migrations/0001_initial.py | 21 | ||||
-rw-r--r-- | ctrack/organisations/migrations/__init__.py | 0 | ||||
-rw-r--r-- | ctrack/organisations/models.py | 15 | ||||
-rw-r--r-- | ctrack/organisations/tests/__init__.py | 0 | ||||
-rw-r--r-- | ctrack/organisations/tests/test_models.py | 11 | ||||
-rw-r--r-- | ctrack/organisations/urls.py | 9 | ||||
-rw-r--r-- | ctrack/organisations/views.py | 2 | ||||
-rw-r--r-- | ctrack/users/tests/factories.py | 9 |
15 files changed, 88 insertions, 1 deletions
@@ -284,3 +284,4 @@ ctrack/media/ .pytest_cache/ +.idea/ diff --git a/config/settings/base.py b/config/settings/base.py index 15a3be8..fa52962 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -76,6 +76,7 @@ THIRD_PARTY_APPS = [ LOCAL_APPS = [ "ctrack.users.apps.UsersConfig", + "ctrack.organisations.apps.OrganisationsConfig", # Your stuff: custom apps go here ] # https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps diff --git a/config/urls.py b/config/urls.py index 2e9f883..9fd5bbb 100644 --- a/config/urls.py +++ b/config/urls.py @@ -14,6 +14,7 @@ urlpatterns = [ path(settings.ADMIN_URL, admin.site.urls), # User management path("users/", include("ctrack.users.urls", namespace="users")), + path("organisations/", include("ctrack.organisations.urls", namespace="organisations")), path("accounts/", include("allauth.urls")), # Your stuff: custom urls includes go here ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/ctrack/conftest.py b/ctrack/conftest.py index b994f24..36254cd 100644 --- a/ctrack/conftest.py +++ b/ctrack/conftest.py @@ -2,7 +2,8 @@ import pytest from django.test import RequestFactory from ctrack.users.models import User -from ctrack.users.tests.factories import UserFactory +from ctrack.organisations.models import Organisation +from ctrack.users.tests.factories import UserFactory, OrganisationFactory @pytest.fixture(autouse=True) @@ -16,5 +17,10 @@ def user() -> User: @pytest.fixture +def org() -> Organisation: + return OrganisationFactory() + + +@pytest.fixture def request_factory() -> RequestFactory: return RequestFactory() diff --git a/ctrack/organisations/__init__.py b/ctrack/organisations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ctrack/organisations/__init__.py diff --git a/ctrack/organisations/admin.py b/ctrack/organisations/admin.py new file mode 100644 index 0000000..8890f15 --- /dev/null +++ b/ctrack/organisations/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin + +from .models import Organisation + +# Register your models here. +admin.site.register(Organisation) diff --git a/ctrack/organisations/apps.py b/ctrack/organisations/apps.py new file mode 100644 index 0000000..72eb1d9 --- /dev/null +++ b/ctrack/organisations/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class OrganisationsConfig(AppConfig): + name = 'ctrack.organisations' diff --git a/ctrack/organisations/migrations/0001_initial.py b/ctrack/organisations/migrations/0001_initial.py new file mode 100644 index 0000000..6171bb8 --- /dev/null +++ b/ctrack/organisations/migrations/0001_initial.py @@ -0,0 +1,21 @@ +# Generated by Django 2.2.9 on 2020-01-20 16:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Organisation', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ], + ), + ] diff --git a/ctrack/organisations/migrations/__init__.py b/ctrack/organisations/migrations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ctrack/organisations/migrations/__init__.py diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py new file mode 100644 index 0000000..976e661 --- /dev/null +++ b/ctrack/organisations/models.py @@ -0,0 +1,15 @@ +from django.db import models + +# Create your models here. +from django.urls import reverse +from slugify import slugify + + +class Organisation(models.Model): + name = models.CharField(max_length=255, blank=False) + + def get_absolute_url(self): + return reverse("organisations:detail", kwargs={"name": self.slugify_name()}) + + def slugify_name(self): + return slugify(self.name) diff --git a/ctrack/organisations/tests/__init__.py b/ctrack/organisations/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ctrack/organisations/tests/__init__.py diff --git a/ctrack/organisations/tests/test_models.py b/ctrack/organisations/tests/test_models.py new file mode 100644 index 0000000..1307a83 --- /dev/null +++ b/ctrack/organisations/tests/test_models.py @@ -0,0 +1,11 @@ +import pytest +from slugify import slugify + +from ..models import Organisation + +pytestmark = pytest.mark.django_db + + +def test_organisation_get_absolute_url(org: Organisation): + slug = slugify(org.name) + assert org.get_absolute_url() == f"/organisations/{slug}/" diff --git a/ctrack/organisations/urls.py b/ctrack/organisations/urls.py new file mode 100644 index 0000000..a3b1b9f --- /dev/null +++ b/ctrack/organisations/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from ctrack.organisations.views import organisations_detail_view + +app_name = "organisations" + +urlpatterns = [ + path("<str:name>/", view=organisations_detail_view, name="detail") +] diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py new file mode 100644 index 0000000..30d00be --- /dev/null +++ b/ctrack/organisations/views.py @@ -0,0 +1,2 @@ +def organisations_detail_view(request): + pass diff --git a/ctrack/users/tests/factories.py b/ctrack/users/tests/factories.py index b537136..d4b9544 100644 --- a/ctrack/users/tests/factories.py +++ b/ctrack/users/tests/factories.py @@ -1,9 +1,18 @@ from typing import Any, Sequence from django.contrib.auth import get_user_model +from ctrack.organisations.models import Organisation from factory import DjangoModelFactory, Faker, post_generation +class OrganisationFactory(DjangoModelFactory): + + name = Faker("name") + + class Meta: + model = Organisation + + class UserFactory(DjangoModelFactory): username = Faker("user_name") |