Browse Source

added 55 courses to the table Curso

dmr1725 4 years ago
parent
commit
f7206feff5

BIN
server/CompanionApp/__pycache__/models.cpython-38.pyc View File


BIN
server/CompanionApp/__pycache__/views.cpython-38.pyc View File


+ 18
- 0
server/CompanionApp/migrations/0014_auto_20201207_1613.py View File

@@ -0,0 +1,18 @@
1
+# Generated by Django 3.0.8 on 2020-12-07 20:13
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('CompanionApp', '0013_auto_20201207_1056'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AlterField(
14
+            model_name='curso',
15
+            name='code',
16
+            field=models.CharField(max_length=15),
17
+        ),
18
+    ]

BIN
server/CompanionApp/migrations/__pycache__/0014_auto_20201207_1613.cpython-38.pyc View File


+ 1
- 1
server/CompanionApp/models.py View File

@@ -9,7 +9,7 @@ class Facultad(models.Model):
9 9
 class Curso(models.Model):
10 10
     fac_id = models.ForeignKey(Facultad, on_delete=models.CASCADE)
11 11
     name = models.CharField(max_length=150)
12
-    code = models.CharField(max_length=9)
12
+    code = models.CharField(max_length=15)
13 13
     creditos = models.IntegerField(default=0)
14 14
 
15 15
 class User(AbstractUser):

+ 30
- 10
server/CompanionApp/views.py View File

@@ -57,18 +57,38 @@ def insertarTodosLosCursos(request):
57 57
                         code = key
58 58
                         name = data[key][0]
59 59
                         creds = data[key][1]
60
-                        try: 
61
-                            curso = Curso.objects.get(code = code)
62
-                        except Curso.DoesNotExist:
63
-                            curso = None
60
+                        # si la clase es un laboratorio de 0 creditos
61
+                        if 'LAB' in key and (name == 'LABORATORIO' or name == 'LABORATORIO ' or name == 'TALLER' or name == 'TALLER ' or name == 'CONFERENCIA' or name == 'CONFERENCIA '):
62
+                            creds = 0
63
+                            try: 
64
+                                curso = Curso.objects.get(code = code)
65
+                            except Curso.DoesNotExist:
66
+                                curso = None
67
+
68
+                            if curso == None:
69
+                                curso_serializer = CursoSerializer(data={'name': name, 'code': code, 'creditos': creds, 'fac_id': fac_id})
70
+                                if curso_serializer.is_valid():
71
+                                    curso_serializer.save()
72
+                            else:
73
+                                print('ya se creo del lab', i)
74
+                                i += 1
75
+                        elif 'LAB in key' and (name != 'LABORATORIO' or name != 'LABORATORIO ' or name != 'TALLER' or name != 'TALLER ' or name != 'CONFERENCIA' or name != 'CONFERENCIA '):
76
+                            continue
64 77
                         
65
-                        if curso == None:
66
-                            curso_serializer = CursoSerializer(data={'name': name, 'code': code, 'creditos': creds, 'fac_id': fac_id})
67
-                            if curso_serializer.is_valid():
68
-                                curso_serializer.save()
78
+                        # todas las otras clases que no tengan _LAB en su codigo
69 79
                         else:
70
-                            print('ya se creo', i)
71
-                            i += 1
80
+                            try: 
81
+                                curso = Curso.objects.get(code = code)
82
+                            except Curso.DoesNotExist:
83
+                                curso = None
84
+                            
85
+                            if curso == None:
86
+                                curso_serializer = CursoSerializer(data={'name': name, 'code': code, 'creditos': creds, 'fac_id': fac_id})
87
+                                if curso_serializer.is_valid():
88
+                                    curso_serializer.save()
89
+                            else:
90
+                                print('ya se creo', i)
91
+                                i += 1
72 92
         return JsonResponse({'message': 'se insertaron todos los cursos'}, status=status.HTTP_201_CREATED)
73 93
 
74 94