feat: Implementierung des 'Heimspiel'-Status für Spiele

This commit is contained in:
Matthias Nagel 2025-10-02 14:04:17 +02:00
parent cebda0838b
commit 450d3597d2
12 changed files with 64 additions and 6 deletions

View File

@ -19,9 +19,11 @@ class TrainingForm(forms.ModelForm):
class GameForm(forms.ModelForm):
start_time = forms.DateTimeField(input_formats=['%d.%m.%Y %H:%M', '%Y-%m-%dT%H:%M'], widget=forms.DateTimeInput(format='%d.%m.%Y %H:%M', attrs={'type': 'datetime-local'}))
end_time = forms.DateTimeField(input_formats=['%d.%m.%Y %H:%M', '%Y-%m-%dT%H:%M'], widget=forms.DateTimeInput(format='%d.%m.%Y %H:%M', attrs={'type': 'datetime-local'}), required=False)
is_home_game = forms.BooleanField(required=False)
class Meta:
model = Game
fields = ['title', 'description', 'start_time', 'end_time', 'location_address', 'team', 'opponent', 'meeting_minutes_before_game', 'season', 'min_players']
fields = ['title', 'description', 'start_time', 'end_time', 'location_address', 'team', 'opponent', 'meeting_minutes_before_game', 'season', 'min_players', 'is_home_game']
class OpenGameForm(forms.Form):
teams = forms.ModelMultipleChoiceField(queryset=Team.objects.none(), widget=forms.CheckboxSelectMultiple)

View File

@ -0,0 +1,18 @@
# Generated by Django 5.2.6 on 2025-10-02 10:58
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('calendars', '0003_game_opened_for_teams'),
]
operations = [
migrations.AddField(
model_name='game',
name='is_home_game',
field=models.BooleanField(default=True),
),
]

View File

@ -27,6 +27,7 @@ class Game(Event):
meeting_minutes_before_game = models.PositiveIntegerField(default=60)
season = models.CharField(max_length=255, blank=True)
min_players = models.PositiveIntegerField(default=9)
is_home_game = models.BooleanField(default=True)
opened_for_teams = models.ManyToManyField('clubs.Team', related_name='opened_games', blank=True)
class GameResult(models.Model):

View File

@ -1,4 +1,5 @@
{% extends "base.html" %}
{% load l10n %}
{% block content %}
<div class="row justify-content-center">
@ -10,7 +11,26 @@
<div class="card-body">
<form method="post">
{% csrf_token %}
{{ form.as_p }}
{% for field in form %}
<div class="mb-3">
<label for="{{ field.id_for_label }}" class="form-label">{{ field.label }}</label>
{% if object and field.name == 'start_time' %}
<p>Current: {{ object.start_time|localize }}</p>
{% endif %}
{% if object and field.name == 'end_time' %}
<p>Current: {{ object.end_time|localize }}</p>
{% endif %}
{{ field }}
{% if field.help_text %}
<small class="form-text text-muted">{{ field.help_text }}</small>
{% endif %}
{% for error in field.errors %}
<div class="alert alert-danger">{{ error }}</div>
{% endfor %}
</div>
{% endfor %}
<button type="submit" class="btn btn-primary">Save</button>
</form>
</div>

View File

@ -70,10 +70,16 @@ class GameCreateView(LoginRequiredMixin, CreateView):
class EventUpdateView(LoginRequiredMixin, CoachCheckMixin, UpdateView):
model = Event
form_class = EventForm
template_name = 'calendars/event_form.html'
success_url = reverse_lazy('dashboard')
def get_form_class(self):
if hasattr(self.object, 'game'):
return GameForm
if hasattr(self.object, 'training'):
return TrainingForm
return EventForm
class EventDeleteView(LoginRequiredMixin, CoachCheckMixin, DeleteView):
model = Event
template_name = 'calendars/event_confirm_delete.html'

View File

@ -28,7 +28,12 @@
{% endif %}
">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">{{ item.event.title }}</h5>
<h5 class="mb-1">
{{ item.event.title }}
{% if item.event.game.is_home_game %}
<i class="bi bi-house-door-fill"></i>
{% endif %}
</h5>
<small>{{ item.event.start_time|localize }}</small>
</div>
<p class="mb-1"><strong>Team:</strong> {{ item.event.team.name }}</p>
@ -104,7 +109,12 @@
{% endif %}
">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">{{ item.event.title }}</h5>
<h5 class="mb-1">
{{ item.event.title }}
{% if item.event.game.is_home_game %}
<i class="bi bi-house-door-fill"></i>
{% endif %}
</h5>
<small>{{ item.event.start_time|localize }}</small>
</div>
<p class="mb-1"><strong>Team:</strong> {{ item.event.team.name }}</p>

Binary file not shown.

View File

@ -4,6 +4,7 @@
<head>
<title>Baseball Organisator</title>
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<style>
.event-game {
border-left: 5px solid #dc3545; /* red */