-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feat(kontres)/add image to bookable item (#785) * added optional image to bookable item model * added update method in serializer to handle new images * linting * remove update method for images * Feat(kontres)/add approved by (#786) * added approved by field * endpoint will now set approved by * serializer will return full user object in approved_by_detail * created test for approved by * migration * remove unnecessary code * removed write-only field in approved-by context * Create minutes for Codex (#787) * init * format * Feat(minute)/viewset (#788) * added richer reponse on post and put * added to admin panel * added filter for minute --------- Co-authored-by: Erik Skjellevik <[email protected]>
- Loading branch information
Showing
25 changed files
with
525 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import factory | ||
from factory.django import DjangoModelFactory | ||
|
||
from app.content.factories.user_factory import UserFactory | ||
from app.content.models.minute import Minute | ||
|
||
|
||
class MinuteFactory(DjangoModelFactory): | ||
class Meta: | ||
model = Minute | ||
|
||
title = factory.Faker("sentence", nb_words=4) | ||
content = factory.Faker("text") | ||
author = factory.SubFactory(UserFactory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from app.content.filters.cheatsheet import CheatsheetFilter | ||
from app.content.filters.event import EventFilter | ||
from app.content.filters.user import UserFilter | ||
from app.content.filters.minute import MinuteFilter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django_filters.rest_framework import FilterSet, OrderingFilter | ||
|
||
from app.content.models import Minute | ||
|
||
|
||
class MinuteFilter(FilterSet): | ||
"""Filters minutes""" | ||
|
||
ordering = OrderingFilter( | ||
fields=("created_at", "updated_at", "title", "author", "tag") | ||
) | ||
|
||
class Meta: | ||
model = Minute | ||
fields = ["author", "title", "tag"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Generated by Django 4.2.5 on 2024-04-08 17:56 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("content", "0058_merge_20231217_2155"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Minute", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
("title", models.CharField(max_length=200)), | ||
("content", models.TextField(blank=True, default="")), | ||
( | ||
"author", | ||
models.ForeignKey( | ||
blank=True, | ||
default=None, | ||
null=True, | ||
on_delete=django.db.models.deletion.SET_NULL, | ||
related_name="meeting_minutes", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 4.2.5 on 2024-04-08 19:44 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("content", "0059_minute"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="minute", | ||
name="tag", | ||
field=models.CharField( | ||
choices=[("Møtereferat", "Minute"), ("Dokument", "Document")], | ||
default="Møtereferat", | ||
max_length=50, | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from django.db import models | ||
|
||
from app.common.enums import AdminGroup | ||
from app.common.permissions import BasePermissionModel | ||
from app.content.enums import MinuteTagEnum | ||
from app.content.models.user import User | ||
from app.util.models import BaseModel | ||
|
||
|
||
class Minute(BaseModel, BasePermissionModel): | ||
write_access = (AdminGroup.INDEX,) | ||
read_access = (AdminGroup.INDEX,) | ||
|
||
title = models.CharField(max_length=200) | ||
content = models.TextField(default="", blank=True) | ||
tag = models.CharField( | ||
max_length=50, choices=MinuteTagEnum.choices, default=MinuteTagEnum.MINUTE | ||
) | ||
author = models.ForeignKey( | ||
User, | ||
blank=True, | ||
null=True, | ||
default=None, | ||
on_delete=models.SET_NULL, | ||
related_name="meeting_minutes", | ||
) | ||
|
||
@classmethod | ||
def has_update_permission(cls, request): | ||
return cls.has_write_permission(request) | ||
|
||
@classmethod | ||
def has_destroy_permission(cls, request): | ||
return cls.has_write_permission(request) | ||
|
||
@classmethod | ||
def has_retrieve_permission(cls, request): | ||
return cls.has_read_permission(request) | ||
|
||
def has_object_read_permission(self, request): | ||
return self.has_read_permission(request) | ||
|
||
def has_object_update_permission(self, request): | ||
return self.has_write_permission(request) | ||
|
||
def has_object_destroy_permission(self, request): | ||
return self.has_write_permission(request) | ||
|
||
def has_object_retrieve_permission(self, request): | ||
return self.has_read_permission(request) | ||
|
||
def __str__(self): | ||
return self.title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from rest_framework import serializers | ||
|
||
from app.content.models import Minute, User | ||
|
||
|
||
class SimpleUserSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = User | ||
fields = ("user_id", "first_name", "last_name", "image") | ||
|
||
|
||
class MinuteCreateSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Minute | ||
fields = ("title", "content", "tag") | ||
|
||
def create(self, validated_data): | ||
author = self.context["request"].user | ||
minute = Minute.objects.create(**validated_data, author=author) | ||
return minute | ||
|
||
|
||
class MinuteSerializer(serializers.ModelSerializer): | ||
author = SimpleUserSerializer(read_only=True) | ||
|
||
class Meta: | ||
model = Minute | ||
fields = ("id", "title", "content", "author", "created_at", "updated_at", "tag") | ||
|
||
|
||
class MinuteUpdateSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Minute | ||
fields = ("id", "title", "content", "tag") | ||
|
||
def update(self, instance, validated_data): | ||
return super().update(instance, validated_data) | ||
|
||
|
||
class MinuteListSerializer(serializers.ModelSerializer): | ||
author = SimpleUserSerializer(read_only=True) | ||
|
||
class Meta: | ||
model = Minute | ||
fields = ("id", "title", "author", "created_at", "updated_at", "tag") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
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.content.filters import MinuteFilter | ||
from app.content.models import Minute | ||
from app.content.serializers import ( | ||
MinuteCreateSerializer, | ||
MinuteListSerializer, | ||
MinuteSerializer, | ||
MinuteUpdateSerializer, | ||
) | ||
|
||
|
||
class MinuteViewSet(BaseViewSet): | ||
serializer_class = MinuteSerializer | ||
permission_classes = [BasicViewPermission] | ||
pagination_class = BasePagination | ||
queryset = Minute.objects.all() | ||
|
||
filter_backends = [DjangoFilterBackend, filters.SearchFilter] | ||
filterset_class = MinuteFilter | ||
search_fields = [ | ||
"title", | ||
"author__first_name", | ||
"author__last_name", | ||
"author__user_id", | ||
] | ||
|
||
def get_serializer_class(self): | ||
if hasattr(self, "action") and self.action == "list": | ||
return MinuteListSerializer | ||
return super().get_serializer_class() | ||
|
||
def create(self, request, *args, **kwargs): | ||
data = request.data | ||
serializer = MinuteCreateSerializer(data=data, context={"request": request}) | ||
if serializer.is_valid(): | ||
minute = super().perform_create(serializer) | ||
serializer = MinuteSerializer(minute) | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
|
||
return Response( | ||
{"detail": serializer.errors}, status=status.HTTP_400_BAD_REQUEST | ||
) | ||
|
||
def update(self, request, *args, **kwargs): | ||
minute = self.get_object() | ||
serializer = MinuteUpdateSerializer( | ||
minute, data=request.data, context={"request": request} | ||
) | ||
if serializer.is_valid(): | ||
minute = super().perform_update(serializer) | ||
serializer = MinuteSerializer(minute) | ||
return Response(serializer.data, status=status.HTTP_200_OK) | ||
|
||
return Response( | ||
{"detail": serializer.errors}, status=status.HTTP_400_BAD_REQUEST | ||
) | ||
|
||
def destroy(self, request, *args, **kwargs): | ||
super().destroy(request, *args, **kwargs) | ||
return Response({"detail": "The minute was deleted"}, status=status.HTTP_200_OK) |
23 changes: 23 additions & 0 deletions
23
app/kontres/migrations/0007_bookableitem_image_bookableitem_image_alt.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 4.2.5 on 2024-03-22 12:36 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("kontres", "0006_rename_alcohol_agreement_reservation_serves_alcohol"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="bookableitem", | ||
name="image", | ||
field=models.URLField(blank=True, max_length=600, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="bookableitem", | ||
name="image_alt", | ||
field=models.CharField(blank=True, max_length=200, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Generated by Django 4.2.5 on 2024-04-06 09:39 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
("kontres", "0007_bookableitem_image_bookableitem_image_alt"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="reservation", | ||
name="approved_by", | ||
field=models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.SET_NULL, | ||
related_name="approved_reservations", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
] |
Oops, something went wrong.