Implement group management features and update templates for improved navigation
This commit is contained in:
parent
f3e914aed8
commit
088bb52c07
9 changed files with 80 additions and 37 deletions
11
base/templates/base/inline_form.html
Normal file
11
base/templates/base/inline_form.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
{% for error in form.non_field_errors %}<article class="message error">{{ error }}</article>{% endfor %}
|
||||
<form method="post" {% if action %}action="{% url action %}"{% endif %}>
|
||||
{% csrf_token %}
|
||||
<fieldset role="group">
|
||||
{% for field in form %}{{ field }}{% endfor %}
|
||||
<input type="submit" {% if submit %}value="{{ submit }}"{% endif %}>
|
||||
{% if field.errors %}
|
||||
<small id="{{ field.errors.field_id }}_error" class="form-error">{{ field.errors|join:", " }}</small>
|
||||
{% endif %}
|
||||
</fieldset>
|
||||
</form>
|
|
@ -4,7 +4,7 @@
|
|||
<i class="ri-music-ai-fill big-logo"></i>
|
||||
<h1>Musik</h1>
|
||||
<p>
|
||||
<a href="{% url "login" %}" role="button"><i class="ri-play-fill"></i> Jouer</a>
|
||||
<a href="{% url "home" %}" role="button"><i class="ri-play-fill"></i> Jouer</a>
|
||||
</p>
|
||||
</main>
|
||||
<footer>
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
{% include "game/home.html" %}
|
||||
{% endblock content %}
|
||||
{% block body %}
|
||||
{% if user.is_authenticated %}
|
||||
{{ block.super }}
|
||||
{% else %}
|
||||
{% include "hero.html" %}
|
||||
{% endif %}
|
||||
{% include "hero.html" %}
|
||||
{% endblock body %}
|
||||
|
|
|
@ -4,8 +4,13 @@ register = template.Library()
|
|||
|
||||
|
||||
@register.inclusion_tag("base/form.html")
|
||||
def form(form, **kwargs):
|
||||
def form(f, **kwargs):
|
||||
return kwargs | {
|
||||
"form": form,
|
||||
"errors": form.errors,
|
||||
"form": f,
|
||||
"errors": f.errors,
|
||||
}
|
||||
|
||||
|
||||
@register.inclusion_tag("base/inline_form.html")
|
||||
def inline_form(f, **kwargs):
|
||||
return form(f, **kwargs)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from django.contrib.auth.models import User
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic.edit import CreateView
|
||||
|
@ -10,6 +11,11 @@ from . import forms
|
|||
class HomePageView(TemplateView):
|
||||
template_name = "index.html"
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if request.user.is_authenticated:
|
||||
return redirect("home")
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
class SignupView(SuccessMessageMixin, CreateView):
|
||||
model = User
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 %}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue