Exemple #1
0
def insert_attachment_file(doc_type, fid, filename, filepath, filetype):
    '''This method is to store attachment files such as CVs and personal statements into the database'''
    form = Forms.get(Forms.fid == fid)
    file = Files(filepath = filepath, filename=filename, filetype = filetype)
    file.save()
    if doc_type == "cv":
        try:
            form.cv = file
        except Exception as e:
            print (e)
            return False
    if doc_type =="statement":
        try:
            form.personal_statement = file
        except Exception as e:
            print (e)
            return False
    form.save()
    return form
Exemple #2
0
	def POST(self):
		web.header('Content-type', 'text/plain')
		
		user_id = session.user().id

		sid = int(web.input(id='0')['id'], 10)
		sname = web.input(name='')['name']
		scode = web.input(code='')['code']

		return Files.save(user_id, sid, sname, scode)
Exemple #3
0
    def POST(self):
        web.header('Content-type', 'text/plain')

        user_id = session.user().id

        sid = int(web.input(id='0')['id'], 10)
        sname = web.input(name='')['name']
        scode = web.input(code='')['code']

        return Files.save(user_id, sid, sname, scode)
Exemple #4
0
def viewform(request):
    usercheck = user_permission_check(request)
    if user_permission_check(request) == "2":
        return HttpResponseRedirect("/404")
    elif user_permission_check(request) == "3":
        return HttpResponseRedirect("/404")
    elif user_permission_check(request) == "1":
        navbardash = True
        if not request.GET.get("id"):
            return HttpResponseRedirect("/dashboard")
        else:
            if request.GET.get('successfulupload') == str(1):
                successform = 1
            elif request.GET.get('successfulupload') == str(0):
                successform = 2
            user = request.user
            formid_get = request.GET.get("id")
            ecfdata_info = EcfData.objects.get(id=formid_get)
            if ecfdata_info.user_id == user.id:
                userdata = User.objects.get(id=ecfdata_info.user_id)
                moduledata_info = ModuleData.objects.filter(
                    ecfdata_id=formid_get)

                # Code for viewing and downloading the uploaded files
                fileupload_data = Files.objects.filter(ecfdata_id=formid_get)
                totalmodules = 0
                pendingmod = 0
                approvedmod = 0
                rejectedmod = 0
                finalmod = -1
                for item in moduledata_info:
                    totalmodules += 1
                    if item.approved == 0:
                        pendingmod += 1
                    elif item.approved == 1:
                        approvedmod += 1
                    elif item.approved == 2:
                        rejectedmod += 1
                if totalmodules == pendingmod:
                    finalmod = 0
                elif totalmodules == approvedmod:
                    finalmod = 1
                elif totalmodules == rejectedmod:
                    finalmod = 2
                elif pendingmod >= 1:
                    finalmod = 4
                else:
                    finalmod = 3

                # If new files are requested by the secretary
                if request.method == "POST":
                    foreignid = request.GET.get('id')
                    ecfdataid = EcfData.objects.get(id=foreignid)
                    form = extraUpload(request.POST, request.FILES)
                    if form.is_valid():
                        filestore = Files(document=request.FILES['fileinput'],
                                          ecfdata_id=ecfdataid.id)
                        filestore.pk = None
                        filestore.save()
                        ecfdataid.moreproof = False
                        ecfdataid.save()
                        context = {}
                        allusers = User.objects.all()
                        secretaryCheck = allusers.select_related('profile')
                        for item in secretaryCheck:
                            if item.profile.userpower == 2:
                                send_mail(
                                    'More proof uploaded for form #' +
                                    str(ecfdataid.id),
                                    render_to_string(
                                        'emails/secretary/moreproofuploaded.txt',
                                        context),
                                    sendingemailaddress,
                                    [item.email],
                                    fail_silently=True,
                                )
                        return HttpResponseRedirect("/viewform?id=" +
                                                    foreignid +
                                                    "&successfulupload=1")
                    else:
                        return HttpResponseRedirect("/viewform?id=" +
                                                    foreignid +
                                                    "&successfulupload=0")
                else:
                    form = extraUpload()

                return render(request, 'viewform.html', locals())
            else:
                return HttpResponseRedirect("/404")
Exemple #5
0
def newform(request):
    usercheck = user_permission_check(request)
    if user_permission_check(request) == "2":
        return HttpResponseRedirect("/404")
    elif user_permission_check(request) == "3":
        return HttpResponseRedirect("/404")
    elif user_permission_check(request) == "1":
        navbarnew = True
        units = request.GET.get('units')
        unitsx = request.GET.get('units', 0)
        x = int(unitsx)

        if (x <= 0) or (x == None) or (x > 10):
            return HttpResponseRedirect("/units?nounits=1")
        else:
            if units:
                units = range(1, int(units) + 1)

            if request.method == "POST":
                unitsx = request.GET.get('units', 0)
                x = int(unitsx)
                form = NewEcf(request.POST, request.FILES, units_no=x)
                user = request.user
                if form.is_valid():
                    ukvisa = form.cleaned_data['ukvisa']
                    coursename = form.cleaned_data['coursename']
                    studyyear = form.cleaned_data['studyyear']
                    numberofunits = form.cleaned_data['numberofunits']
                    durationenddate = form.cleaned_data['durationenddate']
                    durationstartdate = form.cleaned_data['durationstartdate']
                    circumstance = form.cleaned_data['circumstance']
                    detailecf = form.cleaned_data['detailecf']

                    ecfdata = EcfData(user=user,
                                      ukvisa=ukvisa,
                                      coursename=coursename,
                                      studyyear=studyyear,
                                      numberofunits=numberofunits,
                                      durationenddate=durationenddate,
                                      durationstartdate=durationstartdate,
                                      circumstance=circumstance,
                                      detailecf=detailecf)
                    ecfdata.save()

                    foreignid = EcfData.objects.get(id=ecfdata.id)
                    filestore = Files(document=request.FILES['fileinput'],
                                      ecfdata=foreignid)
                    filestore.pk = None
                    filestore.save()

                    listunitcode = []
                    listtype = []
                    liststartdate = []
                    listenddate = []
                    listaction = []
                    for item in range(1, ecfdata.numberofunits + 1):
                        listunitcode.append("unitcode" + str(item))
                        listtype.append("type" + str(item))
                        liststartdate.append("startdate" + str(item))
                        listenddate.append("enddate" + str(item))
                        listaction.append("action" + str(item))

                    for i in range(0, ecfdata.numberofunits):

                        foreignid = EcfData.objects.get(id=ecfdata.id)
                        unitcode = form.cleaned_data[listunitcode[i]]
                        type = form.cleaned_data[listtype[i]]
                        startdate = form.cleaned_data[liststartdate[i]]
                        enddate = form.cleaned_data[listenddate[i]]
                        action = form.cleaned_data[listaction[i]]

                        moduledata = ModuleData(
                            unitcode=unitcode,
                            type=type,
                            startdate=startdate,
                            enddate=enddate,
                            action=action,
                            ecfdata=foreignid,
                        )

                        moduledata.pk = None
                        moduledata.save()
                        context = {}
                        send_mail(
                            'Submmited New Form #' + str(ecfdata.id),
                            render_to_string('emails/newform.txt', context),
                            sendingemailaddress,
                            [user.email],
                            fail_silently=True,
                        )
                        studentpubdata = User.objects.all()
                        studcheck = studentpubdata.select_related('profile')
                        for item in studcheck:
                            if item.profile.userpower == 2:
                                send_mail(
                                    'New form #' + str(ecfdata.id) +
                                    ' submitted',
                                    render_to_string(
                                        'emails/secretary/newform.txt',
                                        context),
                                    sendingemailaddress,
                                    [item.email],
                                    fail_silently=True,
                                )

                    return HttpResponseRedirect("/dashboard?success=1")
                else:
                    return HttpResponseRedirect("/dashboard?success=0")

            else:
                form = NewEcf(units_no=x)

        return render(request, 'newform.html', locals())