@@ -536,11 +536,33 @@ def Admin_view_all_working_curriculums(request):
536536 # Manually serialize the curriculums into a list of dictionaries
537537 curriculum_data = []
538538 for curriculum in curriculums :
539+ primary_batches = curriculum .batches .all ()
540+
541+ from django .db .models import Q
542+ multi_curriculum_batches = Batch .objects .filter (
543+ curriculum_options__isnull = False
544+ ).exclude (
545+ curriculum_options = []
546+ )
547+
548+ batches_with_this_curriculum = []
549+ for batch in primary_batches :
550+ batches_with_this_curriculum .append (batch )
551+
552+ for batch in multi_curriculum_batches :
553+ if batch .curriculum_options :
554+ for curr_option in batch .curriculum_options :
555+ if curr_option .get ('id' ) == curriculum .id :
556+ batches_with_this_curriculum .append (batch )
557+ break
558+
559+ unique_batches = list (set (batches_with_this_curriculum ))
560+
539561 curriculum_data .append ({
540562 'id' :curriculum .id ,
541563 'name' : curriculum .name ,
542564 'version' : str (curriculum .version ), # Convert Decimal to string for JSON compatibility
543- 'batch' : [str (batch ) for batch in curriculum . batches ], # Use batches property from model
565+ 'batch' : [str (batch ) for batch in unique_batches ], # Include both primary and multi-curriculum batches
544566 'semesters' : curriculum .no_of_semester ,
545567 })
546568
@@ -1833,7 +1855,7 @@ def edit_batch_form(request, batch_id):
18331855 curricula_data = [{
18341856 'id' : curriculum .id ,
18351857 'name' : curriculum .name ,
1836- 'version' : curriculum .version ,
1858+ 'version' : str ( curriculum .version ) ,
18371859 # Uncomment these if you want to include discipline and programme details
18381860 # 'discipline': curriculum.discipline.name,
18391861 # 'programme': curriculum.programme.name,
@@ -1870,16 +1892,52 @@ def edit_batch_form(request, batch_id):
18701892 except Discipline .DoesNotExist :
18711893 return JsonResponse ({'error' : 'Invalid discipline ID' }, status = 400 )
18721894
1873- # Update curriculum (if provided)
1874- curriculum_id = data .get ('disciplineBatch' )
1875- if curriculum_id :
1876- try :
1877- curriculum = Curriculum .objects .get (id = curriculum_id )
1878- batch .curriculum = curriculum
1879- except Curriculum .DoesNotExist :
1880- return JsonResponse ({'error' : 'Invalid curriculum ID' }, status = 400 )
1881- else :
1882- batch .curriculum = None # Set curriculum to None if not provided
1895+ curriculum_data = data .get ('disciplineBatch' ) or data .get ('curriculum' ) or data .get ('curriculum_data' )
1896+ if curriculum_data is not None :
1897+ # Normalize to list of ids if possible
1898+ curriculum_ids = []
1899+ if isinstance (curriculum_data , list ):
1900+ curriculum_ids = curriculum_data
1901+ elif isinstance (curriculum_data , str ):
1902+ if ',' in curriculum_data :
1903+ curriculum_ids = [c .strip () for c in curriculum_data .split (',' ) if c .strip ()]
1904+ elif curriculum_data .lower () in ['null' , 'none' , '' ]:
1905+ curriculum_ids = []
1906+ else :
1907+ curriculum_ids = [curriculum_data ]
1908+ else :
1909+ curriculum_ids = [curriculum_data ]
1910+
1911+ if len (curriculum_ids ) > 1 :
1912+ option_list = []
1913+ for cid in curriculum_ids :
1914+ try :
1915+ c_obj = Curriculum .objects .get (id = int (cid ))
1916+ option_list .append ({'id' : c_obj .id , 'name' : c_obj .name , 'version' : str (c_obj .version )})
1917+ except (Curriculum .DoesNotExist , ValueError ):
1918+ return JsonResponse ({'error' : f'Invalid curriculum ID: { cid } ' }, status = 400 )
1919+ batch .curriculum = None
1920+ try :
1921+ batch .curriculum_options = option_list
1922+ except Exception :
1923+ pass
1924+ elif len (curriculum_ids ) == 1 :
1925+ # Single curriculum selected
1926+ try :
1927+ c_obj = Curriculum .objects .get (id = int (curriculum_ids [0 ]))
1928+ batch .curriculum = c_obj
1929+ try :
1930+ batch .curriculum_options = None
1931+ except Exception :
1932+ pass
1933+ except (Curriculum .DoesNotExist , ValueError ):
1934+ return JsonResponse ({'error' : 'Invalid curriculum ID' }, status = 400 )
1935+ else :
1936+ batch .curriculum = None
1937+ try :
1938+ batch .curriculum_options = None
1939+ except Exception :
1940+ pass
18831941
18841942 # Save the updated batch
18851943 batch .save ()
@@ -3215,7 +3273,6 @@ def course_slot_type_choices(request):
32153273 API endpoint to return the list of course slot type choices from the CourseSlot model.
32163274 """
32173275 choices = [{'value' : key , 'label' : label } for key , label in CourseSlot ._meta .get_field ('type' ).choices ]
3218- # print(choices)
32193276 return JsonResponse ({'choices' : choices })
32203277
32213278@csrf_exempt
@@ -3277,14 +3334,6 @@ def get_programme(request, programme_id):
32773334@permission_classes ([IsAuthenticated ])
32783335def get_batch_names (request ):
32793336 choices = [{'value' : key , 'label' : label } for key , label in Batch ._meta .get_field ('name' ).choices ]
3280- # print('choices',choices)
3281-
3282- # batch_names = Batch.objects.values_list('name', flat=True).distinct()
3283- # print(batch_names)
3284- # # Convert the QuerySet to a list
3285- # batch_names_list = list(batch_names)
3286- # print(batch_names_list)
3287- # Return the list as a JSON response
32883337 return JsonResponse ({'choices' : choices })
32893338
32903339@csrf_exempt
@@ -3309,13 +3358,9 @@ def get_all_disciplines(request):
33093358@csrf_exempt
33103359@permission_classes ([IsAuthenticated ])
33113360def get_unused_curriculam (request ):
3312- # Fetch all curriculum IDs that are present in the Batch table
33133361 used_curriculum_ids = Batch .objects .exclude (curriculum__isnull = True ).values_list ('curriculum_id' , flat = True )
3314-
3315- # Fetch curricula whose IDs are not in the used_curriculum_ids list
33163362 unused_curricula = Curriculum .objects .exclude (id__in = used_curriculum_ids )
3317-
3318- # Serialize the unused curricula
3363+ # ...existing code...
33193364 unused_curricula_data = [
33203365 {
33213366 'id' : curriculum .id ,
0 commit comments