Skip to content

Commit

Permalink
Merge branch 'develop' into feat-buddy-tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeejoee authored Oct 27, 2023
2 parents 021d507 + b672c93 commit 2bc247d
Show file tree
Hide file tree
Showing 23 changed files with 761 additions and 9 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default_language_version:
repos:
# basic hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand Down Expand Up @@ -38,22 +38,22 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.282'
rev: 'v0.1.1'
hooks:
- id: ruff
name: lint by Ruff
args: [ --fix, --exit-non-zero-on-fix ]

# uncompromise python formatter
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.10.1
hooks:
- id: black
name: format by black
exclude: ^.*\b(migrations)\b.*$

- repo: https://github.com/Riverside-Healthcare/djlint
rev: 'v1.32.1' # replace with the latest tag on GitHub
rev: 'v1.34.0' # replace with the latest tag on GitHub
hooks:
- id: djlint-django
entry: djlint --reformat
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ DC_CMD = $(cmd)
ARG =

MODELS_PNG = models.png
GRAPH_MODELS_CMD = graph_models accounts plugins auth sections \
GRAPH_MODELS_CMD = graph_models accounts plugins auth sections events \
universities esncards buddy_system \
--verbose-names --disable-sort-fields \
--pydot -X 'ContentType|Base*Model' \
Expand All @@ -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
3 changes: 3 additions & 0 deletions fiesta/apps/accounts/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ def __str__(self):
f"{self.home_university or (self.home_faculty.university if self.home_faculty else None) or ''} "
)

def is_esn_card_holder(self):
return False


__all__ = [
"UserProfile",
Expand Down
Empty file added fiesta/apps/events/__init__.py
Empty file.
58 changes: 58 additions & 0 deletions fiesta/apps/events/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from __future__ import annotations

from django.contrib import admin

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


@admin.register(EventsConfiguration)
class EventsConfigurationAdmin(BaseChildConfigurationAdmin):
base_model = BasePluginConfiguration
list_display = (
"name",
"section",
"shared",
"require_confirmation",
"members_can_create",
"online_purchases",
)
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
18 changes: 18 additions & 0 deletions fiesta/apps/events/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import annotations

from django.utils.translation import gettext_lazy as _

from apps.plugins.plugin import BasePluginAppConfig


class EventsConfig(BasePluginAppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "apps.events"
verbose_name = _("Events")
emoji = ""
description = _("Fiesta plugin to handle events management and registrations.")

configuration_model = "events.EventsConfiguration"


__all__ = ["EventsConfig"]
138 changes: 138 additions & 0 deletions fiesta/apps/events/migrations/0001_initial.py

Large diffs are not rendered by default.

Empty file.
17 changes: 17 additions & 0 deletions fiesta/apps/events/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from __future__ import annotations

from .configuration import EventsConfiguration
from .event import Event
from .organizer import Organizer
from .participant import Participant
from .place import Place
from .price_variant import PriceVariant

__all__ = [
"EventsConfiguration",
"Event",
"Organizer",
"Participant",
"Place",
"PriceVariant",
]
30 changes: 30 additions & 0 deletions fiesta/apps/events/models/configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import annotations

from django.db import models
from django.utils.translation import gettext_lazy as _

from apps.plugins.models import BasePluginConfiguration


class EventsConfiguration(BasePluginConfiguration):
require_confirmation = models.BooleanField(
default=True,
verbose_name=_("require confirmation to publish"),
)

members_can_create = models.BooleanField(
default=True,
verbose_name=_("basic members can create an event"),
)

online_purchases = models.BooleanField(
default=True,
verbose_name=_("online purchases"),
)

class Meta:
verbose_name = _("events configuration")
verbose_name_plural = _("events configurations")


__all__ = ["EventsConfiguration"]
137 changes: 137 additions & 0 deletions fiesta/apps/events/models/event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
from __future__ import annotations

from django.db import models
from django.utils.translation import gettext_lazy as _

from apps.files.storage import NamespacedFilesStorage
from apps.plugins.middleware.plugin import HttpRequest
from apps.utils.models import BaseTimestampedModel

# TODO Maybe pre-registration, registration and paused registration for different field.


class State(models.TextChoices):
DRAFT = "draft", _("Draft")
PUBLISHED = "published", _("Published")
HIDDEN = "hidden", _("Hidden") # Visible only after invite


def has_permission_for_cover_photo_view(request: HttpRequest, name: str) -> bool: # TODO
if request.user.is_authenticated:
return True

return False


class Event(BaseTimestampedModel):
# storage used for cover photos
event_portrait_cover_photo_storage = NamespacedFilesStorage(
"event-portrait-cover-photo",
has_permission=has_permission_for_cover_photo_view,
)

event_landscape_cover_photo_storage = NamespacedFilesStorage(
"event-landscape-cover-photo",
has_permission=has_permission_for_cover_photo_view,
)

title = models.CharField(
max_length=64,
unique=True,
verbose_name=_("title"),
help_text=_("full name of the event"),
)

subtitle = models.TextField(
verbose_name=_("subtitle"),
help_text=_("short description of the event"),
blank=True,
)

description = models.TextField(
verbose_name=_("description"),
help_text=_("full description of the event"),
)

capacity = models.SmallIntegerField(
verbose_name=_("capacity"),
help_text=_("capacity of the event"),
)

state = models.CharField(
choices=State.choices,
default=State.DRAFT,
max_length=16,
verbose_name=_("state"),
help_text=_("current state of the event"),
)

start = models.DateTimeField(
verbose_name=_("start"),
help_text=_("when the event starts"),
)

end = models.DateTimeField(
verbose_name=_("end"),
help_text=_("when the event ends"),
null=True,
blank=True,
)

landscape_cover = models.ImageField(
storage=event_landscape_cover_photo_storage,
upload_to=event_landscape_cover_photo_storage.upload_to,
verbose_name=_("landscape cover photo"),
null=True,
blank=True,
)

portrait_cover = models.ImageField(
storage=event_portrait_cover_photo_storage,
upload_to=event_portrait_cover_photo_storage.upload_to,
verbose_name=_("portrait cover photo"),
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.ForeignKey(
to="sections.Section",
on_delete=models.CASCADE,
related_name="events",
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")
verbose_name_plural = _("events")


__all__ = ["Event"]

# TODO hybrid registration, default user, only online (qr), offline registrations (counter, subtract from capacity)
47 changes: 47 additions & 0 deletions fiesta/apps/events/models/organizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from __future__ import annotations

from django.db import models
from django.utils.translation import gettext_lazy as _

from apps.utils.models import BaseTimestampedModel


class Role(models.TextChoices):
EVENT_LEADER = "event_leader", _("Event_leader")
OC = "oc", _("OC")


class Organizer(BaseTimestampedModel):
state = models.CharField(
choices=Role.choices,
default=Role.OC,
verbose_name=_("state"),
help_text=_("current state of the event"),
)

user = models.ForeignKey(
"accounts.User",
on_delete=models.CASCADE,
related_name="event",
verbose_name=_("user"),
db_index=True,
)

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

class Meta:
verbose_name = _("organizer")
verbose_name_plural = _("organizers")
unique_together = (("user", "event"),)

def __str__(self):
return self.user + self.event


__all__ = ["Organizer"]
Loading

0 comments on commit 2bc247d

Please sign in to comment.