mirror of
https://github.com/ae-utbm/sith.git
synced 2025-06-29 14:45:17 +00:00
room management views
This commit is contained in:
parent
a8c6cc29f5
commit
79fc6e3859
@ -1,25 +1,61 @@
|
|||||||
{% extends "core/base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
|
{% from "reservation/macros.jinja" import room_detail %}
|
||||||
|
|
||||||
|
{% block additional_css %}
|
||||||
|
<link rel="stylesheet" href="{{ static("core/components/card.scss") }}">
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h3>{% trans %}Club tools{% endtrans %}</h3>
|
<h3>{% trans %}Club tools{% endtrans %} ({{ club.name }})</h3>
|
||||||
<div>
|
<div>
|
||||||
<h4>{% trans %}Communication:{% endtrans %}</h4>
|
<h4>{% trans %}Communication:{% endtrans %}</h4>
|
||||||
<ul>
|
<ul>
|
||||||
<li> <a href="{{ url('com:news_new') }}?club={{ object.id }}">{% trans %}Create a news{% endtrans %}</a></li>
|
<li>
|
||||||
<li> <a href="{{ url('com:weekmail_article') }}?club={{ object.id }}">{% trans %}Post in the Weekmail{% endtrans %}</a></li>
|
<a href="{{ url('com:news_new') }}?club={{ object.id }}">
|
||||||
|
{% trans %}Create a news{% endtrans %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{ url('com:weekmail_article') }}?club={{ object.id }}">
|
||||||
|
{% trans %}Post in the Weekmail{% endtrans %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
{% if object.trombi %}
|
{% if object.trombi %}
|
||||||
<li> <a href="{{ url('trombi:detail', trombi_id=object.trombi.id) }}">{% trans %}Edit Trombi{% endtrans %}</a></li>
|
<li>
|
||||||
|
<a href="{{ url('trombi:detail', trombi_id=object.trombi.id) }}">
|
||||||
|
{% trans %}Edit Trombi{% endtrans %}</a>
|
||||||
|
</li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li> <a href="{{ url('trombi:create', club_id=object.id) }}">{% trans %}New Trombi{% endtrans %}</a></li>
|
<li><a href="{{ url('trombi:create', club_id=object.id) }}">{% trans %}New Trombi{% endtrans %}</a></li>
|
||||||
<li> <a href="{{ url('club:poster_list', club_id=object.id) }}">{% trans %}Posters{% endtrans %}</a></li>
|
<li><a href="{{ url('club:poster_list', club_id=object.id) }}">{% trans %}Posters{% endtrans %}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
|
<h4>{% trans %}Reservable rooms{% endtrans %}</h4>
|
||||||
|
<a
|
||||||
|
href="{{ url("reservation:room_create") }}?club={{ object.id }}"
|
||||||
|
class="btn btn-blue"
|
||||||
|
>
|
||||||
|
{% trans %}Add a room{% endtrans %}
|
||||||
|
</a>
|
||||||
|
{%- if reservable_rooms|length > 0 -%}
|
||||||
|
<ul class="card-group">
|
||||||
|
{%- for room in reservable_rooms -%}
|
||||||
|
{{ room_detail(
|
||||||
|
room,
|
||||||
|
can_edit=user.can_edit(room),
|
||||||
|
can_delete=request.user.has_perm("reservation.delete_room")
|
||||||
|
) }}
|
||||||
|
{%- endfor -%}
|
||||||
|
</ul>
|
||||||
|
{%- else -%}
|
||||||
|
{% trans %}This club manages no reservable room{% endtrans %}
|
||||||
|
{%- endif -%}
|
||||||
<h4>{% trans %}Counters:{% endtrans %}</h4>
|
<h4>{% trans %}Counters:{% endtrans %}</h4>
|
||||||
<ul>
|
<ul>
|
||||||
{% for c in object.counters.filter(type="OFFICE") %}
|
{% for counter in counters %}
|
||||||
<li>{{ c }}:
|
<li>{{ counter }}:
|
||||||
<a href="{{ url('counter:details', counter_id=c.id) }}">View</a>
|
<a href="{{ url('counter:details', counter_id=counter.id) }}">View</a>
|
||||||
<a href="{{ url('counter:admin', counter_id=c.id) }}">Edit</a>
|
<a href="{{ url('counter:admin', counter_id=counter.id) }}">Edit</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -241,6 +241,12 @@ class ClubToolsView(ClubTabsMixin, CanEditMixin, DetailView):
|
|||||||
template_name = "club/club_tools.jinja"
|
template_name = "club/club_tools.jinja"
|
||||||
current_tab = "tools"
|
current_tab = "tools"
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
return super().get_context_data(**kwargs) | {
|
||||||
|
"reservable_rooms": list(self.object.reservable_rooms.all()),
|
||||||
|
"counters": list(self.object.counters.filter(type="OFFICE")),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class ClubMembersView(ClubTabsMixin, CanViewMixin, DetailFormView):
|
class ClubMembersView(ClubTabsMixin, CanViewMixin, DetailFormView):
|
||||||
"""View of a club's members."""
|
"""View of a club's members."""
|
||||||
|
@ -16,6 +16,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.card-group {
|
||||||
|
display: flex;
|
||||||
|
gap: 15px;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
.card {
|
.card {
|
||||||
background-color: $primary-neutral-light-color;
|
background-color: $primary-neutral-light-color;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
@ -92,13 +99,23 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 765px) {
|
@media screen and (max-width: 765px) {
|
||||||
@include row-layout
|
@include row-layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When combined with card, card-row display the card in a row layout,
|
// When combined with card, card-row display the card in a row layout,
|
||||||
// whatever the size of the screen.
|
// whatever the size of the screen.
|
||||||
&.card-row {
|
&.card-row {
|
||||||
@include row-layout
|
@include row-layout;
|
||||||
|
|
||||||
|
&.card-row-m {
|
||||||
|
//width: 50%;
|
||||||
|
max-width: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.card-row-s {
|
||||||
|
//width: 33%;
|
||||||
|
max-width: 33%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
33
reservation/forms.py
Normal file
33
reservation/forms.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
from django import forms
|
||||||
|
|
||||||
|
from club.widgets.ajax_select import AutoCompleteSelectClub
|
||||||
|
from core.models import User
|
||||||
|
from reservation.models import Room
|
||||||
|
|
||||||
|
|
||||||
|
class RoomCreateForm(forms.ModelForm):
|
||||||
|
required_css_class = "required"
|
||||||
|
error_css_class = "error"
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Room
|
||||||
|
fields = ["name", "club", "location", "description"]
|
||||||
|
widgets = {"club": AutoCompleteSelectClub}
|
||||||
|
|
||||||
|
|
||||||
|
class RoomUpdateForm(forms.ModelForm):
|
||||||
|
required_css_class = "required"
|
||||||
|
error_css_class = "error"
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Room
|
||||||
|
fields = ["name", "club", "location", "description"]
|
||||||
|
widgets = {"club": AutoCompleteSelectClub}
|
||||||
|
|
||||||
|
def __init__(self, *args, request_user: User, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
if not request_user.has_perm("reservation.change_room"):
|
||||||
|
# if the user doesn't have the global edition permission
|
||||||
|
# (i.e. it's a club board member, but not a sith admin)
|
||||||
|
# some fields aren't editable
|
||||||
|
del self.fields["club"]
|
27
reservation/templates/reservation/macros.jinja
Normal file
27
reservation/templates/reservation/macros.jinja
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{% macro room_detail(room, can_edit, can_delete) %}
|
||||||
|
<div class="card card-row card-row-m">
|
||||||
|
<div class="card-content">
|
||||||
|
<strong class="card-title">{{ room.name }}</strong>
|
||||||
|
<em>{{ room.get_location_display() }}</em>
|
||||||
|
<p>{{ room.description|truncate(250) }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="card-top-left">
|
||||||
|
{% if can_edit %}
|
||||||
|
<a
|
||||||
|
class="btn btn-grey btn-no-text"
|
||||||
|
href="{{ url("reservation:room_edit", room_id=room.id) }}"
|
||||||
|
>
|
||||||
|
<i class="fa fa-edit"></i>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if can_delete %}
|
||||||
|
<a
|
||||||
|
class="btn btn-red btn-no-text"
|
||||||
|
href="{{ url("reservation:room_delete", room_id=room.id) }}"
|
||||||
|
>
|
||||||
|
<i class="fa fa-trash"></i>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endmacro %}
|
13
reservation/urls.py
Normal file
13
reservation/urls.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from reservation.views import (
|
||||||
|
RoomCreateView,
|
||||||
|
RoomDeleteView,
|
||||||
|
RoomUpdateView,
|
||||||
|
)
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path("room/create/", RoomCreateView.as_view(), name="room_create"),
|
||||||
|
path("room/<int:room_id>/edit", RoomUpdateView.as_view(), name="room_edit"),
|
||||||
|
path("room/<int:room_id>/delete", RoomDeleteView.as_view(), name="room_delete"),
|
||||||
|
]
|
@ -1 +1,51 @@
|
|||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
|
from django.contrib.messages.views import SuccessMessageMixin
|
||||||
|
from django.urls import reverse_lazy
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django.views.generic import CreateView, DeleteView, TemplateView, UpdateView
|
||||||
|
|
||||||
|
from club.models import Club
|
||||||
|
from core.auth.mixins import CanEditMixin
|
||||||
|
from core.views import UseFragmentsMixin
|
||||||
|
from core.views.mixins import FragmentMixin
|
||||||
|
from reservation.forms import ReservationForm, RoomCreateForm, RoomUpdateForm
|
||||||
|
from reservation.models import ReservationSlot, Room
|
||||||
|
|
||||||
|
|
||||||
|
class RoomCreateView(SuccessMessageMixin, PermissionRequiredMixin, CreateView):
|
||||||
|
form_class = RoomCreateForm
|
||||||
|
template_name = "core/create.jinja"
|
||||||
|
success_message = _("%(name)s was created successfully")
|
||||||
|
permission_required = "reservation.add_room"
|
||||||
|
|
||||||
|
def get_initial(self):
|
||||||
|
init = super().get_initial()
|
||||||
|
if "club" in self.request.GET:
|
||||||
|
club_id = self.request.GET["club"]
|
||||||
|
if club_id.isdigit() and int(club_id) > 0:
|
||||||
|
init["club"] = Club.objects.filter(id=int(club_id)).first()
|
||||||
|
return init
|
||||||
|
|
||||||
|
|
||||||
|
class RoomUpdateView(SuccessMessageMixin, CanEditMixin, UpdateView):
|
||||||
|
model = Room
|
||||||
|
pk_url_kwarg = "room_id"
|
||||||
|
form_class = RoomUpdateForm
|
||||||
|
template_name = "core/edit.jinja"
|
||||||
|
success_message = _("%(name)s was updated successfully")
|
||||||
|
|
||||||
|
def get_form_kwargs(self):
|
||||||
|
return super().get_form_kwargs() | {"request_user": self.request.user}
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return self.request.path
|
||||||
|
|
||||||
|
|
||||||
|
class RoomDeleteView(PermissionRequiredMixin, DeleteView):
|
||||||
|
model = Room
|
||||||
|
pk_url_kwarg = "room_id"
|
||||||
|
template_name = "core/delete_confirm.jinja"
|
||||||
|
success_url = reverse_lazy("reservation:room_list")
|
||||||
|
permission_required = "reservation.delete_room"
|
||||||
|
@ -274,7 +274,7 @@ LOGGING = {
|
|||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/1.8/topics/i18n/
|
# https://docs.djangoproject.com/en/1.8/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = "fr-FR"
|
LANGUAGE_CODE = "fr"
|
||||||
|
|
||||||
LANGUAGES = [("en", _("English")), ("fr", _("French"))]
|
LANGUAGES = [("en", _("English")), ("fr", _("French"))]
|
||||||
|
|
||||||
|
@ -45,6 +45,10 @@ urlpatterns = [
|
|||||||
path("trombi/", include(("trombi.urls", "trombi"), namespace="trombi")),
|
path("trombi/", include(("trombi.urls", "trombi"), namespace="trombi")),
|
||||||
path("matmatronch/", include(("matmat.urls", "matmat"), namespace="matmat")),
|
path("matmatronch/", include(("matmat.urls", "matmat"), namespace="matmat")),
|
||||||
path("pedagogy/", include(("pedagogy.urls", "pedagogy"), namespace="pedagogy")),
|
path("pedagogy/", include(("pedagogy.urls", "pedagogy"), namespace="pedagogy")),
|
||||||
|
path(
|
||||||
|
"reservation/",
|
||||||
|
include(("reservation.urls", "reservation"), namespace="reservation"),
|
||||||
|
),
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
path("i18n/", include("django.conf.urls.i18n")),
|
path("i18n/", include("django.conf.urls.i18n")),
|
||||||
path("jsi18n/", JavaScriptCatalog.as_view(), name="javascript-catalog"),
|
path("jsi18n/", JavaScriptCatalog.as_view(), name="javascript-catalog"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user