Skip to content

Commit

Permalink
update events
Browse files Browse the repository at this point in the history
  • Loading branch information
deawer234 committed Oct 4, 2023
1 parent 28af4b0 commit 73cd8ed
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 9 deletions.
46 changes: 44 additions & 2 deletions fiesta/apps/events/forms/event.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from apps.fiestaforms.forms import BaseModelForm
from apps.events.models import Event
from django.forms import Field as FormField, modelform_factory, CharField, HiddenInput
from apps.events.models import Event, Organizer
from django.forms import Field as FormField, modelform_factory, CharField, HiddenInput, ChoiceField, Fiel
from django.utils.translation import gettext_lazy as _

class AddEventForm(BaseModelForm):
section_name = CharField(label=_("ESN section"), disabled=True)
author_name = CharField(label=_("Author of the event"), disabled=True)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.fields["section"].disabled = True
self.fields["author"].disabled = True

self.initial["section_name"] = self.initial["section"].name
self.initial["author_name"] = self.initial["author"].full_name


class Meta:
model = Event
Expand All @@ -27,8 +31,46 @@ class Meta:
"landscape_cover",
"portrait_cover",
"section",
"author"
)
widgets = {
"section": HiddenInput,
"author": HiddenInput,
}

class UpdateEventForm(BaseModelForm):
# section_name = CharField(label=_("ESN section"), disabled=True)
# author_name = CharField(label=_("Author of the event"), disabled=True)

add_organizer = ChoiceField()

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

# self.fields["section"].disabled = True
# self.fields["author"].disabled = True

# self.initial["section_name"] = self.initial["section"].name
# self.initial["author_name"] = self.initial["author"].full_name


class Meta:
model = Event
fields = (
# TODO: place ?
"title",
"subtitle",
"description",
"capacity",
"state",
"start",
"end",
"landscape_cover",
"portrait_cover",
"section",
"author"
)
widgets = {
"section": HiddenInput,
"author": HiddenInput,
}
8 changes: 7 additions & 1 deletion fiesta/apps/events/templates/events/event_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ <h1>{{ event.title }}</h1>
Place:{{ event.place }}<br>
Author:{{ event.author }}<br>
ESN Section {{ event.section }}<br>


<a href="{% url "events:event-update" event.id %}" class="button-with-icon">
<button class="button-style">Add event</button>
<svg class="h-8 w-8 text-black" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"/>
</svg>
</a>

<br><br>
{% if event.organizers.all %}
Expand Down
11 changes: 11 additions & 0 deletions fiesta/apps/events/templates/events/parts/update_event_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<form hx-post="{% url "events:event-update" event.id %}"
hx-swap="outerHTML"
{% if form.is_multipart %}enctype="multipart/form-data" hx-encoding="multipart/form-data"{% endif %}>
{% csrf_token %}
{% if redirect_field_value %}
<input type="hidden"
name="{{ redirect_field_name }}"
value="{{ redirect_field_value }}" />
{% endif %}
{{ form }}
</form>
9 changes: 9 additions & 0 deletions fiesta/apps/events/templates/events/update_event.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "fiesta/base-variants/center-card-2xl.html" %}

{% load i18n %}

{% block card_body %}

{% include "events/parts/update_event_form.html" %}

{% endblock %}
3 changes: 2 additions & 1 deletion fiesta/apps/events/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.urls import path

from .views import EventsIndexView
from .views.event import AddEventView, EventDetailView, ParticipantsView
from .views.event import AddEventView, EventDetailView, ParticipantsView, UpdateEventView

# Define your urls here

Expand All @@ -12,6 +12,7 @@
urlpatterns = [
path('', EventsIndexView.as_view(), name="index"),
path('add-event', AddEventView.as_view(), name="add-event"),
path('event-update/<uuid:pk>', UpdateEventView.as_view(), name="event-update"),
path('event-detail/<uuid:pk>', EventDetailView.as_view(), name="event-detail"),
path("event-detail/<uuid:pk>/participants", ParticipantsView.as_view(), name="participants"), # event-detail/<uuid:pk>/

Expand Down
3 changes: 2 additions & 1 deletion fiesta/apps/events/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from .index import EventsIndexView
from .event import AddEventView, EventDetailView
from .event import AddEventView, EventDetailView, UpdateEventView

__all__ = [
"EventsIndexView",
"AddEventView",
"EventDetailView",
"UpdateEventView"
]
49 changes: 45 additions & 4 deletions fiesta/apps/events/views/event.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import Any
from uuid import UUID

import django_filters
from django.contrib.postgres.search import SearchVector
from django.forms import TextInput
from django.views.generic import CreateView, DetailView
from django.views.generic import CreateView, DetailView, UpdateView
import django_tables2 as tables

from django.utils.translation import gettext_lazy as _
Expand All @@ -18,13 +19,15 @@
from apps.fiestaforms.views.htmx import HtmxFormMixin
from django.contrib.messages.views import SuccessMessageMixin
from apps.plugins.middleware.plugin import HttpRequest
from apps.events.forms.event import AddEventForm
from apps.events.forms.event import AddEventForm, UpdateEventForm
from ..models.participant import ParticipantState
from ...fiestatables.columns import ImageColumn, NaturalDatetimeColumn, LabeledChoicesColumn
from ...fiestatables.filters import BaseFilterSet, ProperDateFromToRangeFilter
from ...fiestatables.views.tables import FiestaTableView
from ...sections.views.mixins.membership import EnsurePrivilegedUserViewMixin
from ...utils.breadcrumbs import with_breadcrumb
from allauth.account.utils import get_next_redirect_url
from django.contrib.auth import REDIRECT_FIELD_NAME


@with_breadcrumb(_("Events"))
Expand All @@ -46,14 +49,51 @@ class AddEventView(
success_message = _("Event added")

def get_initial(self):
print(self.request.in_space_of_section.id)
return dict(
section=self.request.in_space_of_section,
author=self.request.user
)

def get_success_url(self):
return reverse("events:index")

@with_breadcrumb(_("Events"))
@with_breadcrumb(_("Update"))
class UpdateEventView(
UpdateView,
HtmxFormMixin,
AjaxViewMixin,
SuccessMessageMixin
):
request: HttpRequest
object: Event

template_name = 'events/update_event.html'
ajax_template_name = 'events/parts/update_event_form.html'

form_class = UpdateEventForm

success_message = _("Event updated")

def get_object(self, queryset=None):
event_id = self.kwargs.get('pk')
return self.request.in_space_of_section.events.get(id=event_id)

def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
data.update(
{
"redirect_field_name": REDIRECT_FIELD_NAME,
"redirect_field_value": get_next_redirect_url(self.request, REDIRECT_FIELD_NAME),
}
)
return data

def get_success_url(self):
return reverse("events:event-detail", args=[self.object.id])




@with_breadcrumb(_("Events"))
@with_breadcrumb(_("Detail"))
Expand All @@ -71,7 +111,7 @@ class EventParticipantsFilter(BaseFilterSet):
label=_("Search"),
widget=TextInput(attrs={"placeholder": _("Hannah, Diego, Joe...")}),
)
state = ChoiceFilter(choices=EventState.choices, label=_("State"))
state = ChoiceFilter(choices=ParticipantState.choices, label=_("State"))

created = ProperDateFromToRangeFilter(label=_("Created"))

Expand Down Expand Up @@ -145,6 +185,7 @@ class ParticipantsView(EnsurePrivilegedUserViewMixin, FiestaTableView):


def get_queryset(self):
print(self.request.in_space_of_section.memberships.all())
event_id = self.kwargs.get('pk')
return self.request.in_space_of_section.events.get(id=event_id).participants.filter(
state__in=(
Expand Down

0 comments on commit 73cd8ed

Please sign in to comment.