[chronojump-server] Modified group columns data output method and implemented gyms_list page
- From: Max Ros i Morejon <maxros src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump-server] Modified group columns data output method and implemented gyms_list page
- Date: Thu, 27 Jun 2019 10:22:39 +0000 (UTC)
commit 6321a06427c772bdb1072632f721b8df3f470402
Author: Max Ros i Morejon <mros33 gmail com>
Date: Thu Jun 27 12:22:30 2019 +0200
Modified group columns data output method and implemented gyms_list page
.../organizations/api/serializers.py | 23 +++--
.../chronojump_networks/organizations/api/urls.py | 5 +
.../chronojump_networks/organizations/api/views.py | 31 ++++--
.../organizations/groups/groups_list.html | 20 ++--
.../templates/organizations/gyms/gyms_list.html | 112 +++++++++++++++++++++
5 files changed, 171 insertions(+), 20 deletions(-)
---
diff --git a/chronojumpserver-django/chronojump_networks/organizations/api/serializers.py
b/chronojumpserver-django/chronojump_networks/organizations/api/serializers.py
index 4faaa2d..f2711bc 100644
--- a/chronojumpserver-django/chronojump_networks/organizations/api/serializers.py
+++ b/chronojumpserver-django/chronojump_networks/organizations/api/serializers.py
@@ -4,22 +4,35 @@ from ..models import Player, Station, Exercise, Gym, Group, User
from chronojump_networks.tasks.api.serializers import PlayerTaskSerializer
+class UserSerializer(serializers.ModelSerializer):
+ class Meta:
+ model = User
+ fields = [ 'id', 'name']
+
class PlayerSerializer(serializers.ModelSerializer):
player_tasks = PlayerTaskSerializer(many=True)
class Meta:
model = Player
fields = [ 'id', 'name', 'number', 'height', 'weight', 'imageName', 'player_tasks', 'rfid']
-class GymSerializer(serializers.ModelSerializer):
+class GymTableSerializer(serializers.ModelSerializer):
+ responsible = UserSerializer(many=False)
class Meta:
model = Gym
- field = [ 'id', 'name', 'responsible']
+ fields = [ 'id', 'name', 'responsible']
class GroupSerializer(serializers.ModelSerializer):
class Meta:
model = Group
fields = [ 'id', 'name', 'gym', 'responsible' ]
-
+
+class GroupTableSerializer(serializers.ModelSerializer):
+ gym = GymTableSerializer(many=False)
+ responsible = UserSerializer(many=False)
+ class Meta:
+ model = Group
+ fields = [ 'id', 'name', 'gym', 'responsible' ]
+
class StationSerializer(serializers.ModelSerializer):
class Meta:
model = Station
@@ -37,7 +50,3 @@ class GymStationsSerializer(serializers.ModelSerializer):
model = Station
fields = [ 'id', 'name', 'type', 'exercises']
-class UserSerializer(serializers.ModelSerializer):
- class Meta:
- model = User
- fields = [ 'id', 'name']
diff --git a/chronojumpserver-django/chronojump_networks/organizations/api/urls.py
b/chronojumpserver-django/chronojump_networks/organizations/api/urls.py
index b1cd9dc..72087bc 100644
--- a/chronojumpserver-django/chronojump_networks/organizations/api/urls.py
+++ b/chronojumpserver-django/chronojump_networks/organizations/api/urls.py
@@ -31,6 +31,11 @@ urlpatterns = [
view=views.GroupListView.as_view(),
name='groups_list'
),
+ url(
+ regex=r'^(?P<organization_id>\d+)/gyms/$',
+ view=views.GymListView.as_view(),
+ name='gyms_list'
+ ),
url(
regex=r'^(?P<organization_id>\d+)/gym_stations/$',
view=views.GymStationsListView.as_view(),
diff --git a/chronojumpserver-django/chronojump_networks/organizations/api/views.py
b/chronojumpserver-django/chronojump_networks/organizations/api/views.py
index efe7544..8565b83 100644
--- a/chronojumpserver-django/chronojump_networks/organizations/api/views.py
+++ b/chronojumpserver-django/chronojump_networks/organizations/api/views.py
@@ -2,7 +2,7 @@ import os
import subprocess
from ..models import Player, GroupPlayer, Group, Station, Gym, Exercise, RFIDHistory, OrganizationStaff, User
from ..decorators import check_user_organization
-from .serializers import PlayerSerializer, StationSerializer, ExerciseSerializer, GymStationsSerializer,
GroupSerializer, UserSerializer
+from .serializers import PlayerSerializer, StationSerializer, ExerciseSerializer, GymStationsSerializer,
GroupSerializer, GroupTableSerializer, UserSerializer, GymTableSerializer
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
@@ -102,11 +102,8 @@ class UsersListView(ListAPIView):
def list(self, request, *args, **kwargs):
# Get as dictionary the data given from ajax
organization_id = int(self.kwargs['organization_id'])
- print(organization_id)
staff = OrganizationStaff.objects.filter(organization_id=organization_id)
staff = [s.user_id for s in staff]
- print("id: ")
- print(staff)
queryset = User.objects.filter(id__in = staff)
serializer = UserSerializer(queryset, many=True)
return Response(serializer.data)
@@ -234,11 +231,19 @@ class PlayerListView(ListCreateAPIView):
class GroupListView(ListCreateAPIView):
"""Groups of the organization"""
permission_classes = (IsAuthenticated, )
- serializer_class = GroupSerializer
+ serializer_class = GroupTableSerializer
def get_queryset(self):
organization_id = int(self.kwargs['organization_id'])
- return Group.objects.filter(organization_id=organization_id)
+ groups = Group.objects.filter(organization_id=organization_id)
+ for group in groups:
+ resp = User.objects.filter(id__exact = group.responsible.id)
+ resp_n = [r.name for r in resp]
+ setattr(group, 'responsible_name', resp_n[0])
+ gym = Gym.objects.filter(id__exact = group.gym.id)
+ gym_n = [g.name for g in gym]
+ setattr(group, 'gym_name', gym_n[0])
+ return groups
def create(self, request, *args, **kwargs):
print("crea group")
@@ -275,6 +280,20 @@ class GroupListView(ListCreateAPIView):
print("Removed group %d" % (int(group_id)))
return JsonResponse({}, status=204, safe=False)
+class GymListView(ListCreateAPIView):
+ """Gyms of the organization"""
+ permission_classes = (IsAuthenticated, )
+ serializer_class = GymTableSerializer
+
+ def get_queryset(self):
+ organization_id = int(self.kwargs['organization_id'])
+ gyms = Gym.objects.filter(organization_id=organization_id)
+ for gym in gyms:
+ resp = User.objects.filter(id__exact = gym.responsible.id)
+ resp_n = [r.name for r in resp]
+ setattr(gym, 'responsible_name', resp_n[0])
+ return gyms
+
def register_rfid(request):
"""Call an external program to read rfid and return the value read."""
diff --git a/chronojumpserver-django/chronojump_networks/templates/organizations/groups/groups_list.html
b/chronojumpserver-django/chronojump_networks/templates/organizations/groups/groups_list.html
index cbcd89d..e8e3d0f 100644
--- a/chronojumpserver-django/chronojump_networks/templates/organizations/groups/groups_list.html
+++ b/chronojumpserver-django/chronojump_networks/templates/organizations/groups/groups_list.html
@@ -84,11 +84,19 @@
title: "{% trans 'Group name' %}",
},
{
- "data": "responsible",
+ "data": "responsible.id",
+ "visible": false
+ },
+ {
+ "data": "responsible.name",
title: "{% trans 'Responsible' %}"
},
{
- "data": "gym",
+ "data": "gym.id",
+ "visible": false
+ },
+ {
+ "data": "gym.name",
title: "{% trans 'Gym' %}"
},
{% if user.is_staff %}
@@ -146,7 +154,7 @@
},
"language": {
"lengthMenu": "{% trans 'Showing _MENU_ groups per page' %}",
- "zeroRecords": "{% trans 'There are no groups in this group' %}",
+ "zeroRecords": "{% trans 'There are no groups in this organization' %}",
"info": "{% trans 'Showing the groups _START_ to _END_ of a total of _TOTAL_ groups' %}",
"infoEmpty": "{% trans 'The search returns no results' %}",
"infoFiltered": "{% trans '(from a total of _MAX_ groups)' %}",
@@ -260,12 +268,10 @@
// Get all the values in the form into json object
function serializeGroup() {
- console.log("id = " + $('#groupId').val());
let group_id = $('#groupId').val();
let group_name = $('#name').val();
let group_gym = $('#gymSelect').val();
let group_responsible = $('#respSelect').val();
- console.log("resp: " + $('#respSelect').val());
var group = {
'id': group_id,
'name': group_name,
@@ -281,8 +287,8 @@
console.log(group);
$('#groupId').val(group.id);
$('#name').val(group.name);
- $('#gymSelect').val(group.gym);
- $('#respSelect').val(group.responsible);
+ $('#gymSelect').val(group.gym.id);
+ $('#respSelect').val(group.responsible.id);
}
function putGroup(group) {
diff --git a/chronojumpserver-django/chronojump_networks/templates/organizations/gyms/gyms_list.html
b/chronojumpserver-django/chronojump_networks/templates/organizations/gyms/gyms_list.html
new file mode 100644
index 0000000..f3a0d94
--- /dev/null
+++ b/chronojumpserver-django/chronojump_networks/templates/organizations/gyms/gyms_list.html
@@ -0,0 +1,112 @@
+{% extends 'layout.html' %}
+{% load static i18n %}
+
+{% block title %}Chronojump Networks | {{user.organization.name}} | {{group.name}}{% endblock %}
+
+{% block css %}
+{{ block.super }}
+<link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/dataTables.bootstrap4.min.css">
+<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.5.1/css/buttons.bootstrap4.min.css">
+<!--<link rel="stylesheet"
href="https://cdn.datatables.net/fixedcolumns/3.2.4/css/fixedColumns.bootstrap4.min.css">-->
+
+{% endblock %}
+
+{% block content %}
+{% csrf_token %}
+
+<div class="page-header row">
+ <div class="col-sm-9">
+ {% if user.organization.image %}
+ <img src="{{MEDIA_URL}}{{ user.organization.image }}" class="img-fluid float-left" width="48px"
height="48px" style="margin-top:12px;margin-right:10px;" />
+ {% else %}
+ <img src="{% static 'images/logo_club.png' %}" class="img-fluid float-left" width="48px"
height="48px" style="margin-top:12px;margin-right:10px;" />
+ {% endif %}
+ <h1 class="display-4">{% trans 'Gyms list' %}</h1>
+ </div>
+
+</div>
+
+<div class="row datatables_wrapped">
+ <div class="col">
+ <table id="gyms" cellspacing="0" cellpadding="0" class="table table-sm" style="width:100%">
+ </table>
+ </div>
+</div>
+
+{% endblock %}
+
+{% block javascript %}
+{{ block.super }}
+<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
+<script src="https://cdn.datatables.net/1.10.16/js/dataTables.bootstrap4.min.js"></script>
+<script src="https://cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js"></script>
+<script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.bootstrap4.min.js"></script>
+<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
+<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script>
+<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script>
+<script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.print.min.js"></script>-->
+<script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.html5.min.js"></script>
+<!--<script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.colVis.min.js"></script>
+<script src="https://cdn.datatables.net/fixedcolumns/3.2.4/js/dataTables.fixedColumns.min.js"></script>-->
+<script>
+ var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();
+
+ $(document).ready(function() {
+ /* Datatable for groups */
+ var table_gyms = $('#gyms').DataTable({
+ lengthChange: false,
+ "ajax": {
+ "processing": true,
+ "url" : "{% url 'api_organizations:gyms_list' organization_id=user.organization.id %}",
+ "dataSrc": ""
+ },
+ "order": [
+ [2, 'asc'],
+ [3, 'asc']
+ ],
+ "columns": [
+ {
+ type: "html",
+ orderable:false,
+ render: function(value, type, row) {
+ return '<input class="selectGymCheckbox" type="checkbox" data-gym-id="' + row.id + '"
style=" visibility: hidden"/>';
+ }
+ },
+ {
+ "data": "name",
+ title: "{% trans 'Gym name' %}",
+ },
+ {
+ "data": "responsible.id",
+ "visible": false
+ },
+ {
+ "data": "responsible.name",
+ title: "{% trans 'Responsible' %}"
+ }
+ ],
+ initComplete: function() {
+ // Enable the remove group selection the first time data is loaded
+ enableGroupsTableFunctionality(); //TODO: CHECK if this is needed and implemented
+ },
+ "language": {
+ "lengthMenu": "{% trans 'Showing _MENU_ gyms per page' %}",
+ "zeroRecords": "{% trans 'There are no gyms in this organization with these parameters' %}",
+ "info": "{% trans 'Showing the gyms _START_ to _END_ of a total of _TOTAL_ gyms' %}",
+ "infoEmpty": "{% trans 'The search returns no results' %}",
+ "infoFiltered": "{% trans '(from a total of _MAX_ gyms)' %}",
+ "decimal": ",",
+ "thousands": ".",
+ "paginate": {
+ "first": '<i class="fa fa-fast-backward"></i>',
+ "last": '<i class="fa fa-fast-forward"></i>',
+ "next": '<i class="fa fa-forward"></i>',
+ "previous": '<i class="fa fa-backward"></i>'
+ },
+ "search": "{% trans 'Search:' %}"
+ }
+ });
+
+ });
+</script>
+{% endblock %}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]