Skip to content

Commit

Permalink
added event creation and basic listing
Browse files Browse the repository at this point in the history
  • Loading branch information
deawer234 committed Sep 27, 2023
1 parent 0d227b4 commit 1ddfc82
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 5 deletions.
Empty file.
34 changes: 34 additions & 0 deletions fiesta/apps/events/forms/event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from apps.fiestaforms.forms import BaseModelForm
from apps.events.models import Event
from django.forms import Field as FormField, modelform_factory, CharField, HiddenInput
from django.utils.translation import gettext_lazy as _

class AddEventForm(BaseModelForm):
section_name = CharField(label=_("ESN section"), disabled=True)

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

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

self.initial["section_name"] = self.initial["section"].name

class Meta:
model = Event
fields = (
# TODO: place ?
"title",
"subtitle",
"description",
"capacity",
"state",
"start",
"end",
"landscape_cover",
"portrait_cover",
"section",
)
widgets = {
"section": HiddenInput,
}

9 changes: 9 additions & 0 deletions fiesta/apps/events/templates/events/add_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/add_event_form.html" %}

{% endblock %}
48 changes: 46 additions & 2 deletions fiesta/apps/events/templates/events/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
{% extends "fiesta/base.html" %}

<!-- Missing breadcrums -->
{% block main %}
<!-- <h1>Upcoming Events of {{ request.in_space_of_section }}</h1>-->
<h1>Upcoming Events of {{ request.in_space_of_section }}</h1>
<div class="container mx-auto p-6">
<h1 class="text-3xl font-semibold mb-4">Upcoming Events</h1>
<ul class="divide-y divide-gray-300">
<!-- Event Item -->
{% for event in request.in_space_of_section.events.all %}
{% if request.membership.is_international %}
{% if not event.state == "draft" %}
<li class="py-4">
<div class="flex items-center space-x-4">
<div class="flex-shrink-0">
<div class="h-12 w-12 rounded-full bg-cover bg-center"
style='background-image: url("{{ event.portrait_cover }}")'></div>
</div>
<div class="flex-grow">
<h2 class="text-xl font-semibold">{{ event.title }}</h2>
<p class="text-gray-600">{{ event.start }}</p>
<p class="text-gray-600">{{ event.description }}</p>
</div>
</div>
</li>
{% endif %}
{% else %}
<li class="py-4">
<div class="flex items-center space-x-4">
<div class="flex-shrink-0">
<div class="h-12 w-12 rounded-full bg-cover bg-center"
style='background-image: url("{{ event.portrait_cover }}")'></div>
</div>
<div class="flex-grow">
<h2 class="text-xl font-semibold">{{ event.title }}</h2>
<p class="text-gray-600">{{ event.start }}</p>
<p class="text-gray-600">{{ event.description }}</p>
</div>
</div>
</li>
{% endif %}
{% endfor %}
</ul>
</div>

<!-- Only allow adding of events to members and admins -->
{% if not request.membership.is_international %}
<button><a href="{% url "events:add-event" %}">Add event</a></button>
{% endif %}
<!-- {{ request.in_space_of_section.events }}-->


Expand Down
7 changes: 7 additions & 0 deletions fiesta/apps/events/templates/events/parts/add_event_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<form hx-post="{% url "events:add-event" %}"
id="change-membership-state-form"
hx-swap="outerHTML">
<h1 class="card-title">{{ object }}</h1>
{% csrf_token %}
{{ form }}
</form>
7 changes: 5 additions & 2 deletions fiesta/apps/events/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from django.urls import path, include

from .views import EventsIndexView

from .views.event import AddEventView, EventView
# Define your urls here

app_name="events"
urlpatterns = [
path('', EventsIndexView.as_view())
path('', EventView.as_view(), name="index"),
path('add-event', AddEventView.as_view(), name="add-event"),
]
4 changes: 3 additions & 1 deletion fiesta/apps/events/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from .index import EventsIndexView
from .event import AddEventView, EventView

__all__ = [
"EventsIndexView"
"EventView",
"AddEventView",
]
50 changes: 50 additions & 0 deletions fiesta/apps/events/views/event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from typing import Any
from django.db import models
from django.views.generic import CreateView, ListView
from apps.sections.views.mixins.membership import EnsurePrivilegedUserViewMixin
from allauth.account.utils import get_next_redirect_url
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
from django.urls import reverse
from django.contrib.auth import REDIRECT_FIELD_NAME
from ..models.event import Event
from apps.utils.views import AjaxViewMixin
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.utils.breadcrumbs import with_breadcrumb, with_object_breadcrumb
from apps.sections.models.section import Section

class EventView(ListView):
template_name='events/index.html'
model = Event

def get_queryset(self):
return super().get_queryset()

class AddEventView(
CreateView,
HtmxFormMixin,
AjaxViewMixin,
SuccessMessageMixin
):

request: HttpRequest
object: Event

template_name='events/add_event.html'
ajax_template_name = 'events/parts/add_event_form.html'

form_class = AddEventForm

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,
)

def get_success_url(self):
return reverse("events:index")
2 changes: 2 additions & 0 deletions fiesta/apps/events/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

class EventsIndexView(TemplateView):
template_name = 'events/index.html'


0 comments on commit 1ddfc82

Please sign in to comment.