Skip to content

Commit

Permalink
Merge branch 'events' of https://github.com/esnvutbrno/buena-fiesta i…
Browse files Browse the repository at this point in the history
…nto events
  • Loading branch information
deawer234 committed Sep 26, 2023
2 parents 9728253 + 72892d4 commit 4c21053
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ shell_plus: da
migrate: DA_CMD = migrate ## Runs manage.py migrate for all apps
migrate: da

showmigrations: DA_CMD = showmigrations ## Runs manage.py showmigrations for all apps
showmigrations: da

optimizemigration: DA_CMD = optimizemigration ## Optimize last migration by optimizemigration: app= migration=
optimizemigration: ARG = $(name) $(migration)
optimizemigration: da
Expand Down
39 changes: 38 additions & 1 deletion fiesta/apps/events/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
from django.contrib import admin
from apps.plugins.models import BasePluginConfiguration

from .models import EventsConfiguration
from .models import EventsConfiguration, Event, Organizer, Participant, Place, PriceVariant
from ..plugins.admin import BaseChildConfigurationAdmin


@admin.register(EventsConfiguration)
class EventsConfigurationAdmin(BaseChildConfigurationAdmin):
base_model = BasePluginConfiguration
show_in_index = True


@admin.register(Event)
class EventAdmin(admin.ModelAdmin):
list_display = ("section", "title", "capacity", "state", "start", "end", "author", "place")
show_in_index = True

# @admin.display(
# description=_("Filled"),
# )
# def filled(self, obj: Section):
# return obj.memberships.count()
# TODO


@admin.register(Organizer)
class OrganizerAdmin(admin.ModelAdmin):
list_display = ("user", "event", "state")
show_in_index = True


@admin.register(Participant)
class ParticipantAdmin(admin.ModelAdmin):
list_display = ("user", "event", "price", "created")
show_in_index = True


@admin.register(Place)
class PlaceAdmin(admin.ModelAdmin):
list_display = ("name", "description", "link", "map_link", "section")
show_in_index = True


@admin.register(PriceVariant)
class PriceVariantAdmin(admin.ModelAdmin):
list_display = ("title", "type", "amount", "event", "available_from", "available_to")
show_in_index = True
29 changes: 22 additions & 7 deletions fiesta/apps/events/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,43 @@ class Event(BaseTimestampedModel):
null=True,
blank=True,
)

place = models.ForeignKey(
"events.Place",
on_delete=models.SET_NULL,
verbose_name=_("place"),
db_index=False,
null=True,
blank=True,
)

author = models.ForeignKey(
to="accounts.User",
on_delete=models.SET_NULL,
related_name="events",
verbose_name=_("author"),
db_index=False,
null=True,
blank=True,
)

section = models.ManyToManyField(
"sections.Section",
through="events.EventSection",
section = models.ForeignKey(
to="sections.Section",
on_delete=models.CASCADE,
related_name="events",
verbose_name=_("sections"),
help_text=_("Users from these sections can join this event."),
verbose_name=_("ESN section"),
help_text=_("Users from this section can join this event."),
db_index=True,
)

def __str__(self):
return self.title
return f"{self.title} - {self.start}"

class Meta:
ordering = ["start"]
verbose_name = _("Event")


__all__ = ["Event"]
#TODO hibrid registration, default user, only online (qr), offline registrations (counter, odecist od kapacity)

#TODO hybrid registration, default user, only online (qr), offline registrations (counter, subtract from capacity)
5 changes: 5 additions & 0 deletions fiesta/apps/events/models/organizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class Organizer(BaseTimestampedModel):
verbose_name=_("event"),
db_index=True,
)

class Meta:
verbose_name = _("Organizer")
unique_together = (("user", "event"),)


def __str__(self):
return self.user + self.event
Expand Down
17 changes: 14 additions & 3 deletions fiesta/apps/events/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,36 @@ class Participant(BaseModel):
user = models.ForeignKey(
to="accounts.User",
related_name="user",
on_delete=models.SET_NULL

on_delete=models.SET_NULL,
null=True,
db_index=True,
)

event = models.ForeignKey(
to="events.Event",
on_delete=models.SET_NULL,
related_name="event",
null=True,
db_index=True,
)

price = models.ForeignKey(
to="events.Price",
to="events.PriceVariant",
on_delete=models.SET_NULL,
related_name="price",
null=True,
db_index=False,
)

def __str__(self):
return self.title

class Meta:
unique_together = (("event", "user"),)
verbose_name = _("Participant")
ordering = ["created"]



__all__ = ["Participant"]

Expand Down
15 changes: 15 additions & 0 deletions fiesta/apps/events/models/place.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ class Place(BaseModel):
blank=True,
)

section = models.ForeignKey(
"sections.Section",
on_delete=models.CASCADE,
verbose_name=_("ESN section"),
db_index=True,
)

def __str__(self):
return self.name

class Meta:
verbose_name = _("Place")
unique_together = (("section", "name"),)


# TODO nearest tram stop?

def __str__(self):
Expand Down
85 changes: 85 additions & 0 deletions fiesta/apps/events/models/price_variant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from __future__ import annotations

from datetime import datetime

from django.db import models
from django.db.models import TextChoices
from django.utils.translation import gettext_lazy as _
from djmoney.models.fields import MoneyField # TODO poetry add django-money

from apps.accounts.models import User
from apps.utils.models import BaseModel


class EventPriceVariantType(TextChoices):
FREE = "free", _("Free")
STANDARD = "standard", _("Standard")
WITH_ESN_CARD = "with_esn_card", _("With ESN card")

def is_available(self, variant: PriceVariant, user: User):
to_ = variant.available_to
from_ = variant.available_from

if from_ is not None and from_ is not "" and from_ < datetime.now():
return False

if to_ is not None and to_ is not "" and to_ > datetime.now():
return False

if variant.type == self.STANDARD:
return True
elif variant.type == self.WITH_ESN_CARD and user.profile_or_none or user.profile.is_esn_card_holder():
return True

return False


class PriceVariant(BaseModel):
title = models.CharField(
max_length=256,
verbose_name=_("title"),
help_text=_("full name of the price"),
)

type = models.CharField(max_length=255, choices=EventPriceVariantType.choices)

amount = MoneyField(max_digits=10, decimal_places=2, default_currency='CZK')

event = models.ForeignKey(
"events.Event",
related_name="price_variant",
on_delete=models.CASCADE,
verbose_name=_("event"),
null=True,
db_index=True,
)

available_from = models.DateTimeField(
verbose_name=_("available from"),
help_text=_("From when users can purchase for this price."),
null=True,
blank=True,
)

available_to = models.DateTimeField(
verbose_name=_("available to"),
help_text=_("Until when users can purchase for this price."),
null=True,
blank=True,
)

data = models.JSONField(
verbose_name=_("data"),
help_text=_("any data related to the price"),
default=dict,
)

class Meta:
unique_together = (("title", "event"),)


__all__ = ["PriceVariant"]

# e = Event()
#
# e.price_variants.create(type=EventPriceVariantType.STANDARD, price=100)
7 changes: 6 additions & 1 deletion fiesta/apps/events/templates/events/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{% extends "fiesta/base.html" %}

{% block main %}<h1>Index View</h1>{% endblock %}
{% block main %}
<!-- <h1>Upcoming Events of {{ request.in_space_of_section }}</h1>-->
<!-- {{ request.in_space_of_section.events }}-->


{% endblock %}
12 changes: 11 additions & 1 deletion webpack/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -917,11 +917,16 @@ camelcase-css@^2.0.1:
resolved "https://registry.yarnpkg.com/camelcase-css/-/camelcase-css-2.0.1.tgz#ee978f6947914cc30c6b44741b6ed1df7f043fd5"
integrity sha512-QOSvevhslijgYwRx6Rv7zKdMF8lbRmx+uQGx2+vDc+KI/eBnsy9kit5aj23AgGu3pa4t9AgwbnXWqS+iOY+2aA==

caniuse-lite@^1.0.30001332, caniuse-lite@^1.0.30001517, caniuse-lite@^1.0.30001520:
caniuse-lite@^1.0.30001332, caniuse-lite@^1.0.30001517:
version "1.0.30001520"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001520.tgz#62e2b7a1c7b35269594cf296a80bdf8cb9565006"
integrity sha512-tahF5O9EiiTzwTUqAeFjIZbn4Dnqxzz7ktrgGlMYNLH43Ul26IgTMH/zvL3DG0lZxBYnlT04axvInszUsZULdA==

caniuse-lite@^1.0.30001538:
version "1.0.30001538"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001538.tgz#9dbc6b9af1ff06b5eb12350c2012b3af56744f3f"
integrity sha512-HWJnhnID+0YMtGlzcp3T9drmBJUVDchPJ08tpUGFLs9CYlwWPH2uLgpHn8fND5pCgXVtnGS3H4QR9XLMHVNkHw==

chalk@^2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
Expand Down Expand Up @@ -1445,6 +1450,11 @@ fraction.js@^4.2.0:
resolved "https://registry.yarnpkg.com/fraction.js/-/fraction.js-4.2.0.tgz#448e5109a313a3527f5a3ab2119ec4cf0e0e2950"
integrity sha512-MhLuK+2gUcnZe8ZHlaaINnQLl0xRIGRfcGk2yl8xoQAfHrSsL3rYu6FCmBdkdbhc9EPlwyGHewaRsvwRMJtAlA==

fraction.js@^4.3.6:
version "4.3.6"
resolved "https://registry.yarnpkg.com/fraction.js/-/fraction.js-4.3.6.tgz#e9e3acec6c9a28cf7bc36cbe35eea4ceb2c5c92d"
integrity sha512-n2aZ9tNfYDwaHhvFTkhFErqOMIb8uyzSQ+vGJBjZyanAKZVbGUQ1sngfk9FdkBw7G26O7AgNjLcecLffD1c7eg==

fresh@0.5.2:
version "0.5.2"
resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7"
Expand Down

0 comments on commit 4c21053

Please sign in to comment.