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

refactor: urls and views #1575

Merged
merged 1 commit into from
May 3, 2024
Merged
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
1 change: 0 additions & 1 deletion FusionIIIT/applications/scholarships/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
url(r'^getConvocationFlag/$', views.getConvocationFlag, name='getConvocationFlag'),
url(r'^getContent/$', views.getContent, name='getContent'),
url(r'^updateEndDate/$', views.updateEndDate, name='updateEndDate'),
url(r'^deleteRelease/$', views.deleteRelease, name='deleteRelease'),

]
89 changes: 23 additions & 66 deletions FusionIIIT/applications/scholarships/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from operator import or_
from functools import reduce

from django.http import JsonResponse
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse, HttpResponseRedirect
Expand All @@ -24,13 +23,9 @@
from .validations import MCM_list, MCM_schema, gold_list, gold_schema, silver_list, silver_schema, proficiency_list,proficiency_schema
from jsonschema import validate
from jsonschema.exceptions import ValidationError
from .helpers import getBatch
# Create your views here.





@login_required(login_url='/accounts/login')
def spacs(request):
convener = Designation.objects.get(name='spacsconvenor')
Expand Down Expand Up @@ -75,20 +70,15 @@ def spacs(request):

@login_required(login_url='/accounts/login')
def convener_view(request):
print(request)

try:
convener = Designation.objects.get(name='spacsconvenor')
hd = HoldsDesignation.objects.get(
user=request.user, designation=convener)
except:
return HttpResponseRedirect('/logout')
if request.method == 'POST':
print("this is a check for post request")
if 'Submit' in request.POST:
print("this is a check for post xfhjgisdfkhlsjk request")
award = request.POST.get('type')
print("award " + award)
programme = request.POST.get('programme')
batch = request.POST.get('batch')
from_date = request.POST.get('From')
Expand All @@ -108,17 +98,14 @@ def convener_view(request):
)

# It updates the student Notification table on the spacs head sending the mcm invitation
if batch == 'All':
if batch == 'all':
active_batches = range(datetime.datetime.now().year - 4 , datetime.datetime.now().year + 1)

query = reduce(or_, (Q(id__id__startswith=int(batch)-2000) for batch in active_batches))
recipient = Student.objects.filter(programme=programme).filter(query)
else:
recipient = Student.objects.filter(programme=programme, id__id__startswith=int(batch)-2000)


# Notification starts
print(recipient)
convenor = request.user
for student in recipient:
scholarship_portal_notif(convenor, student.id.user, 'award_' + award) # Notification
Expand All @@ -139,9 +126,9 @@ def convener_view(request):
notification_convocation_flag=True,
invite_convocation_accept_flag=False) for student in recipient])
# Notification ends
print(batch)

messages.success(request,
award + ' applications are invited successfully for ' + str(batch) + ' batch(es)')
award + ' applications are invited successfully for ' + batch + ' batch(es)')
return HttpResponseRedirect('/spacs/convener_view')

elif 'Email' in request.POST:
Expand Down Expand Up @@ -278,7 +265,6 @@ def convener_view(request):

@login_required(login_url='/accounts/login')
def student_view(request):

if request.method == 'POST':
if 'Submit_MCM' in request.POST:
return submitMCM(request)
Expand Down Expand Up @@ -404,52 +390,37 @@ def convenerCatalogue(request):
context['result'] = 'Failure'
return HttpResponse(json.dumps(context), content_type='convenerCatalogue/json')



#below function is refactored and changed as it is not used by the user interface
#it will be changed later for other testing and download of winners
def getWinners(request):
# Extract parameters from the request
award_name = request.GET.get('award_name')
batch_year = int(request.GET.get('batch'))
programme_name = request.GET.get('programme')

# Get the Award_and_scholarship object based on the provided award name
try:
award = Award_and_scholarship.objects.get(award_name=award_name)
except Award_and_scholarship.DoesNotExist:
return JsonResponse({'result': 'Failure', 'message': 'Award not found'})

# Query for previous winners based on the provided criteria
winners = Previous_winner.objects.select_related('student__extra_info').filter(
award = Award_and_scholarship.objects.get(award_name=award_name)
winners = Previous_winner.objects.select_related('student','award_id').filter(
year=batch_year, award_id=award, programme=programme_name)
context = {}
context['student_name'] = []
context['student_program'] = []
context['roll'] = []

context = {
'result': 'Success',
'winners': [],
}

# Process the winners if any found
# If-Else Condition for previous winner if there is or no data in the winner table
if winners:
for winner in winners:
# Fetch extra information for the student
extra_info = winner.student.extra_info

extra_info = ExtraInfo.objects.get(id=winner.student_id)
student_id = Student.objects.get(id=extra_info)
student_name = extra_info.user.first_name
student_roll = winner.student_id
student_program = winner.student.programme

# Append student details to the context
context['winners'].append({
'student_name': student_name,
'roll': student_roll,
'student_program': student_program,
})
student_program = student_id.programme
context['student_name'].append(student_name)
context['roll'].append(student_roll)
context['student_program'].append(student_program)

context['result'] = 'Success'

else:
context['result'] = 'Failure'
context['message'] = 'No winners found for the provided criteria'

return JsonResponse(context)
return HttpResponse(json.dumps(context), content_type='getWinners/json')

def get_MCM_Flag(request): # Here we are extracting mcm_flag
print("get mcm_flags here")
Expand All @@ -469,7 +440,6 @@ def get_MCM_Flag(request): # Here we are extracting mcm_flag
# return HttpResponseRedirect('/spacs/student_view')

def getConvocationFlag(request): # Here we are extracting convocation_flag

print("get convo_flags here")
x = Notification.objects.filter(student_id=request.user.extrainfo.id)
for i in x:
Expand Down Expand Up @@ -521,18 +491,6 @@ def updateEndDate(request):
context['result'] = 'Failure'
return HttpResponse(json.dumps(context), content_type='updateEndDate/json')

def deleteRelease(request):
print("deleteRelease")
id = request.GET.get('id')
is_deleted = Release.objects.filter(pk=id).delete()
request.session['last_clicked'] = "Release_deleted"
context = {}
if is_deleted:
context['result'] = 'Success'
else:
context['result'] = 'Failure'
return HttpResponse(json.dumps(context), content_type='deleteRelease/json')

def getAwardId(request):
award = request.POST.get('award')
a = Award_and_scholarship.objects.get(award_name=award).id
Expand Down Expand Up @@ -1064,14 +1022,14 @@ def sendConvenerRenderRequest(request, additionalParams={}):
source = Constants.FATHER_OCC_CHOICE
time = Constants.TIME
release = Release.objects.all()
notification = Notification.objects.select_related('student_id','release_id').all()
spi = Spi.objects.all()
context.update({ 'source': source, 'time': time, 'ch': ch, 'spi': spi, 'release': release})
context.update(additionalParams)
return render(request, 'scholarshipsModule/scholarships_convener.html', context)

def sendStudentRenderRequest(request, additionalParams={}):
context = getCommonParams(request)

ch = Constants.BATCH
time = Constants.TIME
mother_occ = Constants.MOTHER_OCC_CHOICES
Expand All @@ -1091,7 +1049,6 @@ def sendStudentRenderRequest(request, additionalParams={}):
update_con_flag = False
x_notif_mcm_flag = False
x_notif_con_flag = False
student_batch = getBatch(request.user.extrainfo.student)
for dates in release:
if checkDate(dates.startdate, dates.enddate):
print("sudheer's test --->")
Expand All @@ -1102,11 +1059,11 @@ def sendStudentRenderRequest(request, additionalParams={}):
if no_of_mcm_filled > 0:
update_mcm_flag = True
elif dates.award == 'Convocation Medals' and dates.batch == "20"+str(request.user.extrainfo.student)[0:2]and dates.programme == request.user.extrainfo.student.programme:

x_notif_con_flag = True
if no_of_con_filled > 0:
update_con_flag = True
else:


if dates.award == "Merit-cum-Means Scholarship" and dates.batch =="20"+ str(request.user.extrainfo.student)[0:2]:
try:
Expand Down Expand Up @@ -1141,7 +1098,7 @@ def sendStudentRenderRequest(request, additionalParams={}):
context.update(additionalParams)
return render(request, 'scholarshipsModule/scholarships_student.html',context)

def sendStaffRenderRequest(request, additionalParams={}):
def sendStaffRenderRequest(request, additionalParams={}):
context = getCommonParams(request)
context.update(additionalParams)
return render(request, 'scholarshipsModule/scholarships_staff.html', context)
Expand Down
16 changes: 5 additions & 11 deletions FusionIIIT/templates/scholarshipsModule/applyNew.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<a class="right floated item" style="padding-left:50px" href="https://drive.google.com/open?id=1Ylcj_ZX_h-0TTZ_zOGVF1JLEJE1_YQGD" target="_blank">
<button class="ui primary button">
Form A
<i class="right floated download icon"></i>
<i class="right floated download icon"></i>
</button>
</a>
<a class="right floated item" href="https://drive.google.com/open?id=1AfSw3S5xXgbDn81hg6f2qgQiT_digXT9" target="_blank">
Expand Down Expand Up @@ -318,7 +318,7 @@
</div>
{% endif %}
{% else %}
<div class="ui button">
<div class="ui disabled button">
Applications not invited or has already been submitted
</div>
{% endif %}
Expand Down Expand Up @@ -368,7 +368,7 @@
</div>
{% endif %}
{% else %}
<div class="ui button" id="apply_convocation_btn">
<div class="ui disabled button">
Apply
</div>
{% endif %}
Expand Down Expand Up @@ -957,7 +957,7 @@
<div class="field">
<a class="right floated item">
<label><br></label>
<button type="submit" name="Submit_Silver" class="ui primary large right floated button" id="submit_silver">
<button type="submit" name="Submit_Silver" class="ui primary large right floated button">
Submit
</button>
</a>
Expand Down Expand Up @@ -1077,7 +1077,7 @@
success: function (response) {
if(response.result==='Success'){
location.reload();
console.log("reuk", response.result)
console.log(response.result)
}
else{
console.log(response.result);
Expand All @@ -1104,12 +1104,6 @@
}
});
});

$(document).on('click', '#submit_silver', function (event){
event.preventDefault();
$.ajax()
})

</script>
<script>
function dis(aval) {
Expand Down
35 changes: 1 addition & 34 deletions FusionIIIT/templates/scholarshipsModule/invite.html
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@
<td>{{ i.date_time }}</td>
<td>{{ i.programme}} - {{ i.batch }}</td>
<td> <button class="ui primary button" id = 'update_release_btn' value='{{ i.id}}'>Update</button> </td>

</tr>
{% endfor %}
</tbody>
Expand All @@ -228,17 +227,6 @@
<div class="ui cancel button">Cancel</div>
</div>
</div>
<div class="ui modal1">
<div class="header">Delete Of Application </div>
<div class="content">
<button type='date' name = 'updated_enddate' id= "enddate_up" required>
<input type="hidden" name="delete_release_id" id= "delete_release_id" value="">
</div>
<div class="actions">
<div class="ui approve button" id = "update_enddate_modal_btn">Update</div>
<div class="ui cancel button">Cancel</div>
</div>
</div>
</div>

<script>
Expand All @@ -249,28 +237,7 @@
$('.ui.modal')
.modal('show');
});
$(document).on('click','#delete_release_btn',function (event) {
event.preventDefault();
var x = $(this).val();
$.ajax({
url: '/spacs/deleteRelease/',
type: 'DELETE',
data:{
id:x,
},
success: function (response) {
if(response.result==='Success'){
location.reload();
console.log(response.result)
}
else{
console.log(response.result);
}

}
});
});
$(document).on('click','#update_enddate_modal_btn',function (event) {
$(document).on('click','#update_enddate_modal_btn',function (event) {
event.preventDefault();
var x = $('#update_release_id').val();
var y = $('#enddate_up').val();
Expand Down
Loading