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

Implement feedback models and Client API #5

Merged
merged 9 commits into from
Mar 12, 2023
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
52 changes: 52 additions & 0 deletions b2b/account/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Account app admin configurations."""
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.utils.translation import gettext_lazy as _

from .models import User

admin.site.site_header = "B2B Feedback Admin Panel"
admin.site.index_title = "Administration"


@admin.register(User)
class UserAdmin(BaseUserAdmin):
"""Define admin model for custom User model with no username field."""

fieldsets = (
(None, {"fields": ("email", "password")}),
(_("Personal info"), {"fields": ("name",)}),
(
_("Permissions"),
{
"fields": (
"is_active",
"is_staff",
"is_superuser",
"groups",
"user_permissions",
),
},
),
(_("Important dates"), {"fields": ("last_login", "date_joined")}),
)
add_fieldsets = (
(
None,
{
"classes": ("wide",),
"fields": (
"email",
"password1",
"password2",
"is_active",
"is_staff",
"is_superuser",
),
},
),
)
list_display = ("email", "id", "is_staff", "is_superuser")
readonly_fields = ("last_login", "date_joined")
search_fields = ("email",)
ordering = ("email",)
20 changes: 0 additions & 20 deletions b2b/account/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
"""Common fixtures for the account app tests."""
import pytest
from django.contrib.auth import get_user_model

User = get_user_model()


@pytest.fixture
def user_payload():
"""Return sample user information as a payload."""
return {
"email": "user@example.com",
"password": "test_pass123",
"name": "Test User",
}


@pytest.fixture
def sample_user(user_payload):
"""Create and return a sample user."""
return User.objects.create_user(**user_payload)
1 change: 1 addition & 0 deletions b2b/b2b/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
# Local apps
"account.apps.AccountConfig",
"core.apps.CoreConfig",
"feedback.apps.FeedbackConfig",
# Third-party apps
"rest_framework",
"rest_framework.authtoken",
Expand Down
1 change: 1 addition & 0 deletions b2b/b2b/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
urlpatterns = [
path("admin/", admin.site.urls),
path("account/", include("account.urls")),
path("feedback/", include("feedback.urls")),
]
19 changes: 19 additions & 0 deletions b2b/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
"""Global project fixtures."""
import pytest
from django.contrib.auth import get_user_model
from rest_framework.test import APIClient

User = get_user_model()


@pytest.fixture
def api_client():
"""Return API client."""
return APIClient()


@pytest.fixture
def user_payload():
"""Return sample user information as a payload."""
return {
"email": "user@example.com",
"password": "test_pass123",
"name": "Test User",
}


@pytest.fixture
def sample_user(user_payload):
"""Create and return a sample user."""
return User.objects.create_user(**user_payload)
1 change: 1 addition & 0 deletions b2b/feedback/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""The feedback app."""
32 changes: 32 additions & 0 deletions b2b/feedback/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Account app admin configurations."""
from django.contrib import admin

from .models import Client


@admin.register(Client)
class ClientAdmin(admin.ModelAdmin):
"""Define admin configuration for the Client model."""

autocomplete_fields = [
"client_rep",
"sales_manager",
]
list_display = [
"email",
"name",
"client_rep",
"sales_manager",
"id",
]
list_editable = [
"name",
]
list_select_related = [
"client_rep",
"sales_manager",
]
search_fields = [
"email__icontains",
"name__icontains",
]
9 changes: 9 additions & 0 deletions b2b/feedback/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""The feedback app configuration."""
from django.apps import AppConfig


class FeedbackConfig(AppConfig):
"""The feedback app configuration class."""

default_auto_field = "django.db.models.BigAutoField"
name = "feedback"
Loading