diff --git a/blechreiz/settings.py b/blechreiz/settings.py index c8390af..624ebbe 100644 --- a/blechreiz/settings.py +++ b/blechreiz/settings.py @@ -145,7 +145,7 @@ INSTALLED_APPS = [ "musicians", "eventplanner", "eventplanner_gcal", - "simpleforum", + # "simpleforum", # Disabled "location_field", "scoremanager", # 'imagestore', # Disabled diff --git a/blechreiz/urls.py b/blechreiz/urls.py index 734d353..e6ee832 100644 --- a/blechreiz/urls.py +++ b/blechreiz/urls.py @@ -3,14 +3,12 @@ from django.conf.urls.static import static from django.contrib import admin from django.urls import include, path, re_path -from simpleforum import views as simpleforum_views - urlpatterns = [ path("", include("website.urls")), path("events/", include("eventplanner.urls")), path("musicians/", include("musicians.urls")), path("scores/", include("scoremanager.urls")), - path("messages/", simpleforum_views.message_view), + # path("messages/", simpleforum_views.message_view), # Disabled path("admin/", admin.site.urls), path("location_field/", include("location_field.urls")), path("eventplanner_gcal/", include("eventplanner_gcal.urls")), diff --git a/bootstrapTheme/templates/bootstrapTheme/bootstrapTheme.html b/bootstrapTheme/templates/bootstrapTheme/bootstrapTheme.html index b289368..bfe0a84 100644 --- a/bootstrapTheme/templates/bootstrapTheme/bootstrapTheme.html +++ b/bootstrapTheme/templates/bootstrapTheme/bootstrapTheme.html @@ -1,12 +1,12 @@ {% load sekizai_tags static %} {% addtoblock "css" strip %} -{% endaddtoblock %} {% addtoblock "css" strip %} - +{% endaddtoblock %} {% addtoblock "css" strip %} + {% endaddtoblock %} {% addtoblock "css" strip %} -{% endaddtoblock %} {% addtoblock "css" strip %} -{% endaddtoblock %} {% addtoblock "css" strip %} +{% endaddtoblock %} {% addtoblock "css" strip %} +{% endaddtoblock %} {% addtoblock "css" strip %} @@ -20,18 +20,16 @@ {% endaddtoblock %} {% addtoblock "js" strip %} - + {% endaddtoblock %} {% addtoblock "js" strip %} - + {% endaddtoblock %} {% addtoblock "js" strip %} - + {% endaddtoblock %} {% addtoblock "js" strip %} - -{% endaddtoblock %} {% addtoblock "js" strip %} - + {% endaddtoblock %} {% addtoblock "js" strip %} {% endaddtoblock %} {% addtoblock "js" %} diff --git a/eventplanner/models.py b/eventplanner/models.py index 67e29c9..f8bb9ba 100644 --- a/eventplanner/models.py +++ b/eventplanner/models.py @@ -159,13 +159,18 @@ class EventParticipation(models.Model): return self.user.username def save(self, *args, **kwargs): - prev = EventParticipation.objects.filter(event=self.event, user=self.user) - if len(prev) == 0: + # For new objects, just save directly + if self.pk is None: super().save(*args, **kwargs) - else: - prev = prev[0] + return + + # For existing objects, only save if values changed + try: + prev = EventParticipation.objects.get(pk=self.pk) if prev.status != self.status or prev.comment != self.comment: super().save(*args, **kwargs) + except EventParticipation.DoesNotExist: + super().save(*args, **kwargs) @staticmethod def hasUserSetParticipationForAllEvents(user): diff --git a/eventplanner/serializers.py b/eventplanner/serializers.py index 5c02c10..d17a164 100644 --- a/eventplanner/serializers.py +++ b/eventplanner/serializers.py @@ -1,21 +1,48 @@ +from django.contrib.auth.models import User from rest_framework import serializers from .models import Event, EventParticipation -class ParticipationSerializer(serializers.ModelSerializer): - event = serializers.PrimaryKeyRelatedField(queryset=Event.objects.all()) - user = serializers.CharField(source="get_username", read_only=True) - status = serializers.CharField(required=False) +class ParticipationSerializer(serializers.Serializer): + """Serializer for EventParticipation that handles username lookup.""" - class Meta: - model = EventParticipation - fields = ("event", "user", "status", "comment") + event = serializers.PrimaryKeyRelatedField(queryset=Event.objects.all()) + user = serializers.CharField() + status = serializers.CharField(required=False, default="-") + comment = serializers.CharField(required=False, allow_blank=True, default="") + + def to_representation(self, instance): + """Serialize an EventParticipation instance.""" + return { + "event": instance.event.pk, + "user": instance.user.username, + "status": instance.status, + "comment": instance.comment, + } + + def validate_user(self, value): + """Look up user by username (case-insensitive).""" + try: + return User.objects.get(username__iexact=value) + except User.DoesNotExist: + raise serializers.ValidationError(f"User '{value}' does not exist") def create(self, validated_data): - # Remove the get_username source field as it's read-only - validated_data.pop("get_username", None) - return super().create(validated_data) + """Create or update EventParticipation based on event and user.""" + event = validated_data.get("event") + user = validated_data.get("user") + status = validated_data.get("status", "-") + comment = validated_data.get("comment", "") + + # Use update_or_create to handle both new and existing participations + participation, created = EventParticipation.objects.update_or_create( + event=event, + user=user, + defaults={"status": status, "comment": comment}, + ) + + return participation def update(self, instance, validated_data): instance.status = validated_data.get("status", instance.status) diff --git a/eventplanner/templates/eventplanner/event_update_form.html b/eventplanner/templates/eventplanner/event_update_form.html index 807f6b3..2fcd289 100644 --- a/eventplanner/templates/eventplanner/event_update_form.html +++ b/eventplanner/templates/eventplanner/event_update_form.html @@ -14,26 +14,26 @@ {% addtoblock "css" strip %} {% endaddtoblock %} {% addtoblock "css" strip %} {% endaddtoblock %} {% addtoblock "css" strip %} {% endaddtoblock %} {% addtoblock "js" %} - - - + + + @@ -33,7 +35,6 @@ {% block menu_contents %}
  • HOME
  • Termine
  • -
  • Forum
  • Adressbuch
  • {% endblock %}