mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-07-21 16:39:12 +02:00
Compare commits
2 Commits
e6839a1079
...
57f43a8700
Author | SHA1 | Date | |
---|---|---|---|
57f43a8700 | |||
a72572ded6 |
0
apps/family/api/__init__.py
Normal file
0
apps/family/api/__init__.py
Normal file
46
apps/family/api/serializers.py
Normal file
46
apps/family/api/serializers.py
Normal file
@ -0,0 +1,46 @@
|
||||
# Copyright (C) 2018-2025 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from rest_framework import serializers
|
||||
|
||||
from ..models import Family, FamilyMembership, Challenge, Achievement
|
||||
|
||||
|
||||
class FamilySerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
REST API Serializer for Family.
|
||||
The djangorestframework plugin will analyse the model `Family` and parse all fields in the API.
|
||||
"""
|
||||
class Meta:
|
||||
model = Family
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class FamilyMembershipSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
REST API Serializer for FamilyMembership.
|
||||
The djangorestframework plugin will analyse the model `FamilyMembership` and parse all fields in the API.
|
||||
"""
|
||||
class Meta:
|
||||
model = FamilyMembership
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class ChallengeSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
REST API Serializer for Challenge.
|
||||
The djangorestframework plugin will analyse the model `Challenge` and parse all fields in the API.
|
||||
"""
|
||||
class Meta:
|
||||
model = Challenge
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class AchievementSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
REST API Serializer for Achievement.
|
||||
The djangorestframework plugin will analyse the model `Achievement` and parse all fields in the API.
|
||||
"""
|
||||
class Meta:
|
||||
model = Achievement
|
||||
fields = '__all__'
|
14
apps/family/api/urls.py
Normal file
14
apps/family/api/urls.py
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (C) 2018-2025 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from .views import FamilyViewSet, FamilyMembershipViewSet, ChallengeViewSet, AchievementViewSet
|
||||
|
||||
|
||||
def register_family_urls(router, path):
|
||||
"""
|
||||
Configure router for Family REST API
|
||||
"""
|
||||
router.register(path + 'family', FamilyViewSet)
|
||||
router.register(path + 'familymembership', FamilyMembershipViewSet)
|
||||
router.register(path + 'challenge', ChallengeViewSet)
|
||||
router.register(path + 'achievement', AchievementViewSet)
|
61
apps/family/api/views.py
Normal file
61
apps/family/api/views.py
Normal file
@ -0,0 +1,61 @@
|
||||
# Copyright (C) 2018-2025 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from api.viewsets import ReadProtectedModelViewSet
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from rest_framework.filters import SearchFilter
|
||||
|
||||
from .serializers import FamilySerializer, FamilyMembershipSerializer, ChallengeSerializer, AchievementSerializer
|
||||
from ..models import Family, FamilyMembership, Challenge, Achievement
|
||||
|
||||
|
||||
class FamilyViewSet(ReadProtectedModelViewSet):
|
||||
"""
|
||||
REST API View set.
|
||||
The djangorestframework plugin will get all `Family` objects, serialize it to JSON with the given serializer,
|
||||
then render it on /api/family/family/
|
||||
"""
|
||||
queryset = Family.object.order_by('id')
|
||||
serializer_class = FamilySerializer
|
||||
filter_backends = [DjangoFilterBackend, SearchFilter]
|
||||
filterset_fields = ['name', ]
|
||||
search_fields = ['§name', ]
|
||||
|
||||
|
||||
class FamilyMembershipViewSet(ReadProtectedModelViewSet):
|
||||
"""
|
||||
REST API View set.
|
||||
The djangorestframework plugin will get all `FamilyMembership` objects, serialize it to JSON with the given serializer,
|
||||
then render it on /api/family/familymembership/
|
||||
"""
|
||||
queryset = FamilyMembership.object.order_by('id')
|
||||
serializer_class = FamilyMembershipSerializer
|
||||
filter_backends = [DjangoFilterBackend, SearchFilter]
|
||||
filterset_fields = ['name', ]
|
||||
search_fields = ['§name', ]
|
||||
|
||||
|
||||
class ChallengeViewSet(ReadProtectedModelViewSet):
|
||||
"""
|
||||
REST API View set.
|
||||
The djangorestframework plugin will get all `Challenge` objects, serialize it to JSON with the given serializer,
|
||||
then render it on /api/family/challenge/
|
||||
"""
|
||||
queryset = Challenge.object.order_by('id')
|
||||
serializer_class = ChallengeSerializer
|
||||
filter_backends = [DjangoFilterBackend, SearchFilter]
|
||||
filterset_fields = ['name', ]
|
||||
search_fields = ['§name', ]
|
||||
|
||||
|
||||
class AchievementViewSet(ReadProtectedModelViewSet):
|
||||
"""
|
||||
REST API View set.
|
||||
The djangorestframework plugin will get all `Achievement` objects, serialize it to JSON with the given serializer,
|
||||
then render it on /api/family/achievement/
|
||||
"""
|
||||
queryset = Achievement.object.order_by('id')
|
||||
serializer_class = AchievementSerializer
|
||||
filter_backends = [DjangoFilterBackend, SearchFilter]
|
||||
filterset_fields = ['name', ]
|
||||
search_fields = ['§name', ]
|
@ -1,205 +1,188 @@
|
||||
{% extends "base.html" %}
|
||||
{% comment %}
|
||||
Copyright (C) 2018-2025 by BDE ENS Paris-Saclay
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
{% endcomment %}
|
||||
{% load i18n static django_tables2 %}
|
||||
|
||||
{% block containertype %}container-fluid{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-xl-12">
|
||||
<div class="btn-group btn-group-toggle" style="width: 100%; padding: 0 0 2em 0">
|
||||
<a href="{% url "family:family_list" %}" class="btn btn-sm btn-outline-primary">
|
||||
{% trans "Families" %}
|
||||
</a>
|
||||
<a href="{% url "family:challenge_list" %}" class="btn btn-sm btn-outline-primary">
|
||||
{% trans "Challenges" %}
|
||||
</a>
|
||||
<a href="#" class="btn btn-sm btn-outline-primary active">
|
||||
{% trans "Manage" %}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class='col-sm-5 col-xl-6' id="infos_div">
|
||||
<div class="row justify-content-center justify-content-md-end">
|
||||
{# User details column #}
|
||||
<div class="col picture-col">
|
||||
<div class="card bg-light mb-4 text-center">
|
||||
<a id="profile_pic_link" href="#">
|
||||
<img src="{% static "member/img/default_picture.png" %}"
|
||||
id="profile_pic" alt="" class="card-img-top d-none d-sm-block">
|
||||
</a>
|
||||
<div class="card-body text-center text-break p-2">
|
||||
<span id="user_note"><i class="small">{% trans "Please select a family" %}</i></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Family selection column #}
|
||||
<div class="col-xl" id="user_select_div">
|
||||
<div class="card bg-light border-success mb-4">
|
||||
<div class="card-header">
|
||||
<p class="card-text font-weight-bold">
|
||||
{% trans "Families" %}
|
||||
</p>
|
||||
</div>
|
||||
<div class="card-body p-0" style="min-height:125px;">
|
||||
<ul class="list-group list-group-flush" id="note_list">
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{# User search with autocompletion #}
|
||||
<div class="card-footer">
|
||||
<input class="form-control mx-auto d-block"
|
||||
placeholder="{% trans "Name" %}" type="text" id="note" autofocus />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Summary of challenges and validate button #}
|
||||
<div class="col-xl-5" id="consos_list_div">
|
||||
<div class="card bg-light border-info mb-4">
|
||||
<div class="card-header">
|
||||
<p class="card-text font-weight-bold">
|
||||
{% trans "Challenges" %}
|
||||
</p>
|
||||
</div>
|
||||
<div class="card-body p-0" style="min-height:125px;">
|
||||
<ul class="list-group list-group-flush" id="consos_list">
|
||||
</ul>
|
||||
</div>
|
||||
<div class="card-footer text-center">
|
||||
<span id="consume_all" class="btn btn-primary">
|
||||
{% trans "Validate!" %}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{# Create family/challenge buttons #}
|
||||
<div class="card bg-light border-success mb-4">
|
||||
<h3 class="card-header">
|
||||
<p class="card-text font-weight-bold">
|
||||
{% trans "Create a family or challenge" %}
|
||||
</p>
|
||||
</h3>
|
||||
<div class="card-body">
|
||||
{% if can_add_family %}
|
||||
<a class="btn btn-sm btn-primary" href="{% url "family:add_family" %}">
|
||||
{% trans "Add a family" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if can_add_challenge %}
|
||||
<a class="btn btn-sm btn-primary" href="{% url "family:add_challenge" %}">
|
||||
{% trans "Add a challenge" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{# Buttons column #}
|
||||
<div class="col">
|
||||
{# Regroup buttons under categories #}
|
||||
|
||||
<div class="card bg-light border-primary text-center mb-4">
|
||||
{# Tabs for list and search #}
|
||||
<div class="card-header">
|
||||
<ul class="nav nav-tabs nav-fill card-header-tabs">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link font-weight-bold" data-toggle="tab" href="#list">
|
||||
{% trans "List" %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link font-weight-bold" data-toggle="tab" href="#search">
|
||||
{% trans "Search" %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{# Tabs content #}
|
||||
<div class="card-body">
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane" id="list">
|
||||
<div class="d-inline-flex flex-wrap justify-content-center">
|
||||
{% for challenge in all_challenges %}
|
||||
<button class="btn btn-outline-dark rounded-0 flex-fill"
|
||||
id="challenge{{ challenge.id }}" name="button" value="{{ challenge.name }}">
|
||||
{{ challenge.name }} ({{ challenge.points }} {% trans "points" %})
|
||||
</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane" id="search">
|
||||
<input class="form-control mx-auto d-block mb-3"
|
||||
placeholder="{% trans "Search challenge..." %}" type="search" id="search-input"/>
|
||||
<div class="d-inline-flex flex-wrap justify-content-center" id="search-results">
|
||||
{% for challenge in all_challenges %}
|
||||
<button class="btn btn-outline-dark rounded-0 flex-fill" hidden
|
||||
id="search_challenge{{ challenge.id }}" name="button" value="{{ challenge.name }}">
|
||||
{{ challenge.name }} ({{ challenge.points }} {% trans "points" %})
|
||||
</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Mode switch #}
|
||||
<div class="card-footer border-primary">
|
||||
<a class="btn btn-sm btn-secondary float-left" href="{% url 'note:template_list' %}">
|
||||
<i class="fa fa-edit"></i> {% trans "Edit" %}
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{# transaction history #}
|
||||
<div class="card mb-4" id="history">
|
||||
<div class="card-header">
|
||||
<p class="card-text font-weight-bold">
|
||||
{% trans "Recent achievements history" %}
|
||||
</p>
|
||||
</div>
|
||||
{% render_table table %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
||||
{% block extrajavascript %}
|
||||
<script type="text/javascript" src="{% static "family/js/consos.js" %}"></script>
|
||||
<script type="text/javascript">
|
||||
{% for button in all_challenges %}
|
||||
document.getElementById("button{{ button.id }}").addEventListener("click", function() {
|
||||
addConso({{ button.destination_id }}, {{ button.amount }},
|
||||
{{ polymorphic_ctype }}, {{ button.category_id }}, "{{ button.category.name|escapejs }}",
|
||||
{{ button.id }}, "{{ button.name|escapejs }}");
|
||||
});
|
||||
{% endfor %}
|
||||
|
||||
{% for button in all_challenges %}
|
||||
{% if button.display %}
|
||||
document.getElementById("search_button{{ button.id }}").addEventListener("click", function() {
|
||||
addConso({{ button.destination_id }}, {{ button.amount }},
|
||||
{{ polymorphic_ctype }}, {{ button.category_id }}, "{{ button.category.name|escapejs }}",
|
||||
{{ button.id }}, "{{ button.name|escapejs }}");
|
||||
});
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</script>
|
||||
{% extends "base.html" %}
|
||||
{% comment %}
|
||||
Copyright (C) 2018-2025 by BDE ENS Paris-Saclay
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
{% endcomment %}
|
||||
{% load i18n static django_tables2 %}
|
||||
|
||||
{% block containertype %}container-fluid{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-xl-12">
|
||||
<div class="btn-group btn-group-toggle" style="width: 100%; padding: 0 0 2em 0">
|
||||
<a href="{% url "family:family_list" %}" class="btn btn-sm btn-outline-primary">
|
||||
{% trans "Families" %}
|
||||
</a>
|
||||
<a href="{% url "family:challenge_list" %}" class="btn btn-sm btn-outline-primary">
|
||||
{% trans "Challenges" %}
|
||||
</a>
|
||||
<a href="#" class="btn btn-sm btn-outline-primary active">
|
||||
{% trans "Manage" %}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-sm-5 col-xl-6" id="infos_div">
|
||||
<div class="row justify-content-center justify-content-md-end">
|
||||
{# User details column #}
|
||||
<div class="col picture-col">
|
||||
<div class="card bg-light mb-4 text-center">
|
||||
<a id="profile_pic_link" href="#">
|
||||
<img src="{% static "member/img/default_picture.png" %}" id="profile_pic" alt="" class="card-img-top d-none d-sm-block">
|
||||
</a>
|
||||
<div class="card-body text-center text-break p-2">
|
||||
<span id="user_note"><i class="small">{% trans "Please select a family" %}</i></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Family selection column #}
|
||||
<div class="col-xl" id="user_select_div">
|
||||
<div class="card bg-light border-success mb-4">
|
||||
<div class="card-header">
|
||||
<p class="card-text font-weight-bold">
|
||||
{% trans "Families" %}
|
||||
</p>
|
||||
</div>
|
||||
<div class="card-body p-0" style="min-height:125px;">
|
||||
<ul class="list-group list-group-flush" id="note_list"></ul>
|
||||
</div>
|
||||
{# User search with autocompletion #}
|
||||
<div class="card-footer">
|
||||
<input class="form-control mx-auto d-block" placeholder="{% trans "Name" %}" type="text" id="note" autofocus />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Summary of challenges and validate button #}
|
||||
<div class="col-xl-5" id="consos_list_div">
|
||||
<div class="card bg-light border-info mb-4">
|
||||
<div class="card-header">
|
||||
<p class="card-text font-weight-bold">
|
||||
{% trans "Challenges" %}
|
||||
</p>
|
||||
</div>
|
||||
<div class="card-body p-0" style="min-height:125px;">
|
||||
<ul class="list-group list-group-flush" id="consos_list"></ul>
|
||||
</div>
|
||||
<div class="card-footer text-center">
|
||||
<span id="consume_all" class="btn btn-primary">
|
||||
{% trans "Validate!" %}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Create family/challenge buttons #}
|
||||
<div class="card bg-light border-success mb-4">
|
||||
<h3 class="card-header font-weight-bold text-center">
|
||||
{% trans "Create a family or challenge" %}
|
||||
</h3>
|
||||
<div class="card-body text-center">
|
||||
{% if can_add_family %}
|
||||
<a class="btn btn-sm btn-primary mx-2" href="{% url 'family:add_family' %}">
|
||||
{% trans "Add a family" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if can_add_challenge %}
|
||||
<a class="btn btn-sm btn-primary mx-2" href="{% url 'family:add_challenge' %}">
|
||||
{% trans "Add a challenge" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Buttons column #}
|
||||
<div class="col">
|
||||
<div class="card bg-light border-primary text-center mb-4">
|
||||
{# Tabs for list and search #}
|
||||
<div class="card-header">
|
||||
<ul class="nav nav-tabs nav-fill card-header-tabs">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link font-weight-bold" data-toggle="tab" href="#list">
|
||||
{% trans "List" %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link font-weight-bold" data-toggle="tab" href="#search">
|
||||
{% trans "Search" %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{# Tabs content #}
|
||||
<div class="card-body">
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane" id="list">
|
||||
<div class="d-inline-flex flex-wrap justify-content-center">
|
||||
{% for challenge in all_challenges %}
|
||||
<button class="btn btn-outline-dark rounded-0 flex-fill"
|
||||
id="challenge{{ challenge.id }}" name="button" value="{{ challenge.name }}">
|
||||
{{ challenge.name }} ({{ challenge.points }} {% trans "points" %})
|
||||
</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane" id="search">
|
||||
<input class="form-control mx-auto d-block mb-3" placeholder="{% trans "Search challenge..." %}" type="search" id="search-input"/>
|
||||
<div class="d-inline-flex flex-wrap justify-content-center" id="search-results">
|
||||
{% for challenge in all_challenges %}
|
||||
<button class="btn btn-outline-dark rounded-0 flex-fill" hidden
|
||||
id="search_challenge{{ challenge.id }}" name="button" value="{{ challenge.name }}">
|
||||
{{ challenge.name }} ({{ challenge.points }} {% trans "points" %})
|
||||
</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Mode switch #}
|
||||
<div class="card-footer border-primary">
|
||||
<a class="btn btn-sm btn-secondary float-left" href="{% url 'note:template_list' %}">
|
||||
<i class="fa fa-edit"></i> {% trans "Edit" %}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# transaction history #}
|
||||
<div class="card mb-4" id="history">
|
||||
<div class="card-header">
|
||||
<p class="card-text font-weight-bold">
|
||||
{% trans "Recent achievements history" %}
|
||||
</p>
|
||||
</div>
|
||||
{% render_table table %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extrajavascript %}
|
||||
<script type="text/javascript" src="{% static "family/js/consos.js" %}"></script>
|
||||
<script type="text/javascript">
|
||||
{% for button in all_challenges %}
|
||||
document.getElementById("button{{ button.id }}").addEventListener("click", function() {
|
||||
addConso({{ button.destination_id }}, {{ button.amount }},
|
||||
{{ polymorphic_ctype }}, {{ button.category_id }}, "{{ button.category.name|escapejs }}",
|
||||
{{ button.id }}, "{{ button.name|escapejs }}");
|
||||
});
|
||||
{% endfor %}
|
||||
|
||||
{% for button in all_challenges %}
|
||||
{% if button.display %}
|
||||
document.getElementById("search_button{{ button.id }}").addEventListener("click", function() {
|
||||
addConso({{ button.destination_id }}, {{ button.amount }},
|
||||
{{ polymorphic_ctype }}, {{ button.category_id }}, "{{ button.category.name|escapejs }}",
|
||||
{{ button.id }}, "{{ button.name|escapejs }}");
|
||||
});
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</script>
|
||||
{% endblock %}
|
Reference in New Issue
Block a user