Skip to content

Commit

Permalink
Merge branch 'dev' into dependabot/pip/dev/black-24.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNyl authored Nov 13, 2024
2 parents b66bcc0 + c8669eb commit aabefff
Show file tree
Hide file tree
Showing 17 changed files with 365 additions and 78 deletions.
3 changes: 3 additions & 0 deletions app/content/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
register_with_feide,
send_email,
)
from app.files.views.upload import delete, upload

router = routers.DefaultRouter()

Expand Down Expand Up @@ -51,6 +52,8 @@
urlpatterns = [
re_path(r"", include(router.urls)),
path("accept-form/", accept_form),
path("upload/", upload),
path("delete-file/<str:container_name>/<str:blob_name>/", delete),
path("send-email/", send_email),
path("feide/", register_with_feide),
re_path(r"users/(?P<user_id>[^/.]+)/events.ics", UserCalendarEvents()),
Expand Down
4 changes: 4 additions & 0 deletions app/feedback/factories/bug_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ class Meta:

title = factory.Sequence(lambda n: f"Bug{n}")
author = factory.SubFactory(UserFactory)
description = factory.Faker("text")
url = factory.Faker("url")
platform = factory.Faker("word")
browser = factory.Faker("word")
1 change: 1 addition & 0 deletions app/feedback/factories/idea_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ class Meta:

title = factory.Sequence(lambda n: f"Idea{n}")
author = factory.SubFactory(UserFactory)
description = factory.Faker("text")
46 changes: 46 additions & 0 deletions app/feedback/filters/feedback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from django.db.models import Q
from django_filters import rest_framework as filters
from django_filters.rest_framework import OrderingFilter

from app.feedback.models import Feedback
from app.feedback.models.bug import Bug
from app.feedback.models.idea import Idea


class FeedbackFilter(filters.FilterSet):
feedback_type = filters.CharFilter(
method="filter_feedback_type", label="List of feedback type"
)

status = filters.CharFilter(
method="filter_status",
label="List of feedback status",
)

ordering = OrderingFilter(
fields=(
"created_at",
"updated_at",
)
)

def filter_feedback_type(self, queryset, _name, feedback_type):
if feedback_type == "Idea":
return queryset.filter(Q(instance_of=Idea))
elif feedback_type == "Bug":
return queryset.filter(Q(instance_of=Bug))
else:
return queryset

def filter_status(self, queryset, _name, value):
return queryset.filter(status=value)

class Meta:
model = Feedback
fields = [
"title",
"author",
"status",
"created_at",
"updated_at",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 4.2.5 on 2024-10-21 18:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("feedback", "0001_initial"),
]

operations = [
migrations.AlterModelOptions(
name="feedback",
options={"ordering": ("-created_at",)},
),
migrations.AddField(
model_name="bug",
name="Browser",
field=models.CharField(default="", max_length=200),
),
migrations.AddField(
model_name="bug",
name="Platform",
field=models.CharField(default="", max_length=200),
),
migrations.AddField(
model_name="bug",
name="Url",
field=models.URLField(blank=True, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2.5 on 2024-10-21 22:18

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("feedback", "0002_alter_feedback_options_bug_browser_bug_platform_and_more"),
]

operations = [
migrations.RenameField(
model_name="bug",
old_name="Browser",
new_name="browser",
),
migrations.RenameField(
model_name="bug",
old_name="Platform",
new_name="platform",
),
migrations.RenameField(
model_name="bug",
old_name="Url",
new_name="url",
),
]
6 changes: 5 additions & 1 deletion app/feedback/models/bug.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from django.db import models

from app.feedback.models.feedback import Feedback


class Bug(Feedback):
pass
url = models.URLField(max_length=200, blank=True, null=True)
browser = models.CharField(max_length=200, default="")
platform = models.CharField(max_length=200, default="")
2 changes: 1 addition & 1 deletion app/feedback/models/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __str__(self):
return f"{self.title} - {self.status}"

class Meta:
ordering = ("created_at",)
ordering = ("-created_at",)

@classmethod
def has_read_permission(cls, request):
Expand Down
12 changes: 10 additions & 2 deletions app/feedback/serializers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
from app.feedback.serializers.bug import BugListSerializer
from app.feedback.serializers.idea import IdeaListSerializer
from app.feedback.serializers.bug import (
BugDetailSerializer,
BugCreateSerializer,
BugUpdateSerializer,
)
from app.feedback.serializers.idea import (
IdeaDetailSerializer,
IdeaCreateSerializer,
IdeaUpdateSerializer,
)
from app.feedback.serializers.feedback import FeedbackListPolymorphicSerializer
48 changes: 47 additions & 1 deletion app/feedback/serializers/bug.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from app.feedback.models.bug import Bug


class BugListSerializer(BaseModelSerializer):
class BugSerializer(BaseModelSerializer):
author = SimpleUserSerializer(read_only=True)

class Meta:
Expand All @@ -16,3 +16,49 @@ class Meta:
"author",
"description",
)


class BugCreateSerializer(BaseModelSerializer):
class Meta:
model = Bug
fields = (
"title",
"description",
)

def create(self, validated_data):
user = self.context["request"].user
validated_data["author"] = user

return super().create(validated_data)


class BugUpdateSerializer(BaseModelSerializer):
class Meta:
model = Bug
fields = (
"title",
"description",
"status",
)

def update(self, instance, validated_data):
return super().update(instance, validated_data)


class BugDetailSerializer(BaseModelSerializer):
author = SimpleUserSerializer(read_only=True)

class Meta:
model = Bug
fields = (
"id",
"title",
"description",
"status",
"created_at",
"author",
"url",
"platform",
"browser",
)
62 changes: 3 additions & 59 deletions app/feedback/serializers/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

from app.common.serializers import BaseModelSerializer
from app.feedback.models import Bug, Feedback, Idea
from app.feedback.serializers import BugListSerializer, IdeaListSerializer
from app.feedback.serializers import BugDetailSerializer, IdeaDetailSerializer


class FeedbackListPolymorphicSerializer(PolymorphicSerializer, BaseModelSerializer):
resource_type_field_name = "feedback_type"

model_serializer_mapping = {
Bug: BugListSerializer,
Idea: IdeaListSerializer,
Bug: BugDetailSerializer,
Idea: IdeaDetailSerializer,
}

class Meta:
Expand All @@ -23,59 +23,3 @@ class Meta:
"author",
"description",
)


class IdeaCreateSerializer(BaseModelSerializer):
class Meta:
model = Idea
fields = (
"title",
"description",
)

def create(self, validated_data):
user = self.context["request"].user
validated_data["author"] = user

return super().create(validated_data)


class BugCreateSerializer(BaseModelSerializer):
class Meta:
model = Bug
fields = (
"title",
"description",
)

def create(self, validated_data):
user = self.context["request"].user
validated_data["author"] = user

return super().create(validated_data)


class IdeaUpdateSerializer(BaseModelSerializer):
class Meta:
model = Feedback
fields = (
"title",
"description",
"status",
)

def update(self, instance, validated_data):
return super().update(instance, validated_data)


class BugUpdateSerializer(BaseModelSerializer):
class Meta:
model = Feedback
fields = (
"title",
"description",
"status",
)

def update(self, instance, validated_data):
return super().update(instance, validated_data)
45 changes: 44 additions & 1 deletion app/feedback/serializers/idea.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from app.feedback.models.idea import Idea


class IdeaListSerializer(BaseModelSerializer):
class IdeaSerializer(BaseModelSerializer):
author = SimpleUserSerializer(read_only=True)

class Meta:
Expand All @@ -16,3 +16,46 @@ class Meta:
"author",
"description",
)


class IdeaCreateSerializer(BaseModelSerializer):
class Meta:
model = Idea
fields = (
"title",
"description",
)

def create(self, validated_data):
user = self.context["request"].user
validated_data["author"] = user

return super().create(validated_data)


class IdeaUpdateSerializer(BaseModelSerializer):
class Meta:
model = Idea
fields = (
"title",
"description",
"status",
)

def update(self, instance, validated_data):
return super().update(instance, validated_data)


class IdeaDetailSerializer(BaseModelSerializer):
author = SimpleUserSerializer(read_only=True)

class Meta:
model = Idea
fields = (
"id",
"title",
"description",
"status",
"created_at",
"author",
)
14 changes: 12 additions & 2 deletions app/feedback/views/feedback.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from rest_framework import status
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters, status
from rest_framework.response import Response

from app.common.pagination import BasePagination
from app.common.permissions import BasicViewPermission
from app.common.viewsets import BaseViewSet
from app.feedback.filters.feedback import FeedbackFilter
from app.feedback.models.feedback import Feedback
from app.feedback.serializers.feedback import (
from app.feedback.serializers import (
BugCreateSerializer,
BugUpdateSerializer,
FeedbackListPolymorphicSerializer,
Expand All @@ -20,6 +22,14 @@ class FeedbackViewSet(BaseViewSet):
pagination_class = BasePagination
permission_classes = [BasicViewPermission]

filter_backends = [DjangoFilterBackend, filters.SearchFilter]
filterset_class = FeedbackFilter
search_fields = [
"title",
"author__first_name",
"author__last_name",
]

def create(self, request, *_args, **_kwargs):
data = request.data

Expand Down
Loading

0 comments on commit aabefff

Please sign in to comment.