diff --git a/FusionIIIT/applications/central_mess/migrations/0010_auto_20240425_0417.py b/FusionIIIT/applications/central_mess/migrations/0010_auto_20240425_0417.py new file mode 100644 index 000000000..47d458b9b --- /dev/null +++ b/FusionIIIT/applications/central_mess/migrations/0010_auto_20240425_0417.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.5 on 2024-04-25 04:17 + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('central_mess', '0009_auto_20240424_0342'), + ] + + operations = [ + migrations.AlterField( + model_name='payments', + name='payment_date', + field=models.DateField(default=datetime.date(2024, 4, 25)), + ), + ] diff --git a/FusionIIIT/applications/globals/migrations/0014_auto_20240425_0417.py b/FusionIIIT/applications/globals/migrations/0014_auto_20240425_0417.py new file mode 100644 index 000000000..24b325d3f --- /dev/null +++ b/FusionIIIT/applications/globals/migrations/0014_auto_20240425_0417.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.5 on 2024-04-25 04:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('globals', '0013_auto_20240424_2236'), + ] + + operations = [ + migrations.AlterField( + model_name='extrainfo', + name='user_status', + field=models.CharField(choices=[('NEW', 'NEW'), ('PRESENT', 'PRESENT')], default='PRESENT', max_length=50), + ), + ] diff --git a/FusionIIIT/applications/globals/migrations/0015_auto_20240425_0421.py b/FusionIIIT/applications/globals/migrations/0015_auto_20240425_0421.py new file mode 100644 index 000000000..6e841d10c --- /dev/null +++ b/FusionIIIT/applications/globals/migrations/0015_auto_20240425_0421.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.5 on 2024-04-25 04:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('globals', '0014_auto_20240425_0417'), + ] + + operations = [ + migrations.AlterField( + model_name='extrainfo', + name='user_status', + field=models.CharField(choices=[('PRESENT', 'PRESENT'), ('NEW', 'NEW')], default='PRESENT', max_length=50), + ), + ] diff --git a/FusionIIIT/applications/gymkhana/api/serializers.py b/FusionIIIT/applications/gymkhana/api/serializers.py index c2a833b9e..77a92726c 100644 --- a/FusionIIIT/applications/gymkhana/api/serializers.py +++ b/FusionIIIT/applications/gymkhana/api/serializers.py @@ -37,7 +37,7 @@ class Meta: class Club_DetailsSerializer(serializers.ModelSerializer): class Meta: model=Club_info - fields=['club_name',"co_ordinator","co_coordinator","activity_calender","category",'faculty_incharge'] + fields=['club_name',"co_ordinator","co_coordinator","activity_calender","category",'faculty_incharge',"club_file", "status"] class Session_infoSerializer(serializers.ModelSerializer): class Meta: @@ -50,7 +50,7 @@ class event_infoserializer(serializers.ModelSerializer): class Meta: model=Event_info - fields=['club','event_name','incharge','date','venue','start_time','id','details'] + fields=['club','event_name','incharge','date','venue','start_time','id','details','status'] class club_budgetserializer(serializers.ModelSerializer): diff --git a/FusionIIIT/applications/gymkhana/api/views.py b/FusionIIIT/applications/gymkhana/api/views.py index 9b70cccc6..0ec4b524e 100644 --- a/FusionIIIT/applications/gymkhana/api/views.py +++ b/FusionIIIT/applications/gymkhana/api/views.py @@ -1,6 +1,7 @@ import genericpath import json import tempfile +from datetime import datetime from venv import logger from rest_framework.permissions import IsAuthenticated from rest_framework.authentication import TokenAuthentication @@ -111,33 +112,103 @@ def post(self, request): return Response({"message": "Club member deleted successfully."}, status=status.HTTP_204_NO_CONTENT) -class UpdateClubDetailsAPIView(APIView): - def post(self, request, *args, **kwargs): - club_name = request.data.get('club_name') - co_coordinator = request.data.get('co_coordinator') - co_ordinator = request.data.get('co_ordinator') +# class UpdateClubDetailsAPIView(APIView): +# def post(self, request, *args, **kwargs): +# club_name = request.data.get('club_name') +# co_coordinator = request.data.get('co_coordinator') +# co_ordinator = request.data.get('co_ordinator') - print(f"Received request data: club_name={club_name}, co_coordinator={co_coordinator}, co_ordinator={co_ordinator}") +# print(f"Received request data: club_name={club_name}, co_coordinator={co_coordinator}, co_ordinator={co_ordinator}") - # Retrieve the Club_info object by club_name - try: - club_info = Club_info.objects.get(club_name=club_name) - except Club_info.DoesNotExist: - return Response({"message": "Club not found"}, status=status.HTTP_404_NOT_FOUND) +# # Retrieve the Club_info object by club_name +# try: +# club_info = Club_info.objects.get(club_name=club_name) +# except Club_info.DoesNotExist: +# return Response({"message": "Club not found"}, status=status.HTTP_404_NOT_FOUND) - print(f"Found Club_info object: {club_info}") +# print(f"Found Club_info object: {club_info}") - # Update the details provided in the request - serializer = Club_infoSerializer(instance=club_info, data={'co_coordinator': co_coordinator, 'co_ordinator': co_ordinator}, partial=True) - if serializer.is_valid(): - print("Serializer is valid. Saving...") - serializer.save() - print("Data saved successfully.") - return Response(serializer.data) - else: - print(f"Serializer errors: {serializer.errors}") - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - +# # Update the details provided in the request +# serializer = Club_infoSerializer(instance=club_info, data={'co_coordinator': co_coordinator, 'co_ordinator': co_ordinator}, partial=True) +# if serializer.is_valid(): +# print("Serializer is valid. Saving...") +# serializer.save() +# print("Data saved successfully.") +# return Response(serializer.data) +# else: +# print(f"Serializer errors: {serializer.errors}") +# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + +class ChangeHeadAPIView(APIView): + def post(self, request): + club = request.data.get("club_name") + co_ordinator = request.data.get('co_ordinator') + co_coordinator = request.data.get('co_coordinator') + + if not club or (not co_ordinator and not co_coordinator): + return JsonResponse({'status': 'error', 'message': 'Invalid request parameters'}) + + try: + club_info = Club_info.objects.get(club_name=club) + except Club_info.DoesNotExist: + return JsonResponse({'status': 'error', 'message': 'Club not found'}) + + message = "" + + if co_ordinator: + if not Club_member.objects.filter(club_id=club, member_id=co_ordinator).exists(): + return JsonResponse({'status': 'error', 'message': 'Selected student is not a member of the club'}) + + try: + co_ordinator_student = Student.objects.get(id_id=co_ordinator) + old_co_ordinator = club_info.co_ordinator_id + club_info.co_ordinator_id = co_ordinator_student + + new_co_ordinator = HoldsDesignation( + user=User.objects.get(username=co_ordinator), + working=User.objects.get(username=co_ordinator), + designation=Designation.objects.get(name="co-ordinator") + ) + new_co_ordinator.save() + + HoldsDesignation.objects.filter( + user__username=old_co_ordinator, + designation=Designation.objects.get(name="co-ordinator") + ).delete() + + message += "Successfully changed co-ordinator !!!" + except Student.DoesNotExist: + return JsonResponse({'status': 'error', 'message': 'Selected student not found'}) + + if co_coordinator: + if not Club_member.objects.filter(club_id=club, member_id=co_coordinator).exists(): + return JsonResponse({'status': 'error', 'message': 'Selected student is not a member of the club'}) + + try: + co_coordinator_student = Student.objects.get(id_id=co_coordinator) + old_co_coordinator = club_info.co_coordinator_id + club_info.co_coordinator_id = co_coordinator_student + + new_co_coordinator = HoldsDesignation( + user=User.objects.get(username=co_coordinator), + working=User.objects.get(username=co_coordinator), + designation=Designation.objects.get(name="co co-ordinator") + ) + new_co_coordinator.save() + + HoldsDesignation.objects.filter( + user__username=old_co_coordinator, + designation=Designation.objects.get(name="co co-ordinator") + ).delete() + + message += "Successfully changed co-coordinator !!!" + except Student.DoesNotExist: + return JsonResponse({'status': 'error', 'message': 'Selected student not found'}) + + club_info.head_changed_on = timezone.now() + club_info.save() + + return JsonResponse({'status': "success", 'message': message}) class AddMemberToClub(APIView): def post(self, request): serializer = Club_memberSerializer(data=request.data) @@ -308,51 +379,76 @@ def post(self, request): return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + -class DeleteEventsView(APIView): - """ - API endpoint to delete events. - """ - def post(self, request): - """ - Handle POST requests to delete events. - """ - try: - events_deleted = [] - events_not_found = [] +# class DeleteEventsView(APIView): +# """ +# API endpoint to delete events. +# """ + +# def post(self, request): +# """ +# Handle POST requests to delete events. +# """ +# try: +# events_deleted = [] +# events_not_found = [] - # Ensure that request.data is a dictionary - event_data_list = request.data if isinstance(request.data, list) else [] - - for event_data in event_data_list: - name = event_data.get('event_name') - venue = event_data.get('venue') - incharge = event_data.get('incharge') - date = event_data.get('date') - - # Query Event_info based on the provided parameters - event = Event_info.objects.filter( - event_name=name, - venue=venue, - incharge=incharge, - date=date - ).first() +# # Ensure that request.data is a dictionary +# event_data_list = request.data if isinstance(request.data, list) else [] + +# for event_data in event_data_list: +# name = event_data.get('event_name') +# venue = event_data.get('venue') +# incharge = event_data.get('incharge') +# date = event_data.get('date') +# event_id = event_data.get('id') + +# # Query Event_info based on the provided parameters +# event = Event_info.objects.filter( +# event_name=name, +# venue=venue, +# incharge=incharge, +# date=date, +# event_id=id, +# ).first() + +# if event: +# event.delete() +# events_deleted.append(event_data) +# else: +# events_not_found.append(event_data) + +# response_data = { +# "events_deleted": events_deleted, +# "events_not_found": events_not_found +# } + +# return Response(response_data, status=status.HTTP_200_OK) +# except Exception as e: +# return Response(str(e), status=status.HTTP_500_INTERNAL_SERVER_ERROR) + +class EventDeleteAPIView(APIView): + def post(self, request, *args, **kwargs): + # Retrieve data from request + event_data = request.data - if event: - event.delete() - events_deleted.append(event_data) - else: - events_not_found.append(event_data) + # Check if 'id' parameter is provided + if 'id' not in event_data: + return Response({'error': 'The "id" parameter is required'}, status=status.HTTP_400_BAD_REQUEST) - response_data = { - "events_deleted": events_deleted, - "events_not_found": events_not_found - } + # Get the event by id + event_id = event_data['id'] + try: + event = Event_info.objects.get(id=event_id) + except Event_info.DoesNotExist: + return Response({'error': 'Event not found with the provided id'}, status=status.HTTP_404_NOT_FOUND) - return Response(response_data, status=status.HTTP_200_OK) - except Exception as e: - return Response(str(e), status=status.HTTP_500_INTERNAL_SERVER_ERROR) + # Delete the event + event.delete() + + return Response({'message': 'Event deleted successfully'}, status=status.HTTP_200_OK) class SessionUpdateAPIView(APIView): @@ -556,23 +652,200 @@ def post(self, request): return Response({"message": "Club deleted successfully"}, status=status.HTTP_200_OK) -class ClubCreateAPIView(APIView): - def post(self, request, format=None): - data = { - 'club_name': request.data.get('club_name'), - 'category': request.data.get('category'), - 'co_ordinator': request.data.get('co_ordinator'), - 'co_coordinator': request.data.get('co_coordinator'), - 'faculty_incharge': request.data.get('faculty_incharge'), - 'club_file': request.data.get('club_file'), - 'activity_calender': request.data.get('activity_calender'), - 'description': request.data.get('description'), - 'status': request.data.get('status'), - 'head_changed_on': request.data.get('head_changed_on'), - 'created_on': request.data.get('created_on') - } - serializer = Club_infoSerializer(data=data) +# class ClubCreateAPIView(APIView): +# def post(self, request, format=None): +# data = { +# 'club_name': request.data.get('club_name'), +# 'category': request.data.get('category'), +# 'co_ordinator': request.data.get('co_ordinator'), +# 'co_coordinator': request.data.get('co_coordinator'), +# 'faculty_incharge': request.data.get('faculty_incharge'), +# 'club_file': request.data.get('club_file'), +# 'activity_calender': request.data.get('activity_calender'), +# 'description': request.data.get('description'), +# 'status': request.data.get('status'), +# 'head_changed_on': request.data.get('head_changed_on'), +# 'created_on': request.data.get('created_on'), +# } +# serializer = Club_infoSerializer(data=data,partial=True) +# if serializer.is_valid(): +# serializer.save() +# return Response(serializer.data, status=status.HTTP_201_CREATED) +# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + + +class CreateClubAPIView(APIView): + def post(self, request): + # Get the string representation of the file content for club_file + club_file_content = request.data.get('club_file') + + # Convert the string to a file object for club_file + club_file_obj = None + if club_file_content: + club_file_obj = ContentFile(club_file_content.encode(), name='club_file.txt') + + # Update the request data with the file object for club_file + request.data['club_file'] = club_file_obj + + # Get the string representation of the file content for activity_calendar + description = request.data.get('description') + + # Initialize the serializer with the modified request data + serializer = Club_infoSerializer(data=request.data) + + # Validate and save the serializer data if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) \ No newline at end of file + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + + + +class UpdateClubStatusAPIView(APIView): + def post(self, request): + # Retrieve data from request + club_data = request.data + + # Extract fields for filtering + club_name = club_data.get('club_name') + co_ordinator = club_data.get('co_ordinator') + co_coordinator = club_data.get('co_coordinator') + faculty_incharge = club_data.get('faculty_incharge') + + # Check if all required fields are provided + if not all([club_name, co_ordinator, co_coordinator, faculty_incharge]): + return Response({"error": "Missing required fields"}, status=status.HTTP_400_BAD_REQUEST) + + # Try to find the club based on provided fields + try: + club = Club_info.objects.get( + club_name=club_name, + co_ordinator=co_ordinator, + co_coordinator=co_coordinator, + faculty_incharge=faculty_incharge + ) + except Club_info.DoesNotExist: + return Response({"error": "Club not found"}, status=status.HTTP_404_NOT_FOUND) + + # Update the status of the club + club.status = 'confirmed' + club.save() + + return Response({"message": "Club status updated to 'confirmed' successfully"}, status=status.HTTP_200_OK) + + + + + + +# class UpdateClubNameAPIView(APIView): +# def post(self, request): +# # Retrieve data from request +# club_data = request.data + +# # Extract fields for filtering +# club_name = club_data.get('club_name') +# co_ordinator = club_data.get('co_ordinator') +# co_coordinator = club_data.get('co_coordinator') +# faculty_incharge = club_data.get('faculty_incharge') +# new_club = club_data.get('new_club') + +# # Check if all required fields are provided +# if not all([club_name, co_ordinator, co_coordinator, faculty_incharge]): +# return Response({"error": "Missing required fields"}, status=status.HTTP_400_BAD_REQUEST) + +# # Try to find the club based on provided fields +# try: +# club = Club_info.objects.get( +# club_name=club_name, +# co_ordinator=co_ordinator, +# co_coordinator=co_coordinator, +# faculty_incharge=faculty_incharge +# ) +# except Club_info.DoesNotExist: +# return Response({"error": "Club not found"}, status=status.HTTP_404_NOT_FOUND) + +# # Update the status of the club +# club.club_name = new_club +# club.save() + +# return Response({"message": "Club name updated successfully"}, status=status.HTTP_200_OK) + + + +class UpdateClubNameAPIView(APIView): + def post(self, request): + # Retrieve data from request + club_data = request.data + + # Extract fields for filtering + club_name = club_data.get('club_name') + co_ordinator = club_data.get('co_ordinator') + co_coordinator = club_data.get('co_coordinator') + faculty_incharge = club_data.get('faculty_incharge') + new_club = club_data.get('new_club') + + # Check if all required fields are provided + if not all([club_name, co_ordinator, co_coordinator, faculty_incharge, new_club]): + return Response({"error": "Missing required fields"}, status=status.HTTP_400_BAD_REQUEST) + + # Try to find the club based on provided fields + try: + club = Club_info.objects.get( + club_name=club_name, + co_ordinator=co_ordinator, + co_coordinator=co_coordinator, + faculty_incharge=faculty_incharge + ) + except Club_info.DoesNotExist: + return Response({"error": "Club not found"}, status=status.HTTP_404_NOT_FOUND) + + # Check if a club with the new name already exists + if Club_info.objects.filter(club_name=new_club).exists(): + return Response({"error": f"A club with the name '{new_club}' already exists"}, status=status.HTTP_400_BAD_REQUEST) + + # Update the status of the club + club.club_name = new_club + club.save() + + # Delete the original club entry + Club_info.objects.filter(club_name=club_name).delete() + + return Response({"message": "Club name updated successfully"}, status=status.HTTP_200_OK) + + + +class ApproveEvent(APIView): + def post(self, request): + # Retrieve data from request + event_data = request.data + + # Extract fields for filtering + event_name = event_data.get('event_name') + incharge = event_data.get('incharge') + date = event_data.get('date') + venue = event_data.get('venue') + event_id = event_data.get('id') + # status = event_data.get('status') + + # Check if all required fields are provided + if not all([event_name, incharge, date, venue, event_id]): + return Response({"error": "Missing required fields"}, status=status.HTTP_400_BAD_REQUEST) + + # Try to find the event based on provided fields + try: + event = Event_info.objects.get( + event_name=event_name, + incharge=incharge, + date=date, + venue=venue, + id=event_id + ) + except Event_info.DoesNotExist: + return Response({"error": "Event not found"}, status=status.HTTP_404_NOT_FOUND) + + # Update the status of the event + event.status = 'confirmed' + event.save() + + return Response({"message": "event status updated successfully"}, status=status.HTTP_200_OK) \ No newline at end of file diff --git a/FusionIIIT/applications/gymkhana/urls.py b/FusionIIIT/applications/gymkhana/urls.py index 5ec84f2b7..3c8c20de1 100644 --- a/FusionIIIT/applications/gymkhana/urls.py +++ b/FusionIIIT/applications/gymkhana/urls.py @@ -1,10 +1,10 @@ from django.conf.urls import url from django.urls import path from rest_framework.urlpatterns import format_suffix_patterns -from applications.gymkhana.api.views import AddClub_BudgetAPIView, AddMemberToClub, ClubCreateAPIView, ClubMemberAPIView, ClubMemberApproveView, ClubMemberDeleteAPIView, CreateVotingPollAPIView, DeleteClubAPIView, DeleteClubBudgetAPIView, DeleteEventsView, EventUpdateAPIView, SessionUpdateAPIView, UpdateClubBudgetAPIView, UpdateClubDetailsAPIView, UploadActivityCalendarAPIView +from applications.gymkhana.api.views import AddClub_BudgetAPIView, AddMemberToClub, ApproveEvent, ChangeHeadAPIView, ClubMemberAPIView, ClubMemberApproveView, ClubMemberDeleteAPIView, CreateClubAPIView, DeleteClubAPIView, DeleteClubBudgetAPIView, EventDeleteAPIView, EventUpdateAPIView, SessionUpdateAPIView, UpdateClubBudgetAPIView, UpdateClubNameAPIView, UpdateClubStatusAPIView, UploadActivityCalendarAPIView from applications.gymkhana.api.views import clubname,Club_Details,club_events,club_budgetinfo,Fest_Budget,club_report,Registraion_form from applications.gymkhana.api.views import session_details -from applications.gymkhana.api.views import DeleteSessionsView, NewEventAPIView, NewSessionAPIView, ShowVotingChoicesAPIView, VoteIncrementAPIView, Voting_Polls, VotingPollsDeleteAPIView +from applications.gymkhana.api.views import DeleteSessionsView, NewEventAPIView, NewSessionAPIView, ShowVotingChoicesAPIView, VoteIncrementAPIView, VotingPollsDeleteAPIView from . import views from rest_framework.authtoken.views import obtain_auth_token @@ -101,9 +101,9 @@ url(r'^api/update_clubBudget/$', UpdateClubBudgetAPIView.as_view(), name='update budget'), url(r'^api/add_clubBudget/$', AddClub_BudgetAPIView.as_view(), name='edit event'), - url(r'^api/update_coordinator/$', UpdateClubDetailsAPIView.as_view(), name = 'update coordinator'), + url(r'^api/update_coordinator/$', ChangeHeadAPIView.as_view(), name = 'update coordinator'), url(r'^api/activity_calender/$', UploadActivityCalendarAPIView.as_view(), name='update activity calendder'), - url(r'^api/delete_event/$', DeleteEventsView.as_view(), name='delete_events_api'), + url(r'^api/delete_event/$', EventDeleteAPIView.as_view(), name='delete_events_api'), url(r'^api/delete_sessions/$', DeleteSessionsView.as_view(), name='delete_sessions_api'), url(r'^api/new_session/$',NewSessionAPIView.as_view(), name='new_session_api'), url(r'^api/new_event/$',NewEventAPIView.as_view(), name='new_event_api'), @@ -117,10 +117,11 @@ url(r'^api/vote/$', VoteIncrementAPIView.as_view(), name='give vote'), url(r'^api/edit_session/$', SessionUpdateAPIView.as_view(), name='edit session'), url(r'^api/edit_event/$', EventUpdateAPIView.as_view(), name='edit event'), - url(r'^session_details/$',session_details.as_view()), url(r'^api/delete_budget/$',DeleteClubBudgetAPIView.as_view(), name='delete budget'), url(r'^api/upload_activitycalender/$', UploadActivityCalendarAPIView.as_view(), name='calender'), - url(r'^api/createClub/$', ClubCreateAPIView.as_view(), name='create new Club'), - url(r'^api/create_poll/$', CreateVotingPollAPIView.as_view(), name='create poll'), + url(r'^api/create_club/$', CreateClubAPIView.as_view(), name='new club'), + url(r'^api/update_clubStatus/$', UpdateClubStatusAPIView.as_view(),name = 'update club status' ), + url(r'^api/updateClubName/$', UpdateClubNameAPIView.as_view(), name = 'update club name'), + url(r'^api/approve_event/$', ApproveEvent.as_view(), name = 'approve event'), ] diff --git a/FusionIIIT/applications/research_procedures/migrations/0004_auto_20240425_0417.py b/FusionIIIT/applications/research_procedures/migrations/0004_auto_20240425_0417.py new file mode 100644 index 000000000..2f0925cfb --- /dev/null +++ b/FusionIIIT/applications/research_procedures/migrations/0004_auto_20240425_0417.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.5 on 2024-04-25 04:17 + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('research_procedures', '0003_auto_20240424_0342'), + ] + + operations = [ + migrations.AlterField( + model_name='staff_allocations', + name='start_date', + field=models.DateField(default=datetime.date(2024, 4, 25)), + ), + ]