init commit
This commit is contained in:
0
scripts/__init__.py
Normal file
0
scripts/__init__.py
Normal file
3
scripts/admin.py
Normal file
3
scripts/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
scripts/apps.py
Normal file
6
scripts/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ScriptsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'scripts'
|
||||
0
scripts/migrations/__init__.py
Normal file
0
scripts/migrations/__init__.py
Normal file
3
scripts/models.py
Normal file
3
scripts/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
3
scripts/tests.py
Normal file
3
scripts/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
9
scripts/urls.py
Normal file
9
scripts/urls.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
# path('sync_equipment/', views.sync_equipment, name='sync_equipment'),
|
||||
# path('sync_muscle_groups/', views.sync_muscle_groups, name='sync_equipment'),
|
||||
path('clear_redis/', views.clear_redis, name='clear_redis'),
|
||||
]
|
||||
46
scripts/views.py
Normal file
46
scripts/views.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from django.shortcuts import render
|
||||
from exercise.models import Exercise
|
||||
from muscle.models import Muscle, ExerciseMuscle
|
||||
from equipment.models import Equipment, WorkoutEquipment
|
||||
from rest_framework.decorators import api_view
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from django.core.cache import cache
|
||||
|
||||
# Create your views here.
|
||||
@api_view(['GET'])
|
||||
def sync_equipment(request):
|
||||
all_exercise = Exercise.objects.all()
|
||||
for exercise in all_exercise:
|
||||
all_equipment = exercise.equipment_required.split(',')
|
||||
for equipment in all_equipment:
|
||||
if len(equipment) > 0:
|
||||
try:
|
||||
equipment_obj = Equipment.objects.get(name=equipment.lower())
|
||||
WorkoutEquipment.objects.create(exercise=exercise, equipment=equipment_obj).save()
|
||||
except Equipment.DoesNotExist:
|
||||
pass
|
||||
|
||||
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
|
||||
@api_view(['GET'])
|
||||
def sync_muscle_groups(request):
|
||||
all_exercise = Exercise.objects.all()
|
||||
for exercise in all_exercise:
|
||||
all_muscle_groups = exercise.muscle_groups.split(',')
|
||||
for muscle_group in all_muscle_groups:
|
||||
if len(muscle_group) > 0:
|
||||
try:
|
||||
muscle_obj = Muscle.objects.get(name=muscle_group.lower())
|
||||
ExerciseMuscle.objects.create(exercise=exercise, muscle=muscle_obj).save()
|
||||
except MuscleGroup.DoesNotExist:
|
||||
pass
|
||||
|
||||
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
|
||||
@api_view(['GET'])
|
||||
def clear_redis(request):
|
||||
cache.clear()
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
Reference in New Issue
Block a user