nice
This commit is contained in:
parent
78ec41ccb0
commit
710459848b
@ -6,7 +6,6 @@ from .views import (
|
||||
TimeEntryDetailView,
|
||||
TimeEntryUpdateView,
|
||||
WeeklySummaryView,
|
||||
DebugDatabaseView
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
@ -17,5 +16,4 @@ urlpatterns = [
|
||||
path('entries/<int:entry_id>/update/', TimeEntryUpdateView.as_view(), name='time-entry-update'),
|
||||
path('weekly-summary/', WeeklySummaryView.as_view(), name='user-weekly-summary'),
|
||||
path('weekly-summary/<int:user_id>/', WeeklySummaryView.as_view(), name='weekly-summary'),
|
||||
path('debug-database/', DebugDatabaseView.as_view()),
|
||||
]
|
||||
@ -3,7 +3,7 @@ from rest_framework.response import Response
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.views import APIView
|
||||
from django.conf import settings
|
||||
from django.db import transaction, connection
|
||||
from django.db import transaction
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
from datetime import time as datetime_time
|
||||
@ -15,89 +15,6 @@ from .serializers import (
|
||||
TimeEntryUpdateSerializer,
|
||||
WeeklySummarySerializer
|
||||
)
|
||||
|
||||
class DebugDatabaseView(APIView):
|
||||
permission_classes = []
|
||||
|
||||
def get(self, request):
|
||||
with connection.cursor() as cursor:
|
||||
|
||||
# Vérifie vers quelle table la FK de TimeEntry pointe réellement
|
||||
cursor.execute("""
|
||||
SELECT
|
||||
CONSTRAINT_NAME,
|
||||
COLUMN_NAME,
|
||||
REFERENCED_TABLE_NAME,
|
||||
REFERENCED_COLUMN_NAME
|
||||
FROM information_schema.KEY_COLUMN_USAGE
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'time_tracking_timeentry'
|
||||
AND COLUMN_NAME = 'user_id'
|
||||
AND REFERENCED_TABLE_NAME IS NOT NULL
|
||||
""")
|
||||
|
||||
foreign_keys = [
|
||||
{
|
||||
'constraint': row[0],
|
||||
'column': row[1],
|
||||
'referenced_table': row[2],
|
||||
'referenced_column': row[3],
|
||||
}
|
||||
for row in cursor.fetchall()
|
||||
]
|
||||
|
||||
# Liste des utilisateurs du modèle users.User
|
||||
cursor.execute("""
|
||||
SELECT
|
||||
id,
|
||||
username,
|
||||
first_name,
|
||||
last_name
|
||||
FROM users_user
|
||||
ORDER BY id
|
||||
""")
|
||||
|
||||
users = [
|
||||
{
|
||||
'id': row[0],
|
||||
'username': row[1],
|
||||
'first_name': row[2],
|
||||
'last_name': row[3],
|
||||
}
|
||||
for row in cursor.fetchall()
|
||||
]
|
||||
|
||||
# Derniers pointages existants
|
||||
cursor.execute("""
|
||||
SELECT
|
||||
id,
|
||||
user_id,
|
||||
date,
|
||||
start_time,
|
||||
end_time
|
||||
FROM time_tracking_timeentry
|
||||
ORDER BY id DESC
|
||||
LIMIT 20
|
||||
""")
|
||||
|
||||
entries = [
|
||||
{
|
||||
'id': row[0],
|
||||
'user_id': row[1],
|
||||
'date': str(row[2]),
|
||||
'start_time': str(row[3]) if row[3] else None,
|
||||
'end_time': str(row[4]) if row[4] else None,
|
||||
}
|
||||
for row in cursor.fetchall()
|
||||
]
|
||||
|
||||
return Response({
|
||||
'database': connection.settings_dict.get('NAME'),
|
||||
'user_model': settings.AUTH_USER_MODEL,
|
||||
'foreign_keys': foreign_keys,
|
||||
'users': users,
|
||||
'entries': entries,
|
||||
})
|
||||
|
||||
class TimeEntryListView(generics.ListAPIView):
|
||||
serializer_class = TimeEntrySerializer
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user