Skip to content

Commit

Permalink
Merge branch 'dev' into feat(user)/user-bio
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNyl committed Apr 16, 2024
2 parents 87974ce + 95ef58c commit 1439062
Show file tree
Hide file tree
Showing 39 changed files with 1,377 additions and 101 deletions.
7 changes: 3 additions & 4 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
## Proposed changes
Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue.
Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue. Remove this part with the description.

Issue number: closes #
Issue number: closes # (remove if not an issue)


## Pull request checklist

Please check if your PR fulfills the following requirements:
- [ ] CHANGELOG.md has been updated. [Guide](https://tihlde.slab.com/posts/changelog-z8hybjom)
- [ ] Tests for the changes have been added (for bug fixes / features)
- [ ] Docs have been reviewed and added / updated if needed (for bug fixes / features)
- [ ] API docs on [Codex](https://codex.tihlde.org/contributing) have been reviewed and added / updated if needed (for bug fixes / features)
- [ ] The fixtures have been updated if needed (for migrations)

## Further comments
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@

## Neste versjon

## Versjon 2023.04.08
-**Codex** Index brukere kan nå opprette dokumenter og møtereferater i Codex.

## Versjon 2023.03.11
- 🦟 **Vipps** Brukere som kommer fra venteliste vil nå få en payment countdown startet, slik at de blir kastet ut hvis de ikke betaler.
-**Venteliste** Brukere vil nå se sin reelle ventelisteplass som tar hensyn til prioriteringer.
- 🎨 **Logging** SQL Debug for pytest er skrudd av.
-**Kontres** Endepunkter for reservasjoner av utstyr og kontor.

## Versjon 2023.02.07
- 🦟 **Vipps** Brukere kan nå oppdatere betalt arrangement, uten at det betalte arrangementet blir slettet.

Expand Down
3 changes: 3 additions & 0 deletions app/communication/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ class UserNotificationSettingType(models.TextChoices):
FINE = "FINE", "Grupper - bot"
GROUP_MEMBERSHIP = "GROUP_MEMBERSHIP", "Grupper - medlemsskap"
OTHER = "OTHER", "Andre"
RESERVATION_NEW = "RESERVATION NEW", "Ny reservasjon"
RESERVATION_APPROVED = "RESERVATION APPROVED", "Godkjent reservasjon"
RESERVATION_CANCELLED = "RESERVATION CANCELLED", "Avslått reservasjon"
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 4.2.5 on 2024-04-10 16:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("communication", "0009_alter_usernotificationsetting_notification_type"),
]

operations = [
migrations.AlterField(
model_name="usernotificationsetting",
name="notification_type",
field=models.CharField(
choices=[
("REGISTRATION", "Påmeldingsoppdateringer"),
("UNREGISTRATION", "Avmeldingsoppdateringer"),
("STRIKE", "Prikkoppdateringer"),
("EVENT_SIGN_UP_START", "Arrangementer - påmeldingsstart"),
("EVENT_SIGN_OFF_DEADLINE", "Arrangementer - avmeldingsfrist"),
("EVENT_EVALUATION", "Arrangementer - evaluering"),
("EVENT_INFO", "Arrangementer - info fra arrangør"),
("FINE", "Grupper - bot"),
("GROUP_MEMBERSHIP", "Grupper - medlemsskap"),
("OTHER", "Andre"),
("RESERVATION NEW", "Ny reservasjon"),
("RESERVATION APPROVED", "Godkjent reservasjon"),
("RESERVATION CANCELLED", "Avslått reservasjon"),
],
max_length=30,
),
),
]
7 changes: 7 additions & 0 deletions app/content/admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,10 @@ def object_link(self, obj):

object_link.admin_order_field = "object_repr"
object_link.short_description = "object"


@admin.register(models.Minute)
class MinuteAdmin(admin.ModelAdmin):
list_display = ("title", "author", "created_at", "updated_at")
search_fields = ("title", "content", "author__user_id")
list_filter = ("author",)
5 changes: 5 additions & 0 deletions app/content/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ class CategoryEnum(ChoiceEnum):
KURS = "Kurs"
ANNET = "Annet"
FADDERUKA = "Fadderuka"


class MinuteTagEnum(models.TextChoices):
MINUTE = "Møtereferat"
DOCUMENT = "Dokument"
1 change: 1 addition & 0 deletions app/content/factories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
from app.content.factories.qr_code_factory import QRCodeFactory
from app.content.factories.user_bio_factory import UserBioFactory
from app.content.factories.logentry_factory import LogEntryFactory
from app.content.factories.minute_factory import MinuteFactory
14 changes: 14 additions & 0 deletions app/content/factories/minute_factory.py
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)
1 change: 1 addition & 0 deletions app/content/filters/__init__.py
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
15 changes: 15 additions & 0 deletions app/content/filters/minute.py
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"]
47 changes: 47 additions & 0 deletions app/content/migrations/0059_minute.py
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,
},
),
]
22 changes: 22 additions & 0 deletions app/content/migrations/0060_minute_tag.py
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,
),
),
]
1 change: 1 addition & 0 deletions app/content/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
get_strike_strike_size,
)
from app.content.models.qr_code import QRCode
from app.content.models.minute import Minute
53 changes: 53 additions & 0 deletions app/content/models/minute.py
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
50 changes: 34 additions & 16 deletions app/content/models/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ def delete(self, *args, **kwargs):
if moved_registration:
moved_registration.save()

if (
moved_registration.event.is_paid_event
and not moved_registration.is_on_wait
):
if moved_registration.event.is_paid_event:
try:
start_payment_countdown(
moved_registration.event, moved_registration
Expand Down Expand Up @@ -294,20 +291,41 @@ def is_prioritized(self):

@property
def wait_queue_number(self):
"""
Returns the number of people in front of the user in the waiting list.
"""
waiting_list_count = (
self.event.get_waiting_list()
.order_by("-created_at")
.filter(created_at__lte=self.created_at)
.count()
)

if waiting_list_count == 0 or not self.is_on_wait:
# Return None if the user is not on the waitlist to indicate they are not waiting for a spot.
if not self.is_on_wait:
return None

return waiting_list_count
# Retrieve all registrations for the event that are on the waitlist and order them by creation time.
waiting_list_registrations = self.event.registrations.filter(
is_on_wait=True
).order_by("created_at")

# Separate the waiting list registrations into prioritized and non-prioritized groups.
prioritized_registrations = [
reg for reg in waiting_list_registrations if reg.is_prioritized
]
non_prioritized_registrations = [
reg for reg in waiting_list_registrations if not reg.is_prioritized
]

# If the registration is prioritized, calculate its queue position among other prioritized registrations.
if self.is_prioritized:
if self in prioritized_registrations:
queue_position = prioritized_registrations.index(self) + 1
else:
return None
else:
# For non-prioritized registrations, calculate queue position considering all prioritized registrations first.
if self in non_prioritized_registrations:
queue_position = (
len(prioritized_registrations)
+ non_prioritized_registrations.index(self)
+ 1
)
else:
return None

return queue_position

def swap_users(self):
"""Swaps a user with a spot with a prioritized user, if such user exists"""
Expand Down
6 changes: 6 additions & 0 deletions app/content/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@
DefaultUserSerializer,
UserPermissionsSerializer,
)
from app.content.serializers.minute import (
MinuteCreateSerializer,
MinuteSerializer,
MinuteUpdateSerializer,
MinuteListSerializer,
)
45 changes: 45 additions & 0 deletions app/content/serializers/minute.py
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")
Loading

0 comments on commit 1439062

Please sign in to comment.