|
@@ -3,7 +3,7 @@ import json
|
3
|
3
|
sys.path.insert(1,'C:/Users/diego/Documents/companion_app/organizar/')
|
4
|
4
|
|
5
|
5
|
|
6
|
|
-from organizar import files3
|
|
6
|
+from organizar import files3, proxSemFiles
|
7
|
7
|
|
8
|
8
|
|
9
|
9
|
from rest_auth.registration.views import SocialLoginView
|
|
@@ -15,7 +15,7 @@ from django.http.response import JsonResponse
|
15
|
15
|
from rest_framework.parsers import JSONParser
|
16
|
16
|
from rest_framework import status
|
17
|
17
|
|
18
|
|
-from .models import Facultad, Curso
|
|
18
|
+from .models import Facultad, Curso, ProximoSemestre
|
19
|
19
|
from .serializers import FacultadSerializer, CursoSerializer
|
20
|
20
|
from rest_framework.decorators import api_view
|
21
|
21
|
|
|
@@ -91,6 +91,49 @@ def insertarTodosLosCursos(request):
|
91
|
91
|
i += 1
|
92
|
92
|
return JsonResponse({'message': 'se insertaron todos los cursos'}, status=status.HTTP_201_CREATED)
|
93
|
93
|
|
|
94
|
+@api_view(['POST',])
|
|
95
|
+def insertarTodosLosCursosProxSemestre(request):
|
|
96
|
+ if request.method == 'POST':
|
|
97
|
+ for file in proxSemFiles:
|
|
98
|
+ path = "C:/Users/diego/Documents/companion_app/Miupi Parser"
|
|
99
|
+ with open(path + '/' + file['file']) as f:
|
|
100
|
+ data = json.load(f)
|
|
101
|
+ fac_id = file["num"] # this id comes from the file organizar. If the course does not exist in table Curso, use this id
|
|
102
|
+ for course in data:
|
|
103
|
+ name = course["Nombre"]
|
|
104
|
+ code = course["Curso"]
|
|
105
|
+ creditos = int(course["Creditos"])
|
|
106
|
+ section = course["Seccion"]
|
|
107
|
+ prof = course["Profesor"]
|
|
108
|
+ hours = course["Horario"]
|
|
109
|
+ days = course["Dias"]
|
|
110
|
+ rooms = course["Salones"]
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+ # seeing if course from json file already exists in table Curso
|
|
114
|
+ cursor = connection.cursor()
|
|
115
|
+ cursor.execute(f'SELECT id from "CompanionApp_curso" where code = \'{code}\'')
|
|
116
|
+ course_id = cursor.fetchone()
|
|
117
|
+
|
|
118
|
+ # if course does not exist in table Curso, create the course in table Course and create the course in table ProximoSemestre
|
|
119
|
+ if course_id == None:
|
|
120
|
+ # create course
|
|
121
|
+ cursor = connection.cursor()
|
|
122
|
+ cursor.execute(f'INSERT INTO "CompanionApp_curso" (name, code, creditos, fac_id_id) VALUES (\'{name}\', \'{code}\', {creditos}, {fac_id})')
|
|
123
|
+
|
|
124
|
+ # seeing again if course from json file already exists in table Curso to fetch course_id
|
|
125
|
+ cursor = connection.cursor()
|
|
126
|
+ cursor.execute(f'SELECT id from "CompanionApp_curso" where code = \'{code}\'')
|
|
127
|
+ course_id = cursor.fetchone()
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+ # insert course to the table ProxSemestre
|
|
131
|
+ course_id = course_id[0]
|
|
132
|
+ cursor = connection.cursor()
|
|
133
|
+
|
|
134
|
+ cursor.execute(f'INSERT INTO "CompanionApp_proximosemestre" (name, code, creditos, section, prof, hours, days, rooms, course_id_id) VALUES (\'{name}\', \'{code}\', {creditos}, \'{section}\', \'{prof}\', \'{hours}\', \'{days}\', \'{rooms}\', {course_id})')
|
|
135
|
+
|
|
136
|
+ return JsonResponse({'message': 'se insertaron todos los cursos'}, status=status.HTTP_201_CREATED)
|
94
|
137
|
|
95
|
138
|
|
96
|
139
|
@api_view(['PATCH',])
|
|
@@ -121,8 +164,17 @@ def findCourse(request):
|
121
|
164
|
courses = list(courses.values())
|
122
|
165
|
return JsonResponse({'list': courses}, status=status.HTTP_200_OK)
|
123
|
166
|
|
|
167
|
+# find courses in our ProximoSemestre table
|
|
168
|
+@api_view(['GET',])
|
|
169
|
+def selectCourseProxSemestre(request):
|
|
170
|
+ if request.method == 'GET':
|
|
171
|
+ course_code = request.query_params['code'].upper()
|
|
172
|
+ courses = ProximoSemestre.objects.filter(code__contains=course_code)[:10]
|
|
173
|
+ courses = list(courses.values())
|
|
174
|
+ return JsonResponse({'list': courses}, status=status.HTTP_200_OK)
|
|
175
|
+
|
124
|
176
|
|
125
|
|
-@api_view(['POST'])
|
|
177
|
+@api_view(['POST',])
|
126
|
178
|
def addTakenCourse(request):
|
127
|
179
|
if request.method == 'POST':
|
128
|
180
|
# request params
|