Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented the create_request, process_request and approve/reject_re… #1305

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 3.1.5 on 2024-03-08 10:23

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('academic_procedures', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='assistantshipclaim',
name='year',
field=models.IntegerField(choices=[(2024, 2024), (2023, 2023)]),
),
migrations.AlterField(
model_name='course_registration',
name='working_year',
field=models.IntegerField(blank=True, choices=[(2024, 2024), (2023, 2023)], null=True),
),
migrations.AlterField(
model_name='finalregistrations',
name='batch',
field=models.IntegerField(default=2024),
),
migrations.AlterField(
model_name='messdue',
name='year',
field=models.IntegerField(choices=[(2024, 2024), (2023, 2023)]),
),
migrations.AlterField(
model_name='register',
name='year',
field=models.IntegerField(default=2024),
),
]
53 changes: 53 additions & 0 deletions FusionIIIT/applications/eis/migrations/0002_auto_20240308_1023.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Generated by Django 3.1.5 on 2024-03-08 10:23

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('eis', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='emp_achievement',
name='a_year',
field=models.IntegerField(blank=True, choices=[(1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)], null=True, verbose_name='year'),
),
migrations.AlterField(
model_name='emp_confrence_organised',
name='k_year',
field=models.IntegerField(blank=True, choices=[(1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)], null=True, verbose_name='year'),
),
migrations.AlterField(
model_name='emp_expert_lectures',
name='l_year',
field=models.IntegerField(blank=True, choices=[(1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)], null=True, verbose_name='year'),
),
migrations.AlterField(
model_name='emp_keynote_address',
name='k_year',
field=models.IntegerField(blank=True, choices=[(1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)], null=True, verbose_name='year'),
),
migrations.AlterField(
model_name='emp_mtechphd_thesis',
name='s_year',
field=models.IntegerField(blank=True, choices=[(1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)], null=True, verbose_name='year'),
),
migrations.AlterField(
model_name='emp_patents',
name='p_year',
field=models.IntegerField(blank=True, choices=[(1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)], null=True, verbose_name='year'),
),
migrations.AlterField(
model_name='emp_published_books',
name='pyear',
field=models.IntegerField(blank=True, choices=[(1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)], null=True, verbose_name='year'),
),
migrations.AlterField(
model_name='emp_research_papers',
name='year',
field=models.CharField(blank=True, choices=[(1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)], max_length=10, null=True),
),
]
24 changes: 24 additions & 0 deletions FusionIIIT/applications/filetracking/api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from applications.filetracking.models import File, Tracking
from django.core.files import File as DjangoFile
from rest_framework import serializers


class FileSerializer(serializers.ModelSerializer):
class Meta:
model = File
fields = '__all__'


class TrackingSerializer(serializers.ModelSerializer):
class Meta:
model = Tracking
fields = '__all__'


class FileHeaderSerializer(serializers.ModelSerializer):
'''
This serializes everything except the attachments of a file and whether it is read or not
'''
class Meta:
model = File
exclude = ['upload_file', 'is_read']
22 changes: 22 additions & 0 deletions FusionIIIT/applications/filetracking/api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.conf.urls import url
from .views import (
CreateFileView,
ViewFileView,
DeleteFileView,
ViewInboxView,
ViewOutboxView,
ViewHistoryView,
ForwardFileView,
GetDesignationsView,
)

urlpatterns = [
url(r'^file/$', CreateFileView.as_view(), name='create_file'),
url(r'^file/(?P<file_id>\d+)/$', ViewFileView.as_view(), name='view_file'),
url(r'^file/(?P<file_id>\d+)/$', DeleteFileView.as_view(), name='delete_file'),
url(r'^inbox/$', ViewInboxView.as_view(), name='view_inbox'),
url(r'^outbox/$', ViewOutboxView.as_view(), name='view_outbox'),
url(r'^history/(?P<file_id>\d+)/$', ViewHistoryView.as_view(), name='view_history'),
url(r'^file/(?P<file_id>\d+)/$', ForwardFileView.as_view(), name='forward_file'),
url(r'^designations/(?P<username>\w+)/$', GetDesignationsView.as_view(), name='get_designations'),
]
111 changes: 111 additions & 0 deletions FusionIIIT/applications/filetracking/api/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status, permissions
from rest_framework.authentication import TokenAuthentication
from ..models import File
from ..sdk.methods import create_file, view_file, delete_file, view_inbox, view_outbox, view_history, forward_file, get_designations

class CreateFileView(APIView):
authentication_classes = [TokenAuthentication]
permission_classes = [permissions.IsAuthenticated]

def post(self, request):
try:
current_user = request.user.username
current_designation = request.data.get('designation')
receiver_username = request.data.get('receiver_username')
receiver_designation = request.data.get('receiver_designation')
subject = request.data.get('subject')
description = request.data.get('description')

if None in [current_designation, receiver_username, receiver_designation, subject, description]:
return Response({'error': 'One or more required fields are missing.'}, status=status.HTTP_400_BAD_REQUEST)

file_id = create_file(uploader=current_user, uploader_designation=current_designation,
receiver=receiver_username, receiver_designation=receiver_designation, subject=subject, description=description)

return Response({'file_id': file_id}, status=status.HTTP_201_CREATED)
except Exception as e:
return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST)


class ViewFileView(APIView):
authentication_classes = [TokenAuthentication]
permission_classes = [permissions.IsAuthenticated]

def get(self, request, file_id):
try:
file_details = view_file(int(file_id))
return Response(file_details, status=status.HTTP_200_OK)
except ValueError:
return Response({'error': 'Invalid file ID format.'}, status=status.HTTP_400_BAD_REQUEST)
except File.DoesNotExist:
return Response({'error': 'File not found.'}, status=status.HTTP_404_NOT_FOUND)
except Exception as e:
return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST)


class DeleteFileView(APIView):
#authentication_classes = [TokenAuthentication]
#permission_classes = [permissions.IsAuthenticated]

def delete(self, request, file_id, *args, **kwargs):
success = delete_file(int(file_id))
if success:
return Response({'message': 'File deleted successfully'},
status=status.HTTP_204_NO_CONTENT)
else:
return Response({'error': 'File not found'},
status=status.HTTP_404_NOT_FOUND)


class ViewInboxView(APIView):
#authentication_classes = [TokenAuthentication]
#permission_classes = [permissions.IsAuthenticated]

def get(self, request, *args, **kwargs):
inbox_files = view_inbox(
request.user.username,
request.query_params.get('designation'),
request.query_params.get('src_module'))
return Response(inbox_files)


class ViewOutboxView(APIView):
#authentication_classes = [TokenAuthentication]
#permission_classes = [permissions.IsAuthenticated]

def get(self, request, *args, **kwargs):
outbox_files = view_outbox(
request.user.username,
request.query_params.get('designation'),
request.query_params.get('src_module'))
return Response(outbox_files)


class ViewHistoryView(APIView):
#authentication_classes = [TokenAuthentication]
#permission_classes = [permissions.IsAuthenticated]

def get(self, request, file_id, *args, **kwargs):
history = view_history(int(file_id))
return Response(history)


class ForwardFileView(APIView):
#authentication_classes = [TokenAuthentication]
#permission_classes = [permissions.IsAuthenticated]

def post(self, request, file_id, *args, **kwargs):
new_tracking_id = forward_file(int(file_id), **request.data)
return Response({'tracking_id': new_tracking_id},
status=status.HTTP_201_CREATED)


class GetDesignationsView(APIView):
#authentication_classes = [TokenAuthentication]
#permission_classes = [permissions.IsAuthenticated]

def get(self, request, username, *args, **kwargs):
user_designations = get_designations(username)
return Response({'designations': user_designations})
38 changes: 38 additions & 0 deletions FusionIIIT/applications/filetracking/decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from django.shortcuts import render, get_object_or_404
from django.contrib.auth.models import User
from applications.globals.models import ExtraInfo, HoldsDesignation


def user_check(request):
"""
This function is used to check if the user is a student or not.
Its return type is bool.
@param:
request - contains metadata about the requested page

@Variables:
current_user - get user from request
user_details - extract details of the user from the database
desig_id - check for designation
student - designation for a student
final_user - final designation of the request(our user)
"""
try:
current_user = get_object_or_404(User, username=request.user.username)
user_details = ExtraInfo.objects.select_related('user','department').get(user=request.user)
des = HoldsDesignation.objects.all().select_related().filter(user=request.user).first()
if str(des.designation) == "student":
return True
else:
return False
except Exception as e:
return False

def user_is_student(view_func):
def _wrapped_view(request, *args, **kwargs):
if user_check(request):
return render(request, 'filetracking/fileTrackingNotAllowed.html')
else:
return view_func(request, *args, **kwargs)
return _wrapped_view

7 changes: 7 additions & 0 deletions FusionIIIT/applications/filetracking/filetracking/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin

# Register your models here.
from applications.filetracking.models import File, Tracking

admin.site.register(File)
admin.site.register(Tracking)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from applications.filetracking.models import File, Tracking
from django.core.files import File as DjangoFile
from rest_framework import serializers


class FileSerializer(serializers.ModelSerializer):
class Meta:
model = File
fields = '__all__'


class TrackingSerializer(serializers.ModelSerializer):
class Meta:
model = Tracking
fields = '__all__'


class FileHeaderSerializer(serializers.ModelSerializer):
'''
This serializes everything except the attachments of a file and whether it is read or not
'''
class Meta:
model = File
exclude = ['upload_file', 'is_read']
22 changes: 22 additions & 0 deletions FusionIIIT/applications/filetracking/filetracking/api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.conf.urls import url
from .views import (
CreateFileView,
ViewFileView,
DeleteFileView,
ViewInboxView,
ViewOutboxView,
ViewHistoryView,
ForwardFileView,
GetDesignationsView,
)

urlpatterns = [
url(r'^file/$', CreateFileView.as_view(), name='create_file'),
url(r'^file/(?P<file_id>\d+)/$', ViewFileView.as_view(), name='view_file'),
url(r'^file/(?P<file_id>\d+)/$', DeleteFileView.as_view(), name='delete_file'),
url(r'^inbox/$', ViewInboxView.as_view(), name='view_inbox'),
url(r'^outbox/$', ViewOutboxView.as_view(), name='view_outbox'),
url(r'^history/(?P<file_id>\d+)/$', ViewHistoryView.as_view(), name='view_history'),
url(r'^file/(?P<file_id>\d+)/$', ForwardFileView.as_view(), name='forward_file'),
url(r'^designations/(?P<username>\w+)/$', GetDesignationsView.as_view(), name='get_designations'),
]
Loading