def loginpage_view(request, *args, **kwargs): if request.method == "GET": zo = checksession(request) if zo != None: return (zo) else: return (renlogin(request, None)) try: aaw = request.POST['logout'] except: aaw = "Login" if request.method == "POST" and aaw != "true" and aaw != "Logout": un = request.POST['username'] pss = request.POST['password'] try: from user.models import user au = user.objects.get(username=un) except: print("user boject not found !") exit() if au != None and str(au.password) == str(pss): request.session['user'] = str(un) return (checksession(request)) else: return (renlogin(request, "Username or Password is Incorrect !")) else: try: request.session['user'] except: request.session['user'] = None del request.session['user'] return (renlogin(request, "Loged Out Successfuly !"))
def co_ord_panel(request,*args,**kwargs): context={} if request.method == "GET" : mutable = request.GET._mutable request.GET._mutable = True try: x=user.objects.get(username=request.session['user']).ucode except: x=0 request.GET['mcode']=x request.GET._mutable = mutable c=checksession(request) if c!='here': return(renlogin(request,None)) instance=mentordetails(request) print(type(instance)) from django.forms.models import model_to_dict b=model_to_dict(instance, fields=[field.name for field in instance._meta.fields]) bb={} print(b) for ar in b: if ar=="dcode": if b.get('dcode')!=None: from department.models import department try:dept=department.objects.get(dcode=b.get('dcode')).name except: print("department object not found !") exit() else: dept="Has not been alloted " bb["Department"]=dept elif ar=="mcode": bb["Mentor Code"]=b.get('mcode') else: bb[ar]=b.get(ar) context['mcode']=b.get('mcode') context['details']=bb context['user']=request.session['user'] if 'resp' in request.session: context['expt']=request.session['resp'] del request.session['resp'] else: context['expt']=None #image Check if not provide form import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) from mentor.forms import imageform img1=str(BASE_DIR)+'/static/mentor/'+str(b.get('mcode'))+".jpg" img2=str(BASE_DIR)+'/static/mentor/'+str(b.get('mcode'))+".jpeg" img3=str(BASE_DIR)+'/static/mentor/'+str(b.get('mcode'))+".png" img4=str(BASE_DIR)+'/static/mentor/'+str(b.get('mcode'))+".gif" from django.core.files.storage import default_storage if default_storage.exists(img1) or default_storage.exists(img2) or default_storage.exists(img3) or default_storage.exists(img4):print("") else: form=imageform() context['form']=form return(render(request,"co_ordinator.html",context)) if request.method == "POST" : from mentor.forms import imageform from mentor.models import mentor try: m=user.objects.get(username=request.session['user']) z=mentor.objects.get(mcode=m.ucode) except: print("user boject not found !") exit() form = imageform(request.POST, request.FILES ,instance=z) if form.is_valid(): m.img = form.cleaned_data['img'] x=form.save() resp="Image Uploaded successfuly !" request.session['resp']=resp return(redirect("/co_ordinator/")) else: aa=form.errors request.session['resp']=str(aa) return(redirect("/co_ordinator/"))
def traineepanel_view(request, *args, **kwargs): context = {} if request.method == "GET": mutable = request.GET._mutable request.GET._mutable = True try: x = user.objects.get(username=request.session['user']).ucode except: x = 0 request.GET['tcode'] = x request.GET._mutable = mutable c = checksession(request) if c != 'here': return (renlogin(request, None)) instance = traineedetails(request) from django.forms.models import model_to_dict b = model_to_dict( instance, fields=[field.name for field in instance._meta.fields]) bb = {} for ar in b: if ar == "tcode": bb["Trainee Code"] = b.get('tcode') elif ar == "fname": bb["Father Name"] = b.get('fname') elif ar == "mname": bb["Mother Name"] = b.get('mname') elif ar == "dur": bb["Duration of Internship"] = b.get('dur') elif ar == "dcode": if b.get('dcode') != None: from department.models import department try: dept = department.objects.get( dcode=b.get('dcode')).name except: print("department object not found !") exit() else: dept = "Has not been alloted " bb["Department"] = dept elif ar == "gcode": if b.get('gcode') != None: bb['Group'] = b.get('gcode') else: bb['Group'] = "Has not been alloted " elif ar == "mcode": if b.get('mcode') != None: from mentor.models import mentor try: ment = mentor.objects.get(mcode=b.get('mcode')).name except: print("mentor object not found !") exit() else: ment = "Has not been alloted " bb["Mentor"] = ment elif ar == "proj": if b.get('proj') != None: bb['Project/Study'] = b.get('ar') else: bb['Project/Study'] = "Has not been alloted " elif ar == "rep_date": if str(b.get('rep_date')) != 'None': bb['Reporting Date'] = b.get('rep_date') else: bb['Reporting Date'] = "Not Available" elif ar == "proj_assign_date": if str(b.get('proj_assign_date')) != 'None': bb['Project Assignemnt Date'] = b.get('proj_assign_date') else: bb['Project Assignement Date'] = "Not Available" elif ar == "proj_sub_date": if str(b.get('proj_sub_date')) != 'None': bb['Project Submission Date'] = b.get('proj_sub_date') else: bb['Project Submission Date'] = "Not Available" else: bb[ar] = b.get(ar) context['tcode'] = b.get('tcode') context['details'] = bb context['user'] = request.session['user'] if 'resp' in request.session: context['expt'] = request.session['resp'] del request.session['resp'] else: context['expt'] = None #image Check if not provide form import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) from trainee.forms import imageform img1 = str(BASE_DIR) + '/static/trainee/' + str( b.get('tcode')) + ".jpg" img2 = str(BASE_DIR) + '/static/trainee/' + str( b.get('tcode')) + ".jpeg" img3 = str(BASE_DIR) + '/static/trainee/' + str( b.get('tcode')) + ".png" img4 = str(BASE_DIR) + '/static/trainee/' + str( b.get('tcode')) + ".gif" from django.core.files.storage import default_storage if default_storage.exists(img1) or default_storage.exists( img2) or default_storage.exists( img3) or default_storage.exists(img4): print("") else: form = imageform() context['form'] = form return (render(request, "trainee.html", context)) if request.method == "POST": from trainee.forms import imageform from trainee.models import trainee try: m = user.objects.get(username=request.session['user']) z = trainee.objects.get(tcode=m.ucode) except: print("user boject not found !") exit() form = imageform(request.POST, request.FILES, instance=z) if form.is_valid(): m.img = form.cleaned_data['img'] x = form.save() resp = "Image Uploaded successfuly !" request.session['resp'] = resp return (redirect("/trainee/")) else: aa = form.errors request.session['resp'] = str(aa) return (redirect("/trainee/"))
def clearance_view(request, *args, **kwargs): if request.method == "GET": from mentor.models import mentor mutable = request.GET._mutable request.GET._mutable = True try: x = user.objects.get(username=request.session['user']).ucode y = user.objects.get(username=request.session['user']).utype except: x = 0 y = 0 if y == 'T': request.GET['tcode'] = x else: request.GET['tcode'] = None if y == 'M' or y == 'C': request.GET['mcode'] = x try: co_ord = str(mentor.objects.get(mcode=x).co_ord) except: co_ord = '0' else: request.GET['mcode'] = None request.GET['mecode'] = x request.GET['metype'] = y request.GET._mutable = mutable c = checksession(request) if c != 'here': return (c) context = {} context['alert'] = 'None' context['user'] = request.session['user'] if str(request.GET['metype']) == 'T': aou = getclrdata(request, str(request.GET['mecode'])) if aou != None: context = {**context, **aou} from trainee.models import trainee try: xo = trainee.objects.get( tcode=str(request.POST['mecode'])).name except: xo = None print("no trainee") context['ofcname'] = str(xo) return (render(request, "clearance.html", context)) else: return (HttpResponse("Project Not Submitted Yet !")) if str(request.GET['metype']) == 'M' or str( request.GET['metype']) == 'C': context['rtype'] = 'M' context['req'] = 'None' try: from crequests.models import crequests from clearance.models import clearance from trainee.models import trainee inko = clearance.objects.get(mcode=str(request.GET['mecode'])) context['clname'] = inko.cname ati = crequests.objects.filter(ccode=str( inko.ccode), status=2) | crequests.objects.filter( ccode=str( clearance.objects.get( mcode=str(request.GET['mecode'])).ccode), status=0) if len(ati) > 0: context['clrof'] = {} for ayq in ati: nm = trainee.objects.get(tcode=ayq.tcode).name context['clrof'][nm] = str(ayq.tcode) else: context['clrof'] = "None" #extras for co-ordinator: context['tdlst'] = 'None' if request.GET['metype'] == "C" or co_ord == '1': from crequests.models import crequests from trainee.models import trainee cti = crequests.objects.filter() if len(cti) > 0: context['tdlst'] = {} for sl in cti: context['tdlst'][str(sl.tcode)] = str( trainee.objects.get(tcode=str(sl.tcode)).name) else: context['tdlst'] = 'None' return (render(request, "clearance.html", context)) except: return (redirect("/login/")) if request.method == 'POST': pd = {} for key, value in request.POST.items(): pd[key] = value mutable = request.POST._mutable request.POST._mutable = True try: x = user.objects.get(username=request.session['user']).ucode y = user.objects.get(username=request.session['user']).utype except: x = 0 y = 0 if y == 'T': request.POST['tcode'] = x else: request.POST['tcode'] = None if y == 'M' or y == 'C': request.POST['mcode'] = x try: co_ord = str(mentor.objects.get(mcode=x).co_ord) except: co_ord = '0' else: request.POST['mcode'] = None try: request.POST['makerequest'] except: request.POST['makerequest'] = None mr = request.POST['makerequest'] try: request.POST['requestresponse'] except: request.POST['requestresponse'] = None rr = request.POST['requestresponse'] try: request.POST['checkclearance'] except: request.POST['checkclearance'] = None chc = request.POST['checkclearance'] request.POST['mecode'] = x request.POST['metype'] = y request.POST._mutable = mutable c = checksession(request) if c != 'here': return (c) context = {} context['alert'] = "None" context['user'] = request.session['user'] if mr != None: from crequests.models import crequests from clearance.models import clearance try: apo = clearance.objects.filter() except: apo = None if apo != None and len(apo) > 0: for ak in apo: try: crequests.objects.create(ccode=ak.ccode, tcode=str( request.POST['mecode']), status=2) except: print("Can't Create request !") context['alert'] = "Request Made !" context['rtype'] = "T" aou = getclrdata(request, str(request.POST['mecode'])) if aou != None: context = {**context, **aou} from trainee.models import trainee try: xo = trainee.objects.get( tcode=str(request.POST['mecode'])).name except: xo = None print("no trainee") context['ofcname'] = str(xo) return (render(request, "clearance.html", context)) else: return (HttpResponse("Project Not Submitted Yet !")) else: return (HttpResponse("No Clearances to be requested !")) if rr != None: from clearance.models import clearance from crequests.models import crequests del pd['csrfmiddlewaretoken'] del pd['requestresponse'] for ax in pd: tcde = ax.split("-")[1] sts = pd[ax] try: ccd = str( clearance.objects.get( mcode=request.POST['mecode']).ccode) crequests.objects.filter(ccode=ccd, tcode=tcde).update(status=sts) context['alert'] = 'Done!' except: print("Can't update Clearance !") context['alert'] = 'Not Done!' return (redirect("/clearance/")) if chc != None: aou = getclrdata(request, str(request.POST['ofc'])) if aou != None: context = {**context, **aou} context['ofcname'] = str(request.POST['ofcname']) return (render(request, "clearance.html", context)) else: return (HttpResponse("Project Not Submitted Yet !"))
def sendto_view(request, *args, **kwargs): context = {} if request.method == "GET": try: request.GET['msgs'] except: mutable = request.GET._mutable request.GET._mutable = True request.GET['msgs'] = None request.GET._mutable = mutable if request.GET['msgs'] == "" or request.GET['msgs'] == None: mutable = request.GET._mutable request.GET._mutable = True try: x = user.objects.get(username=request.session['user']) except: request.session['user'] = None return (redirect('/login/')) try: request.GET['tocode'] except: request.GET['tocode'] = None try: request.GET['totype'] except: request.GET['totype'] = None if x.utype == "T": request.GET['tcode'] = x.ucode request.GET['metype'] = 'T' request.GET['mecode'] = x.ucode else: request.GET['tcode'] = None request.GET['metype'] = None request.GET['mecode'] = None if x.utype == "M": request.GET['mcode'] = x.ucode request.GET['metype'] = 'M' request.GET['mecode'] = x.ucode from mentor.models import mentor try: cor = mentor.objects.get(mcode=x.ucode).co_ord except: print("Mentor object not found") if str(cor) == "1": request.GET['co_ord'] = 1 request.GET['metype'] = 'C' if str(cor) == "0": request.GET['co_ord'] = 0 request.GET['metype'] = 'M' else: request.GET['mcode'] = None request.GET['co_ord'] = 0 request.GET._mutable = mutable try: c = checksession(request) except: print(c) checksession(request) from trainee.models import trainee from mentor.models import mentor #trainee msgs if request.GET['tcode'] != None: try: trq = trainee.objects.get(tcode=request.GET['tcode']) except: print("traine object not found !") try: from group.models import group if str(request.GET['co_ord']) == '1': agrps = group.objects.filter().order_by('-gcode') else: agrps = group.objects.filter( mcode=request.GET['mecode']).order_by('-gcode') except: print("group object not found !") grp = [] if request.GET['tcode'] != None: grp.append("G-" + str(trq.gcode)) ment = [] if request.GET['mcode'] != None: for qweq in agrps: grp.append("G-" + str(qweq.gcode)) if request.GET['tcode'] != None: menti = "M-" + str(trq.mcode) try: mentnamei = str( mentor.objects.get( mcode=str(trq.mcode)).name) + " (Mentor)" except: mentnamei = None if mentnamei != None: nal = (menti, mentnamei) ment.append(nal) if request.GET['mcode'] != None: try: mni = mentor.objects.filter().order_by('-name') except: print("mentors object not found") for aer in mni: menti = "M-" + str(aer.mcode) mentnamei = str(aer.name) + " (Mentor)" nal = (menti, mentnamei) ment.append(nal) from mentor.models import mentor try: from mentor.models import mentor ghi = mentor.objects.filter(co_ord=1)[0] except: ghi = None if ghi != None: cord = "C-" + str(ghi.mcode) if str(request.GET['co_ord']) == '0': cordname = str(ghi.name) + " (Co-ordinator)" else: cordname = None else: cord = None context['optionto'] = {} if len(grp) > 0: if request.GET['tcode'] != None: context['optionto'][grp[0]] = "Own Group" else: for qm in grp: context['optionto'][qm] = str( qm.split('-')[1]) + "-(Group)" if len(ment) > 0: if request.GET['tcode'] != None: context['optionto'][ment[0][0]] = ment[0][1] if request.GET['mcode'] != None: for opc in ment: a = opc[0].split('-') try: if str(mentor.objects.get(mcode=a[1]).co_ord ) != '1' and a[1] != request.GET['mecode']: context['optionto'][opc[0]] = opc[1] except: print("no object of user") exit() if cord != None and cordname != None: context['optionto'][cord] = cordname #fellow trainee def stuofgrp(grpc): if grpc != None: try: return (trainee.objects.filter( gcode=grpc).order_by('-name')) except: print("trainee object not found") #for trainees if request.GET['tcode'] != None: nxi = stuofgrp(trq.gcode) #trainee to list for mentors if request.GET['mcode'] != None: if request.GET['metype'] == 'C': try: nxi = trainee.objects.filter().order_by('-name') except: print("co_ord but still cant find trainee") else: mbo = 1 for qm in grp: zli = stuofgrp(qm.split('-')[1]) if mbo == 1: nxi = zli else: nxi = nxi | zli mbo = mbo + 1 zx = [] tcodeq = "" tnameq = "" try: nxi except: nxi = "" if str(type(nxi)) == "<class 'django.db.models.query.QuerySet'>": for i in range(0, len(nxi)): try: tcodeq = "T-" + str(nxi[i].tcode) except: print("Trainee object not found !") try: tnameq = str(nxi[i].name) + " (Trainee)" except: tnameq = None cx = (tcodeq, tnameq) if tcodeq != "T-" + str(request.GET['tcode']): zx.append(cx) for zq in zx: context['optionto'][zq[0]] = zq[1] zx = [] tcodeq = "" tnameq = "" try: context['optiontoselected'] = str( request.GET['totype']) + "-" + str(request.GET['tocode']) except: context['optiontoselected'] = None return (render(request, "sendto.html", context))
def message_view(request, *args, **kwargs): context = {} if request.method == "GET": try: request.GET['msgs'] except: mutable = request.GET._mutable request.GET._mutable = True request.GET['msgs'] = None request.GET._mutable = mutable if request.GET['msgs'] == "" or request.GET['msgs'] == None: mutable = request.GET._mutable request.GET._mutable = True try: x = user.objects.get(username=request.session['user']) except: request.session['user'] = None return (redirect('/login/')) try: request.GET['tocode'] except: request.GET['tocode'] = None try: request.GET['totype'] except: request.GET['totype'] = None if x.utype == "T": request.GET['tcode'] = x.ucode request.GET['metype'] = 'T' request.GET['mecode'] = x.ucode else: request.GET['tcode'] = None request.GET['metype'] = None request.GET['mecode'] = None if x.utype == "M": request.GET['mcode'] = x.ucode request.GET['metype'] = 'M' request.GET['mecode'] = x.ucode from mentor.models import mentor try: cor = mentor.objects.get(mcode=x.ucode).co_ord except: print("Mentor object not found") if str(cor) == "1": request.GET['co_ord'] = 1 request.GET['metype'] = 'C' if str(cor) == "0": request.GET['co_ord'] = 0 request.GET['metype'] = 'M' else: request.GET['mcode'] = None request.GET['co_ord'] = 0 request.GET._mutable = mutable c = checksession(request) from trainee.models import trainee from mentor.models import mentor #trainee msgs if request.GET['tcode'] != None: try: trq = trainee.objects.get(tcode=request.GET['tcode']) except: print("traine object not found !") try: from group.models import group agrps = group.objects.filter().order_by('-gcode') except: print("group object not found !") grp = [] if request.GET['tcode'] != None: grp.append("G-" + str(trq.gcode)) ment = [] if request.GET['mcode'] != None: for qweq in agrps: grp.append("G-" + str(qweq.gcode)) if request.GET['tcode'] != None: menti = "M-" + str(trq.mcode) try: mentnamei = str( mentor.objects.get( mcode=str(trq.mcode)).name) + " (Mentor)" except: mentnamei = None if mentnamei != None: nal = (menti, mentnamei) ment.append(nal) if request.GET['mcode'] != None: try: mni = mentor.objects.filter().order_by('-name') except: print("mentors object not found") for aer in mni: menti = "M-" + str(aer.mcode) mentnamei = str(aer.name) + " (Mentor)" nal = (menti, mentnamei) ment.append(nal) try: from mentor.models import mentor ghi = mentor.objects.get(co_ord=1) except: ghi = None if ghi != None: cord = "C-" + str(ghi.mcode) if str(request.GET['co_ord']) == '0': cordname = str(ghi.name) + " (Co-ordinator)" else: cordname = None else: cord = None context['optionto'] = {} if len(grp) > 0: if request.GET['tcode'] != None: context['optionto'][grp[0]] = "Own Group" else: for qm in grp: context['optionto'][qm] = str( qm.split('-')[1]) + "-(Group)" if len(ment) > 0: if request.GET['tcode'] != None: context['optionto'][ment[0][0]] = ment[0][1] if request.GET['mcode'] != None: for opc in ment: a = opc[0].split('-') try: if str(mentor.objects.get(mcode=a[1]).co_ord ) != '1' and a[1] != request.GET['mecode']: context['optionto'][opc[0]] = opc[1] except: print("no object of user") exit() if cord != None and cordname != None: context['optionto'][cord] = cordname #fellow trainee def stuofgrp(grpc): if grpc != None: try: return (trainee.objects.filter( gcode=grpc).order_by('-name')) except: print("trainee object not found") #for trainees if request.GET['tcode'] != None: nxi = stuofgrp(trq.gcode) #trainee to list for mentors if request.GET['mcode'] != None: if request.GET['metype'] == 'C': try: nxi = trainee.objects.filter().order_by('-name') except: print("co_ord but still cant find trainee") else: mbo = 1 for qm in grp: zli = stuofgrp(qm.split('-')[1]) if mbo == 1: nxi = zli else: nxi.union(zli, all=True) mbo = mbo + 1 zx = [] tcodeq = "" tnameq = "" try: nxi except: nxi = "" if str(type(nxi)) == "<class 'django.db.models.query.QuerySet'>": for i in range(0, len(nxi)): try: tcodeq = "T-" + str(nxi[i].tcode) except: print("Trainee object not found !") try: tnameq = str(nxi[i].name) + " (Trainee)" except: tnameq = None cx = (tcodeq, tnameq) if tcodeq != "T-" + str(request.GET['tcode']): zx.append(cx) for zq in zx: context['optionto'][zq[0]] = zq[1] zx = [] tcodeq = "" tnameq = "" #sento ends here context['msgs'] = {} from message.models import message def getmsg(): try: xop = message.objects.filter( tocode=request.GET['tocode'], totype=request.GET['totype']).order_by( '-dateandtime').reverse() rep = {} for mg in xop: if mg.fromtype == 'M' or mg.fromtype == 'C': if len( mentor.objects.filter(mcode=mg.fromcode, co_ord='0')) > 0: sendername = str( mentor.objects.get( mcode=mg.fromcode, co_ord='0').name) + " (Mentor)" else: sendername = str( mentor.objects.get( mcode=mg.fromcode, co_ord='1').name) + " (Co-ordinator)" if mg.fromtype == 'T': sendername = str( trainee.objects.filter( tcode=mg.fromcode)[0].name) + " (Trainee)" if context['msgs'].get(sendername) == None: context['msgs'][sendername] = [ mg.msg, mg.dateandtime.isoformat(), str(mg.fromcode) + str(mg.fromtype) ] rep[sendername] = 0 sendername = "" else: context['msgs'][str(sendername) + str(int(rep.get(sendername)) + 1)] = [ mg.msg, mg.dateandtime.isoformat(), str(mg.fromcode) + str(mg.fromtype) ] rep[sendername] = int(rep.get(sendername)) + 1 sendername = "" except: print("mentor or trainee or message object not found") if request.GET['totype'] == 'G': getmsg() if request.GET['totype'] == 'M' or request.GET[ 'totype'] == 'T' or request.GET['totype'] == 'C': try: xop = message.objects.filter( tocode=request.GET['tocode'], totype=request.GET['totype'], fromcode=request.GET['mecode'], fromtype=request.GET['metype']).order_by( '-dateandtime').reverse() xopo = message.objects.filter( fromcode=request.GET['tocode'], fromtype=request.GET['totype'], tocode=request.GET['mecode'], totype=request.GET['metype']).order_by( '-dateandtime').reverse() #from me to him rep = {} for mg in xop: if mg.fromtype == 'M' or mg.fromtype == 'C': if len( mentor.objects.filter(mcode=mg.fromcode, co_ord='0')) > 0: sendername = str( mentor.objects.get( mcode=mg.fromcode, co_ord='0').name) + " (Mentor)" else: sendername = str( mentor.objects.get( mcode=mg.fromcode, co_ord='1').name) + " (Co-ordinator)" if mg.fromtype == 'T': sendername = str( trainee.objects.filter( tcode=mg.fromcode)[0].name) + " (Trainee)" if context['msgs'].get(sendername) == None: context['msgs'][sendername] = [ mg.msg, mg.dateandtime.isoformat(), str(mg.fromcode) + str(mg.fromtype) ] rep[sendername] = 0 sendername = "" else: context['msgs'][str(sendername) + str(int(rep.get(sendername)) + 1)] = [ mg.msg, mg.dateandtime.isoformat(), str(mg.fromcode) + str(mg.fromtype) ] rep[sendername] = int(rep.get(sendername)) + 1 sendername = "" #from him to me rep = {} for mg in xopo: if mg.fromtype == 'M' or mg.fromtype == 'C': if len( mentor.objects.filter(mcode=mg.fromcode, co_ord='0')) > 0: sendername = str( mentor.objects.get( mcode=mg.fromcode, co_ord='0').name) + " (Mentor)" else: sendername = str( mentor.objects.get( mcode=mg.fromcode, co_ord='1').name) + " (Co-ordinator)" if mg.fromtype == 'T': sendername = str( trainee.objects.filter( tcode=mg.fromcode)[0].name) + " (Trainee)" if context['msgs'].get(sendername) == None: context['msgs'][sendername] = [ mg.msg, mg.dateandtime.isoformat(), str(mg.fromcode) + str(mg.fromtype) ] rep[sendername] = 0 sendername = "" else: context['msgs'][str(sendername) + str(int(rep.get(sendername)) + 1)] = [ mg.msg, mg.dateandtime.isoformat(), str(mg.fromcode) + str(mg.fromtype) ] rep[sendername] = int(rep.get(sendername)) + 1 sendername = "" except: print("mentor or trainee or message object not found") if c != 'here': return (renlogin(request, None)) context['expt'] = "Here" # Message Notification try: nti = message.objects.filter( tocode=request.GET['mecode'], totype=request.GET['metype'], gstatus=0).order_by('-dateandtime').reverse() noti = {} print(nti) cntr = 1 for red in nti: if red.fromtype == 'M': name = str( mentor.objects.get( mcode=red.fromcode).name) + "(Mentor)" elif red.fromtype == 'T': name = str( trainee.objects.get( tcode=red.fromcode).name) + "(Trainee)" elif red.fromtype == 'C': name = str( mentor.objects.get( mcode=red.fromcode).name) + "(Co-Ordinator)" else: name = None name = name + str(cntr) noti[name] = {} noti[name]['notimsg'] = red.msg noti[name]['notifromcode'] = red.fromcode noti[name]['notifromtype'] = red.fromtype noti[name]['notitocode'] = red.tocode noti[name]['notitotype'] = red.totype cntr = cntr + 1 if len(noti) != 0: context['noti'] = noti else: context['noti'] = 'None' except: context['noti'] = 'None' # Notification End allmsg = context['msgs'] nam = {} dtl = [] for a in allmsg: dtl.append(allmsg[a][1]) dtl.sort() for b in dtl: for aa in allmsg: if b == allmsg[aa][1]: nam[aa] = allmsg[aa] context['msgs'] = nam context['mecode'] = str(request.GET['mecode']) + str( request.GET['metype']) return (render(request, "messages.html", context)) if request.GET['msgs'] != "" or request.GET['msgs'] != None: mutable = request.GET._mutable request.GET._mutable = True try: x = user.objects.get(username=request.session['user']) except: x = 0 try: tocode = request.GET['tocode'] except: tocode = None try: totype = request.GET['totype'] except: totype = None if x.utype == "T": request.GET['tcode'] = x.ucode request.GET['metype'] = 'T' request.GET['mecode'] = x.ucode else: request.GET['tcode'] = None request.GET['metype'] = None request.GET['mecode'] = None if x.utype == "M": request.GET['mcode'] = x.ucode request.GET['metype'] = 'M' request.GET['mecode'] = x.ucode from mentor.models import mentor try: cor = mentor.objects.get(mcode=x.ucode).co_ord except: print("Mentor object not found") if str(cor) == "1": request.GET['co_ord'] = 1 request.GET['metype'] = 'C' else: request.GET['mcode'] = None request.GET['co_ord'] = 0 request.GET._mutable = mutable try: msgs = request.GET['msgs'] except: msgs = None print("\n\n", msgs, "\n\n") if msgs != None and msgs != "": from message.models import message mecode = request.GET['mecode'] metype = request.GET['metype'] print("\ntocode=", tocode, "\ntotype=", totype, "\nfromcode=", mecode, "\nfromtype=", metype, "\nmsg=", msgs) try: from message.models import message message.objects.create(tocode=tocode, totype=totype, fromcode=mecode, fromtype=metype, msg=msgs) context['expt'] = "Done" except: context['expt'] = "Message object not saved" print("Message object not saved") return (HttpResponse(context['expt'])) else: context['expt'] = "" return (HttpResponse(context['expt']))
def attendence_view(request,*args,**kwargs): if request.method == "GET" : context={} try: request.GET['saveattendence'] for key, value in request.GET.items(): if key!='saveattendence': print(key,value) attendence.objects.create(tcode=key,status=value) context['respo']='Done !' except: context['respo']=None mutable = request.GET._mutable request.GET._mutable = True try: x=user.objects.get(username=request.session['user']).ucode y=user.objects.get(username=request.session['user']).utype except: x=0 y=0 if y=='T': request.GET['tcode']=x else: request.GET['tcode']=None if y=='M' or y=='C': request.GET['mcode']=x try: co_ord=str(mentor.objects.get(mcode=x).co_ord) except: co_ord='0' else: request.GET['mcode']=None request.GET['mecode']=x request.GET['metype']=y request.GET._mutable = mutable c=checksession(request) if c!='here': return(c) context['user']=request.session['user'] try:aof=request.GET['aof'] except:aof=None try:arq=request.GET['arq'] except:arq=None if aof!=None and arq!=None: aob=tattendence(aof) if aob!="No such Trainee Attendence found" and aob!=[]: tato=[] for tik in aob: tat={} if str(tik.status)=='1': tat['date']=str(tik.date) tat['status']="Present" if str(tik.status)=='0': tat['date']=str(tik.date) tat["status"]="Absent" tato.append(tat) resq=str(tato) resq=resq.replace("'",'"') response="<input type='hidden' id='atnd' value='"+resq+"' />Select dates to show attendence of :<br>Starting from date: <input type='date' id='sd' placeholder='2019-05-09' /> Till date: <input type='date' id='ed' placeholder='2019-08-04' /><button class='pure-button' onclick='datesel()'>Get Data</button>" else:response="No such Trainee Attendence found" return(HttpResponse(response)) else: if request.GET['metype']=='T' : context['atype']='T' context['bname']="Check Attendence" context['aof']=request.GET['mecode'] context['formid']="frm1" tlst={} from trainee.models import trainee try: tlst[request.GET['mecode']]=trainee.objects.get(tcode=request.GET['mecode']).name except: print("no trainee found !") print(tlst) context['tlst']=tlst return(render(request,"attendence.html",context)) if request.GET['metype']=='M' and co_ord =='0': from group.models import group try: grpsofmentor=group.objects.filter(mcode=request.GET['mecode']).order_by('-gcode') except: print("no groups found !") mbo=1 nxi="A" for a in grpsofmentor: from trainee.models import trainee try:tr=trainee.objects.filter(gcode=a.gcode).order_by('name') except:print("no trainee found") if mbo==1: nxi=tr else: nxi = nxi | tr mbo=mbo+1 tlst={} print(nxi) if len(grpsofmentor)>1: for zin in nxi: tlst[zin.tcode]=zin.name context['tlst']=tlst context['atype']='M' return(render(request,"attendence.html",context)) if request.GET['metype']=='M' and co_ord =='1': from trainee.models import trainee try:nxi=trainee.objects.filter().order_by('name') except:print("no trainee Found") tlst={} for zin in nxi: tlst[zin.tcode]=zin.name atlst={} for zin in nxi: if zin.proj_sub_date ==None: zin.proj_sub_date='9000-12-31' zin.proj_sub_date=datetime.strptime(str(zin.proj_sub_date), '%Y-%m-%d') today=datetime.today().strftime('%Y-%m-%d') try: attendence.objects.get(tcode=zin.tcode,date=today) hkl=True except: hkl=False if zin.proj_sub_date >= datetime.strptime(today, '%Y-%m-%d') and hkl==False : atlst[zin.tcode]=zin.name context['tlst']=tlst context['atlst']=atlst context['atype']='C' print(context) return(render(request,"attendence.html",context))