From bde3420d8435f07d0d5919a117cd066aa3d3fc19 Mon Sep 17 00:00:00 2001 From: Sushanth Rao Date: Mon, 14 Dec 2020 20:52:16 +0530 Subject: [PATCH 01/11] Using cpanel branch to render JSON response - Updated ACM app views to render JSON response for all actions. - Updated SMP app views to render JSON response for all actions. Signed-off-by: Sushanth Rao --- .idea/.gitignore | 8 + .idea/ACM-Website-Revamp.iml | 18 + .idea/dataSources.xml | 11 + .../inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 7 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + SMP/views.py | 86 ++-- acm/views.py | 378 ++++++++++-------- 9 files changed, 309 insertions(+), 219 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/ACM-Website-Revamp.iml create mode 100644 .idea/dataSources.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/ACM-Website-Revamp.iml b/.idea/ACM-Website-Revamp.iml new file mode 100644 index 0000000..89c4acf --- /dev/null +++ b/.idea/ACM-Website-Revamp.iml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..6de30a7 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,11 @@ + + + + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:$PROJECT_DIR$/ACM_Website/db.sqlite3 + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..97961d1 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7a4aa57 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SMP/views.py b/SMP/views.py index 0e29470..376b6ea 100644 --- a/SMP/views.py +++ b/SMP/views.py @@ -1,42 +1,46 @@ -from django.shortcuts import render +from django.contrib.auth.hashers import make_password +from django.views.decorators.csrf import csrf_exempt + from .models import * from acm.models import * -from django.http import HttpResponse +from django.http import JsonResponse import json from .forms import * -from django.shortcuts import redirect -from django.contrib import messages def home(request, sig_id): - si = SIG.objects.filter(pk=sig_id) - sig = si[0] - sigo = SIG.objects.all() - smps = SMP.objects.filter(sig_id=sig_id) - data2= open('staticfiles/acm/json/smp.json',encoding='utf-8').read() - data2= json.loads(data2) - data = '' - for i in range(5): - if(int(data2[i]['id']) == sig_id): - data = data2[i] - contex = {'sig': sig, 'sigo': sigo, 'smps': smps,'data':data} - return render(request, 'spms.html', contex) + sig = SIG.objects.filter(pk=sig_id).values('id', 'name', 'image', 'mission_statement', 'vision_statement')[0] + sigo = all_sigs() + smps = list(SMP + .objects + .filter(sig_id=sig_id).values('id', 'sig_id', 'name', 'mentors', 'overview', 'platform_of_tutoring')) + with open('acm/static/acm/json/smp.json') as f: + data2 = json.loads(f.read()) + data = '' + for i in range(5): + if int(data2[i]['id']) == sig_id: + data = data2[i] + context = {'sig': sig, 'sigo': sigo, 'smps': smps, 'data': data} + return JsonResponse(context) def des(request, sig_id, smp_id): - smp = (SMP.objects.filter(pk=smp_id))[0] - smp_des = SMP_des.objects.filter(smp_id=smp_id) - contex = {'smp': smp, 'smp_des': smp_des} - return render(request, 'smp_des.html', contex) + smp = SMP.objects.filter(pk=smp_id).values('id', 'sig_id', 'name', 'mentors', 'overview', 'platform_of_tutoring')[0] + smp_des = list(SMP_des.objects.filter(smp_id=smp_id).values('id', 'smp_id', 'sub_heading', 'sub_des')) + context = {'smp': smp, 'smp_des': smp_des} + return JsonResponse(context) +@csrf_exempt def new_smp(request): validated = 0 static_fields = ['Name', 'Mentors', 'Overview', 'Platform'] dynammic_fields = ['Exercise', 'Prerequisite', 'Course-content'] if request.method == "POST": - password_form = PasswordForm(request.POST) - smp_form = SMPForm(request.POST) + request_params = request.body.decode('utf-8') + data = json.loads(request_params) + password_form = PasswordForm(data) + smp_form = SMPForm(data) if smp_form.is_valid(): sig = smp_form.cleaned_data["SIG"] name = smp_form.cleaned_data["Name"] @@ -44,47 +48,45 @@ def new_smp(request): overview = smp_form.cleaned_data["Overview"] platform = smp_form.cleaned_data["Platform"] SMP_object = SMP.objects.create( - sig_id=SIG.objects.get(pk=sig), name=name, mentors=mentors, overview=overview, platform_of_tutoring=platform) + sig_id=SIG.objects.get(pk=sig), name=name, + mentors=mentors, overview=overview, platform_of_tutoring=platform) SMP_object.save() for field in dynammic_fields: for i in range(smp_form.cleaned_data[field.lower() + "_freq"]): - des = smp_form.cleaned_data[field+'_' + str(i+1)] + des = smp_form.cleaned_data[field + '_' + str(i + 1)] if des: SMP_des_object = SMP_des.objects.create( smp_id=SMP_object, sub_heading=field, sub_des=des) SMP_des_object.save() for i in range(smp_form.cleaned_data["week_freq"]): - for j in range(smp_form.cleaned_data["week_"+str(i+1)+"_description_freq"]): + for j in range(smp_form.cleaned_data["week_" + str(i + 1) + "_description_freq"]): des = smp_form.cleaned_data["Week_" + - str(i+1)+"_Description_"+str(j+1)] + str(i + 1) + "_Description_" + str(j + 1)] if des: SMP_des_object = SMP_des.objects.create( - smp_id=SMP_object, sub_heading="Week "+str(i+1), sub_des=des) + smp_id=SMP_object, sub_heading="Week " + str(i + 1), sub_des=des) SMP_des_object.save() - - messages.success(request, "SMP created") - return redirect('acm:home_page') + return JsonResponse({'message': 'SMP successfully created'}, status=201) if password_form.is_valid(): - # To be hidden somehow - if password_form.cleaned_data["key"] == "s@ng@madethiz": + # TODO: Use ENV variable to store PASSWORD + if make_password(password_form.cleaned_data["key"]) == make_password("PASSWORD"): validated = 1 else: - messages.MessageFailure(request, 'Incorrect password') - - else: - password_form = PasswordForm() - smp_form = SMPForm() + JsonResponse({'message': 'Incorrect password'}, status=401) - sigo = SIG.objects.all() - context = {'password_form': password_form, - 'smp_form': smp_form, - 'validated': validated, + sigo = all_sigs() + context = {'validated': validated, 'static_fields': static_fields, 'dynammic_fields': dynammic_fields, 'range_of_8': [1, 2, 3, 4, 5, 6, 7, 8], 'sigo': sigo, } - return render(request, 'smp_form.html', context) + return JsonResponse(context) + + +# Common block +def all_sigs(): + return list(SIG.objects.all().values('id', 'name', 'image', 'mission_statement', 'vision_statement')) diff --git a/acm/views.py b/acm/views.py index 586ff3b..7061a93 100644 --- a/acm/views.py +++ b/acm/views.py @@ -1,261 +1,285 @@ -from django.shortcuts import render +from django.contrib.auth.hashers import make_password +from django.views.decorators.csrf import csrf_exempt + from .models import * from SMP.models import * import json -from django.http import HttpResponse +from django.http import JsonResponse from .forms import * -from django.contrib import messages -from django.shortcuts import redirect + def home_page(request): - events = Events.objects.all() - special_people = Special_people.objects.all() + events = list(Events.objects.all().values('id', 'sig_id', 'name', 'description')) + special_people = list( + Special_people.objects.all().values('id', 'name', 'post', 'fb_link', 'linkedin_link', 'image_path')) # opens the json file and saves the raw contents - data = open('staticfiles/acm/json/index.json',encoding='utf-8').read() - descriptions = json.loads(data) - sigo = SIG.objects.all() - context = {'events': events,'sigo': sigo, 'descriptions':descriptions,'special_people':special_people} - return render(request, 'acm/index.html', context) + sigo = all_sigs() + context = {'events': events, 'special_people': special_people, 'sigo': sigo} + return JsonResponse(context) def load_sig_contents(sig_id): - si = SIG.objects.filter(pk=sig_id) - sig = si[0] - sigo = SIG.objects.all() - events = Events.objects.filter(sig_id=sig_id) - projects = Projects.objects.filter(sig_id=sig_id) - with open('staticfiles/acm/json/yantras.json') as f: + sig = SIG.objects.filter(pk=sig_id).values('id', 'name', 'image', 'mission_statement', 'vision_statement')[0] + sigo = all_sigs() + events = list(Events.objects.filter(sig_id=sig_id).values('id', 'sig_id', 'name', 'description')) + projects = list(Projects.objects.filter(sig_id=sig_id) + .values('id', 'name', 'display_picture', 'duration_in_months', 'mentors', + 'members', 'introduction', 'method', 'results', 'obstacles', + 'conclusion', 'future_work', 'references', 'meet_link')) + with open('acm/static/acm/json/yantras.json') as f: data2 = json.loads(f.read()) - data ='' - x=len(sigo) - for i in range (x): - if(data2[i]['id']==sig_id): - data=data2[i] + data = '' + for i in range(len(sigo)): + if data2[i]['id'] == sig_id: + data = data2[i] return sig, events, projects, sigo, data + def sig_page(request, sig_id): - sig, events, _, sigo, data = load_sig_contents(sig_id) - context = {'sig': sig, 'events': events, 'sigo': sigo , 'data':data} - return render(request, 'acm/yantras.html', context) + sig, events, projects, sigo, data = load_sig_contents(sig_id) + context = {'sig': sig, 'events': events, + 'projects': projects, 'sigo': sigo, 'data': data} + return JsonResponse(context) + def expo_index(request): - context = {'sigo': SIG.objects.all()} - return render(request, 'acm/expo_index.html', context) + context = {'sigo': all_sigs()} + return JsonResponse(context) + def expo(request, sig_id): sig, _, projects, sigo, data = load_sig_contents(sig_id) context = {'projects': projects, 'sigo': sigo, - 'sig': sig} + 'sig': sig} + + return JsonResponse(context) - return render(request, 'acm/expo.html', context) def project(request, project_id): - context = {'project': Projects.objects.get(id=project_id), - 'sigo': SIG.objects.all(), - 'pictures': ProjectPictures.objects.filter(project_id=project_id)} - return render(request, 'acm/project.html', context) + context = {'project': Projects.objects.filter(id=project_id) + .values('id', 'name', 'display_picture', 'duration_in_months', 'mentors', + 'members', 'introduction', 'method', 'results', 'obstacles', + 'conclusion', 'future_work', 'references', 'meet_link')[0], + 'sigo': all_sigs(), + 'pictures': list(ProjectPictures.objects.filter(project_id=project_id) + .values('id', 'project_id', 'picture', 'title'))} + return JsonResponse(context) + def proposal_index(request): - context = {'sigo': SIG.objects.all()} - return render(request, 'acm/proposal_index.html', context) + context = {'sigo': all_sigs()} + return JsonResponse(context) + def all_proposals(request, sig_id): - context = {'projects': Proposals.objects.filter(sig_id = sig_id), - 'sigo': SIG.objects.all(), - 'sig': SIG.objects.get(id=sig_id)} + context = {'projects': list(Proposals.objects.filter(sig_id=sig_id) + .values('id', 'sig_id', 'name', 'duration_in_months', 'mentors', 'members', + 'introduction', 'method', 'existing_work', 'application', 'references')), + 'sigo': all_sigs(), + 'sig': + SIG.objects.filter(id=sig_id).values('id', 'name', 'image', 'mission_statement', 'vision_statement')[ + 0]} + + return JsonResponse(context) - return render(request, 'acm/all_proposals.html', context) def proposal(request, proposal_id): - print(proposal_id) - context = {'project': Proposals.objects.get(id=proposal_id), - 'sigo': SIG.objects.all()} + context = {'project': Proposals.objects.filter(id=proposal_id) + .values('id', 'sig_id', 'name', 'duration_in_months', 'mentors', 'members', + 'introduction', 'method', 'existing_work', 'application', 'references')[0], + 'sigo': all_sigs()} + + return JsonResponse(context) - return render(request,'acm/proposal.html', context) def manage(request, sig_id): sig, events, projects, sigo, data = load_sig_contents(sig_id) context = {'sig': sig, 'events': events, - 'projects': projects, 'sigo': sigo , 'data':data, 'smps':SMP.objects.filter(sig_id=sig_id)} - return render(request, 'acm/manage.html', context) + 'projects': projects, 'sigo': sigo, 'data': data, + 'smps': + list(SMP.objects + .filter(sig_id=sig_id).values('id', 'sig_id', 'name', 'mentors', 'overview', + 'platform_of_tutoring')) + } + return JsonResponse(context) + -def delete_component(request,type,id): - valid=0 +@csrf_exempt +def delete_component(request, type, id): + valid = 0 if request.method == "POST": - password_form=PasswordForm(request.POST) + request_params = request.body.decode('utf-8') + data = json.loads(request_params) + password_form = PasswordForm(data) if password_form.is_valid(): - if password_form.cleaned_data["key"] == "s@ng@madethiz": + if make_password(password_form.cleaned_data["key"]) == make_password("PASSWORD"): valid = 1 - if type=="projects": + if type == "projects": try: Projects.objects.get(id=id).delete() - messages.success(request, "Project deleted") + return JsonResponse({'message': 'Project successfully deleted'}, status=204) except: - messages.MessageFailure(request, "Couldn't delete project") - elif type=="events": + return JsonResponse({'message': "Couldn't delete project"}, status=422) + elif type == "events": try: Events.objects.get(id=id).delete() - messages.success(request, "Event deleted") + return JsonResponse({'message': 'Event successfully deleted'}, status=204) except: - messages.MessageFailure(request, "Couldn't delete event") - elif type=="smp": + return JsonResponse({'message': "Couldn't delete event"}, status=422) + elif type == "smp": try: SMP.objects.get(id=id).delete() - messages.success(request, "SMP deleted") + return JsonResponse({'message': 'SMP successfully deleted'}, status=204) except: - messages.MessageFailure(request, "Couldn't delete SMP") - - return redirect('acm:home_page') + return JsonResponse({'message': "Couldn't delete SMP"}, status=422) else: - messages.MessageFailure(request, 'Incorrect password') + return JsonResponse({'message': 'Incorrect password'}, status=401) else: - messages.MessageFailure(request, 'Incorrect password') - else: - password_form=PasswordForm() - sigo = SIG.objects.all() - context={ 'sigo':sigo, 'password_form':password_form ,'valid':valid } - return render(request,'acm/projects_form.html',context) + return JsonResponse({'message': 'Incorrect password'}, status=401) + sigo = all_sigs() + context = {'sigo': sigo, 'valid': valid} + return JsonResponse(context) def contact_us(request): - sigo = SIG.objects.all() + sigo = all_sigs() context = {'sigo': sigo} - return render(request, 'acm/contact_us.html', context) + return JsonResponse(context) def esp(request): - sigo = SIG.objects.all() + sigo = all_sigs() context = {'sigo': sigo} - return render(request, 'acm/esp.html', context) + return JsonResponse(context) + +@csrf_exempt def new_project(request): - valid=0 + valid = 0 if request.method == "POST": - project_form=Projectform(request.POST) - password_form=PasswordForm(request.POST) + request_params = request.body.decode('utf-8') + data = json.loads(request_params) + project_form = Projectform(data) + password_form = PasswordForm(data) if project_form.is_valid(): - sig=project_form.cleaned_data["SIG"] - name=project_form.cleaned_data["Name"] - des=project_form.cleaned_data["Description"] - rep_link=project_form.cleaned_data["Report_link"] - pos_link=project_form.cleaned_data["Poster_link"] - project_obj=Projects.objects.create(sig_id=SIG.objects.get(pk=sig),name=name,description=des,report_link=rep_link,poster_link=pos_link) + sig = project_form.cleaned_data["SIG"] + name = project_form.cleaned_data["Name"] + des = project_form.cleaned_data["Description"] + rep_link = project_form.cleaned_data["Report_link"] + pos_link = project_form.cleaned_data["Poster_link"] + project_obj = Projects.objects.create(sig_id=SIG.objects.get(pk=sig), name=name, description=des, + report_link=rep_link, poster_link=pos_link) project_obj.save() - messages.success(request, "Project successfully added") - return redirect('/acm/') + # TODO: Check if redirect should be there (or) render a successful message + return JsonResponse({'message': 'Project successfully added'}, status=201) + # TODO: Check code logic if password_form.is_valid(): - if password_form.cleaned_data["key"] == "s@ng@madethiz": + # TODO: Use ENV variable to set PASSWORD + if make_password(password_form.cleaned_data["key"]) == make_password("PASSWORD"): valid = 1 else: - messages.MessageFailure(request, 'Incorrect password') - else : - password_form=PasswordForm() - project_form=Projectform() - sigo = SIG.objects.all() - context={ 'sigo':sigo, 'project_form':project_form, 'password_form':password_form ,'valid':valid } - return render(request,'acm/projects_form.html',context) + return JsonResponse({'message': 'Incorrect Password'}, status=401) + sigo = all_sigs() + context = {'sigo': sigo, 'valid': valid} + return JsonResponse(context) + +@csrf_exempt def new_event(request): - valid=0 - if request.method=="POST": - event_form=EventsForm(request.POST) - password_form=PasswordForm(request.POST) + valid = 0 + if request.method == "POST": + request_params = request.body.decode('utf-8') + data = json.loads(request_params) + event_form = EventsForm(data) + password_form = PasswordForm(data) if event_form.is_valid(): - sig=event_form.cleaned_data["SIG"] - name=event_form.cleaned_data["Name"] - des=event_form.cleaned_data["Description"] - event_obj=Events.objects.create(sig_id=SIG.objects.get(pk=sig),name=name,description=des) + sig = event_form.cleaned_data["SIG"] + name = event_form.cleaned_data["Name"] + des = event_form.cleaned_data["Description"] + event_obj = Events.objects.create(sig_id=SIG.objects.get(pk=sig), name=name, description=des) event_obj.save() - messages.success(request, "Event successfully added") - return redirect('/acm/') + # TODO: Check if redirect should be there (or) render a successful message + return JsonResponse({'message': 'Event successfully added'}, status=201) if password_form.is_valid(): - if password_form.cleaned_data["key"] == "s@ng@madethiz": + # TODO: Use ENV variable to store PASSWORD + if make_password(password_form.cleaned_data["key"]) == make_password("PASSWORD"): valid = 1 else: - messages.MessageFailure(request, 'Incorrect password') - else : - password_form=PasswordForm() - event_form=EventsForm() - sigo = SIG.objects.all() - context={ 'sigo':sigo, 'event_form':event_form, 'password_form':password_form ,'valid':valid } - return render(request,'acm/event_form.html',context) - - -def update_event(request,event_id): - valid=0 - if request.method=="POST": - event_form=EventsForm(request.POST) - password_form=PasswordForm(request.POST) + return JsonResponse({'message': 'Incorrect Password'}, status=401) + sigo = all_sigs() + context = {'sigo': sigo, 'valid': valid} + return JsonResponse(context) + + +@csrf_exempt +def update_event(request, event_id): + valid = 0 + if request.method == "POST": + request_params = request.body.decode('utf-8') + data = json.loads(request_params) + event_form = EventsForm(data) + password_form = PasswordForm(data) if event_form.is_valid(): - sig=event_form.cleaned_data["SIG"] - name=event_form.cleaned_data["Name"] - des=event_form.cleaned_data["Description"] - event_obj=Events.objects.create(sig_id=SIG.objects.get(pk=sig),name=name,description=des) - event_obj.save() - Events.objects.get(pk=event_id).delete() - messages.success(request, "Event successfully added") - return redirect('/acm/') + sig = event_form.cleaned_data["SIG"] + name = event_form.cleaned_data["Name"] + des = event_form.cleaned_data["Description"] + Events.objects.filter(pk=event_id).update(sig_id=SIG.objects.get(pk=sig), name=name, description=des) + # TODO: Check if redirect should be there (or) render a successful message + return JsonResponse({'message': 'Event successfully updated'}, status=201) if password_form.is_valid(): - if password_form.cleaned_data["key"] == "s@ng@madethiz": + # TODO: Use ENV variable to store PASSWORD + if make_password(password_form.cleaned_data["key"]) == make_password("PASSWORD"): valid = 1 else: - messages.MessageFailure(request, 'Incorrect password') - else : - password_form=PasswordForm() - sigo = SIG.objects.all() + return JsonResponse({'message': 'Incorrect Password'}, status=401) + sigo = all_sigs() events = Events.objects.get(pk=event_id) - s=[] - s.append(events.name) - s.append(events.description) - event_form=EventsForm(initial={'SIG':events.sig_id}) - context={ - 'sigo':sigo, - 'event_form':event_form, - 'password_form':password_form , - 'valid':valid, - 's':s, - } - return render(request,'acm/event_form.html',context) - -def update_project(request,project_id): - valid=0 - if request.method=="POST": - project_form=Projectform(request.POST) - password_form=PasswordForm(request.POST) + s = [events.id, events.sig_id.id, events.name, events.description] + context = { + 'sigo': sigo, + 'valid': valid, + 's': s, + } + return JsonResponse(context) + + +@csrf_exempt +def update_project(request, project_id): + valid = 0 + if request.method == "POST": + request_params = request.body.decode('utf-8') + data = json.loads(request_params) + project_form = Projectform(data) + password_form = PasswordForm(data) if project_form.is_valid(): - sig=project_form.cleaned_data["SIG"] - name=project_form.cleaned_data["Name"] - des=project_form.cleaned_data["Description"] - rep_link=project_form.cleaned_data["Report_link"] - pos_link=project_form.cleaned_data["Poster_link"] - project_obj=Projects.objects.create(sig_id=SIG.objects.get(pk=sig),name=name,description=des,report_link=rep_link,poster_link=pos_link) - project_obj.save() - Projects.objects.get(pk=project_id).delete() - messages.success(request, "Project successfully added") - return redirect('/acm/') + sig = project_form.cleaned_data["SIG"] + name = project_form.cleaned_data["Name"] + des = project_form.cleaned_data["Description"] + rep_link = project_form.cleaned_data["Report_link"] + pos_link = project_form.cleaned_data["Poster_link"] + Projects.objects.filter(pk=project_id).update(sig_id=SIG.objects.get(pk=sig), name=name, description=des, + report_link=rep_link, poster_link=pos_link) + # TODO: Check if redirect should be there (or) render a successful message + return JsonResponse({'message': 'Project successfully updated'}) if password_form.is_valid(): - if password_form.cleaned_data['key']=="s@ng@madethiz": - valid=1 + # TODO: Use ENV variable to store PASSWORD + if make_password(password_form.cleaned_data["key"]) == make_password("PASSWORD"): + valid = 1 else: - messages.MessageFailure(request,'Incorrect password') - else: - password_form=PasswordForm() - sigo=SIG.objects.all() - project=Projects.objects.get(pk=project_id) - s=[] - s.append(project.name) - s.append(project.description) - s.append(project.report_link) - s.append(project.poster_link) - project_form=Projectform(initial={'SIG':project.sig_id}) - context={ - 'sigo':sigo, - 'project_form':project_form, - 'password_form':password_form , - 'valid':valid, - 's':s, - } - return render(request,'acm/projects_form.html',context) + return JsonResponse({'message': 'Incorrect Password'}, status=401) + sigo = all_sigs() + project = Projects.objects.get(pk=project_id) + s = [project.id, project.sig_id.id, project.name, project.description, project.report_link, project.poster_link] + context = { + 'sigo': sigo, + 'valid': valid, + 's': s, + } + return JsonResponse(context) + +# Common block +def all_sigs(): + return list(SIG.objects.all().values('id', 'name', 'image', 'mission_statement', 'vision_statement')) From 54c92162895c56ddd3d5a706ef39d8f5d1172ad6 Mon Sep 17 00:00:00 2001 From: Sushanth Rao Date: Mon, 14 Dec 2020 20:57:04 +0530 Subject: [PATCH 02/11] Removed editor files --- .gitignore | 3 ++- .idea/.gitignore | 8 -------- .idea/ACM-Website-Revamp.iml | 18 ------------------ .idea/dataSources.xml | 11 ----------- .idea/inspectionProfiles/profiles_settings.xml | 6 ------ .idea/misc.xml | 7 ------- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 8 files changed, 2 insertions(+), 65 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/ACM-Website-Revamp.iml delete mode 100644 .idea/dataSources.xml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index ae1831e..7886843 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ __pycache__/ *__pycache__ .vscode/ venv/ -*.pyc \ No newline at end of file +*.pyc +.idea \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 73f69e0..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/ACM-Website-Revamp.iml b/.idea/ACM-Website-Revamp.iml deleted file mode 100644 index 89c4acf..0000000 --- a/.idea/ACM-Website-Revamp.iml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml deleted file mode 100644 index 6de30a7..0000000 --- a/.idea/dataSources.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - sqlite.xerial - true - org.sqlite.JDBC - jdbc:sqlite:$PROJECT_DIR$/ACM_Website/db.sqlite3 - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 97961d1..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 7a4aa57..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 8ca6b7a83d4308f05d79aa84fdebd53989812d8c Mon Sep 17 00:00:00 2001 From: Sushanth Rao Date: Mon, 25 Jan 2021 11:15:05 +0530 Subject: [PATCH 03/11] Add SMP form link to admin page - Added add_smp action url in admin - Disabled permission of admin users to add SMPs using default action of django admin - Extended admin/index.html to insert Add SMP link in Django admin - Added code to retrieve environment variables to check for password - ENV variable named as PASSWORD Signed-off-by: Sushanth Rao --- SMP/admin.py | 23 ++++++++++++++++--- SMP/templates/admin/index.html | 10 +++++++++ SMP/templates/smp_form.html | 26 +++++++--------------- SMP/urls.py | 4 +--- SMP/views.py | 40 +++++++++++++++------------------- acm/views.py | 20 +++++------------ 6 files changed, 62 insertions(+), 61 deletions(-) create mode 100644 SMP/templates/admin/index.html diff --git a/SMP/admin.py b/SMP/admin.py index 22236db..a9e9beb 100644 --- a/SMP/admin.py +++ b/SMP/admin.py @@ -1,6 +1,23 @@ from django.contrib import admin -from acm.models import SIG +from django.urls import path from .models import * +from SMP.views import new_smp -admin.site.register(SMP) -admin.site.register(SMP_des) + +@admin.register(SMP) +class SMPAdmin(admin.ModelAdmin): + def has_add_permission(self, request): + return False + + def get_urls(self): + urls = super().get_urls() + urls = [ + path('add_smp/', self.admin_site.admin_view(new_smp)) + ] + urls + return urls + + +@admin.register(SMP_des) +class SMP_desAdmin(admin.ModelAdmin): + def has_add_permission(self, request): + return False diff --git a/SMP/templates/admin/index.html b/SMP/templates/admin/index.html new file mode 100644 index 0000000..bfbfb62 --- /dev/null +++ b/SMP/templates/admin/index.html @@ -0,0 +1,10 @@ +{% extends "admin/index.html" %} + +{% block content %} + +{{ block.super }} +{% endblock %} \ No newline at end of file diff --git a/SMP/templates/smp_form.html b/SMP/templates/smp_form.html index 5aa7edf..4809e03 100644 --- a/SMP/templates/smp_form.html +++ b/SMP/templates/smp_form.html @@ -33,8 +33,6 @@ {% endblock %} {% block content %}




- - {% if validated %}
{% csrf_token %} @@ -47,8 +45,8 @@ {% for f in smp_form %} {% if f.name in static_fields %}
-
- +
+
@@ -57,16 +55,16 @@ {% endif %} {% endfor %} - {% for field in dynammic_fields %} -
+ {% for field in dynamic_fields %} +

{{field}}

{% for f in smp_form %} {% if field in f.name %} {% if f.is_hidden %} -