-
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.
Merge branch 'events' of https://github.com/esnvutbrno/buena-fiesta i…
…nto events
- Loading branch information
Showing
9 changed files
with
199 additions
and
13 deletions.
There are no files selected for viewing
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
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,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 |
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
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
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
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
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,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) |
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,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 %} |
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