-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added event creation and basic listing
- Loading branch information
Showing
9 changed files
with
156 additions
and
5 deletions.
There are no files selected for viewing
Empty file.
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,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, | ||
} | ||
|
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,9 @@ | ||
{% extends "fiesta/base-variants/center-card-2xl.html" %} | ||
|
||
{% load i18n %} | ||
|
||
{% block card_body %} | ||
|
||
{% include "events/parts/add_event_form.html" %} | ||
|
||
{% endblock %} |
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
7 changes: 7 additions & 0 deletions
7
fiesta/apps/events/templates/events/parts/add_event_form.html
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,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> |
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,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"), | ||
] |
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,5 +1,7 @@ | ||
from .index import EventsIndexView | ||
from .event import AddEventView, EventView | ||
|
||
__all__ = [ | ||
"EventsIndexView" | ||
"EventView", | ||
"AddEventView", | ||
] |
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,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") |
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 |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
|
||
class EventsIndexView(TemplateView): | ||
template_name = 'events/index.html' | ||
|
||
|