Implement group management features and update templates for improved navigation

This commit is contained in:
Edgar P. Burkhart 2025-06-15 09:56:08 +02:00
parent f3e914aed8
commit 088bb52c07
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
9 changed files with 80 additions and 37 deletions

View file

@ -3,6 +3,16 @@ from django import forms
from . import models
class GroupForm(forms.ModelForm):
class Meta:
model = models.Group
fields = ["name"]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["name"].widget.attrs["placeholder"] = self.fields["name"].label
class GroupAddMembersForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

View file

@ -1,26 +1,33 @@
<p>Bienvenue {{ user.username }} !</p>
<h2>
<i class="ri-group-2-fill"></i> Mes groupes
</h2>
<p>
<a href="{% url "group_create" %}" role="button"><i class="ri-add-box-fill"></i> Créer un groupe</a>
{% if not user.youtubecredentials.credentials %}
<a href="{% url "youtube_login" %}" role="button"><i class="ri-youtube-fill"></i> Me connecter au compte Youtube</a>
{% extends "base.html" %}
{% load form %}
{% block content %}
<h1>
<i class="ri-music-ai-fill"></i> Musik
</h1>
<p>Bienvenue {{ user.username }} !</p>
<h2>
<i class="ri-group-2-fill"></i> Mes groupes
</h2>
<p>
{% if not user.youtubecredentials.credentials %}
<a href="{% url "youtube_login" %}" role="button"><i class="ri-youtube-fill"></i> Me connecter au compte Youtube</a>
{% endif %}
</p>
{% if user.owned_group_set.exists or user.group_set.exists %}
{% for group in user.owned_group_set.all %}
<a class="group" href="{{ group.get_absolute_url }}">
<article>
<i class="ri-vip-crown-fill owner i"></i> {{ group.name }}
</article>
</a>
{% endfor %}
{% for group in user.group_set.all %}
<a class="group" href="{{ group.get_absolute_url }}">
<article>
<i class="ri-group-2-fill i"></i> {{ group.name }} <span class="group-owner">{{ group.owner }}</span>
</article>
</a>
{% endfor %}
{% endif %}
</p>
{% if user.owned_group_set.exists or user.group_set.exists %}
{% for group in user.owned_group_set.all %}
<a class="group" href="{{ group.get_absolute_url }}">
<article>
<i class="ri-vip-crown-fill owner i"></i> {{ group.name }}
</article>
</a>
{% endfor %}
{% for group in user.group_set.all %}
<a class="group" href="{{ group.get_absolute_url }}">
<article>
<i class="ri-group-2-fill i"></i> {{ group.name }} <span class="group-owner">{{ group.owner }}</span>
</article>
</a>
{% endfor %}
{% endif %}
{% inline_form group_form action="group_create" submit="Créer" %}
{% endblock content %}

View file

@ -3,6 +3,7 @@ from django.urls import path
from . import views
urlpatterns = [
path("home", views.HomeView.as_view(), name="home"),
path("group/create/", views.GroupCreateView.as_view(), name="group_create"),
path(
"group/<int:pk>/update/", views.GroupUpdateView.as_view(), name="group_update"

View file

@ -11,12 +11,22 @@ from django.db import IntegrityError
from django.db.models import Count, Q
from django.shortcuts import get_object_or_404, redirect
from django.views import View
from django.views.generic import TemplateView
from django.views.generic.detail import DetailView, SingleObjectMixin
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from . import forms, models, utils
class HomeView(LoginRequiredMixin, TemplateView):
template_name = "game/home.html"
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
data["group_form"] = forms.GroupForm()
return data
class OwnerFilterMixin(LoginRequiredMixin):
def get_queryset(self):
return super().get_queryset().filter(owner=self.request.user)