Skip to content

Commit

Permalink
feat: Routine updates
Browse files Browse the repository at this point in the history
  • Loading branch information
RatlyREM committed Sep 24, 2023
2 parents 0ca4b90 + 7eedfa2 commit 8eabe13
Show file tree
Hide file tree
Showing 68 changed files with 967 additions and 86 deletions.
Empty file added .idea/.idea/.gitignore
Empty file.
8 changes: 8 additions & 0 deletions .idea/.idea/.idea.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/.idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions .idea/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added .idea/.vs/.idea/v16/.suo
Binary file not shown.
3 changes: 3 additions & 0 deletions .idea/.vs/ProjectSettings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.vs/VSWorkspaceState.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added .idea/.vs/slnx.sqlite
Binary file not shown.
16 changes: 16 additions & 0 deletions .idea/main.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Exer/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file modified Exer/__pycache__/serializers.cpython-310.pyc
Binary file not shown.
Binary file modified Exer/__pycache__/views.cpython-310.pyc
Binary file not shown.
2 changes: 2 additions & 0 deletions Exer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
class Exercise(models.Model):
exercise_id = models.IntegerField(primary_key=True)
usebody = models.ForeignKey('usebody.Usebody', on_delete=models.CASCADE, max_length=11)

exerciseName_English= models.CharField(max_length=50, blank=True, null=True)
exerciseName_Korean = models.CharField(max_length=50, blank=True, null=True)
equipment_name = models.CharField(max_length=50, blank=True, null=True)
videolink = models.CharField(max_length=150, blank=True, null=True)


class Meta:
managed = False
db_table = 'exercise'
Expand Down
12 changes: 11 additions & 1 deletion Exer/serializers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
from rest_framework import serializers
from .models import Exercise
from usebody.models import Usebody

class BodySerializer(serializers.ModelSerializer):
class Meta:
model = Usebody
fields= '__all__'
class ExerciseDetailSerializer(serializers.ModelSerializer):
class Meta:
model = Exercise
fields = ['exerciseName_English', 'exerciseName_Korean', 'equipment_name', 'videolink']
fields = ['usebody_id','exerciseName_English', 'exerciseName_Korean', 'equipment_name', 'videolink']

class ExerciseSerializer(serializers.ModelSerializer):
#usebody_name = serializers.SerializerMethodField()

# def get_usebody_name(self, obj):
# return obj.usebody_name
class Meta:
model = Exercise

fields = ['usebody_id', 'exerciseName_English', 'exerciseName_Korean']
48 changes: 42 additions & 6 deletions Exer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,28 @@
from Exer.serializers import ExerciseDetailSerializer
from django.shortcuts import get_object_or_404

from django.db import connection

#03-01 부위별 운동 간단 조회
#usebody의 id 대신 name이 나오게 하려면 model을 수정해야 할 것으로 보임
class ExerciseBodyAPIiew(APIView):
def get_object(self,pk):
return Exercise.objects.filter(usebody_id=pk)

def get(self,request,pk):
#pk를 usebody_id를 가지는 객체를 가져온다
cursor = connection.cursor()
sql = "select usebody_name from usebody where usebody_id = %s"
cursor.execute(sql, [pk])
result = cursor.fetchall()

exercise = self.get_object(pk)
serializer = ExerciseSerializer(exercise, many=True)

for i in serializer.data:
key = f'usebody_name'
value= result[0][0]
i[key] = value

return Response(serializer.data)


Expand All @@ -33,12 +45,36 @@ def get(self, request,pk):
#03-03 운동 검색
class ExerciseSearchAPIView(APIView):
def post(self,request):
data = request.data
if request.body:
objectsKor = Exercise.objects.filter(exerciseName_English__icontains=request.data.get('searchData'))
objectsEng = Exercise.objects.filter(exerciseName_Korean__icontains=request.data.get('searchData'))

combined_objects = list(objectsKor) + list(objectsEng)

body = []

exercise = Exercise.objects.filter(exerciseName_Korean=data)
serializer = ExerciseSerializer(exercise)
for i in combined_objects:
u_id = i.usebody_id

cursor = connection.cursor()
sql = "select usebody_name from usebody where usebody_id = %s"
cursor.execute(sql, [u_id])
result = cursor.fetchall()
body.append(result[0][0])

serializer = ExerciseSerializer(combined_objects, many=True)

index = 0
for i in serializer.data:

key = f'usebody_name'
value = body[index]
i[key] = value
index+=1

if serializer.is_valid():
return Response(serializer.data)
return Response(serializer.errors)
else:
objects = Exercise.objects.all()
serializer = ExerciseSerializer(objects, many=True)

return Response(serializer.data)
Binary file modified __pycache__/my_settings.cpython-310.pyc
Binary file not shown.
Binary file modified accounts/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified accounts/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file modified accounts/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file added accounts/__pycache__/backends.cpython-310.pyc
Binary file not shown.
Binary file added accounts/__pycache__/backends.cpython-311.pyc
Binary file not shown.
Binary file modified accounts/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file modified accounts/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file added accounts/__pycache__/serializers.cpython-310.pyc
Binary file not shown.
Binary file added accounts/__pycache__/serializers.cpython-311.pyc
Binary file not shown.
Binary file added accounts/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file added accounts/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file added accounts/__pycache__/utils.cpython-310.pyc
Binary file not shown.
Binary file added accounts/__pycache__/utils.cpython-311.pyc
Binary file not shown.
Binary file added accounts/__pycache__/views.cpython-310.pyc
Binary file not shown.
Binary file added accounts/__pycache__/views.cpython-311.pyc
Binary file not shown.
18 changes: 18 additions & 0 deletions accounts/backends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import bcrypt
from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.hashers import check_password
from django.db.models import Q


class EmailBackend(ModelBackend):
def authenticate(self, request, username=None, password=None, **kwargs):
UserModel = get_user_model()
try:
user = UserModel.objects.get(email=username)
except UserModel.DoesNotExist:
return None
else:
if user.check_password(password):
return user
return None
35 changes: 35 additions & 0 deletions accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 4.2.3 on 2023-08-15 16:59

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]

operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('email', models.EmailField(blank=True, max_length=100, unique=True)),
('nickname', models.CharField(blank=True, max_length=20, unique=True)),
('is_superuser', models.BooleanField(default=False)),
('is_active', models.BooleanField(default=True)),
('is_staff', models.BooleanField(default=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
],
options={
'abstract': False,
},
),
]
Binary file not shown.
Binary file not shown.
Binary file modified accounts/migrations/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Loading

0 comments on commit 8eabe13

Please sign in to comment.