Exemplo n.º 1
0
def edit(request, prn):
    if "username" not in request.session:
        print "no session found"
        request.session['redirect'] = request.get_full_path()
        return our_redirect("/ldap_login")
    if prn != request.session['username']:
        print "prn", prn, type(prn)
        print "username", request.session['username'], type(
            request.session['username'])
        return HttpResponse('Please Edit ur own form :@')
    '''The problem with this view :
            We(I) are doing it the old-fashioned way. 
            We(I) are not using the power of Models which allow automatic server-side validation -- i need to read on that.
    '''

    #was prn passed and is it numeric really?
    if prn is not None and prn.isdigit() is True:
        #are we authorized to edit this ?
        #do we hv global edit privileges ?

        #kya ye hamara hi resume hai ?

        #do we hv the record ?
        s = student.objects.filter(pk=prn)
        #see the way to unzip a tuple that is returned by a func
        if len(s) is 0:
            return HttpResponse('This user doesnt exists')
        else:
            s = s[0]
            debugger("Resume found! Using it")

        #get all the records and tell us whether they were creatd or retrieved
        #have moved this to the student_info.models, because all Model info must come from there and tomo if we add a new model, we shouldn't have to come here to provide it's functionality.
        table = tables.get_tables(s)
        #get company specific required fields
        '''We are segregating the company Specific thigs into 3 sequences... 
        a) the main table, which consists all rows of the main table structurw. Who are neither special kinds, nor are already filled. 
        b) cs are the data filled by this partucular student.
        Main table fetches all the data to be collected per student. CS is the data ctually filled by the students. this is used to prefill the foem while editing.and the maintable is required for the "form" for a new user.
        '''

        cs = companySpecificData.objects.filter(
            primary_table=s).order_by('valueOf')
        maintable = companySpecific.objects.exclude(
            fieldType='special').exclude(
                companyspecificdata__in=cs).order_by('displayText')
        print "CS ====", cs
        print "Maintable....", maintable

        table['mt'] = maintable
        table['cs'] = cs
        table['flag'] = 'edit'

        c = RequestContext(request, table)
        t = loader.get_template('student_info/form.html')

        return HttpResponse(t.render(c))
Exemplo n.º 2
0
def edit(request,prn):
    if "username" not in request.session:
       print "no session found"
       request.session['redirect'] = request.get_full_path();
       return our_redirect("/ldap_login")
    if prn != request.session['username']:
        print "prn", prn, type(prn)
        print "username", request.session['username'],type(request.session['username'])
        return HttpResponse('Please Edit ur own form :@')
    '''The problem with this view :
            We(I) are doing it the old-fashioned way. 
            We(I) are not using the power of Models which allow automatic server-side validation -- i need to read on that.
    '''
        
    #was prn passed and is it numeric really?
    if prn is not None and prn.isdigit() is True:
        #are we authorized to edit this ?
            #do we hv global edit privileges ?

            #kya ye hamara hi resume hai ?

        #do we hv the record ?
        s = student.objects.filter(pk=prn); #see the way to unzip a tuple that is returned by a func
        if len(s) is 0:
            return HttpResponse('This user doesnt exists');
        else:
            s=s[0]
            debugger("Resume found! Using it");
        
        #get all the records and tell us whether they were creatd or retrieved
        #have moved this to the student_info.models, because all Model info must come from there and tomo if we add a new model, we shouldn't have to come here to provide it's functionality.
        table=tables.get_tables(s)        
        #get company specific required fields
        '''We are segregating the company Specific thigs into 3 sequences... 
        a) the main table, which consists all rows of the main table structurw. Who are neither special kinds, nor are already filled. 
        b) cs are the data filled by this partucular student.
        Main table fetches all the data to be collected per student. CS is the data ctually filled by the students. this is used to prefill the foem while editing.and the maintable is required for the "form" for a new user.
        '''

       
        cs=companySpecificData.objects.filter(primary_table=s).order_by('valueOf')
        maintable=companySpecific.objects.exclude(fieldType='special').exclude(companyspecificdata__in = cs).order_by('displayText');
        print "CS ====",cs
        print "Maintable....",maintable
        
        table['mt']=maintable;
        table['cs']=cs;
        table['flag']='edit';

        c = RequestContext(request,table);
        t = loader.get_template('student_info/form.html');
        
        return HttpResponse(t.render(c));
Exemplo n.º 3
0
def html(request,prn):
    if 'username' not in request.session:
           request.session['redirect'] = request.get_full_path();
           return our_redirect('/login')
    '''if prn != request.session['username']:
          return HttpResponse('Not urs..!!')'''
    if prn is not None:
        try:
           s = student.objects.get(pk=prn);
        except:
           output = "<h3>Student details for PRN %s not found! <input type = 'button' value='Click to fill your details' onClick='%s/form'></h3>" % (prn,ROOT);
           return HttpResponse(output);

    data = tables.get_tables(s);
    t=loader.get_template('moderncv/htmlview.html')
    c=Context(data)
    return HttpResponse(t.render(c))
Exemplo n.º 4
0
def latex(request, prn):
    if 'username' not in request.session:
        request.session['redirect'] = request.get_full_path()
        return our_redirect('/ldap_login/')
    '''generates the resume and puts it into the resume store for version control'''
    #the current user from session;
    if prn != request.session['username']:
        return HttpResponse('Please mind your own resume...')
    if prn is not None:
        try:
            s = student.objects.get(pk=str(prn))
            print "=============== inside Latex.. found S .....", s
        except Exception as e:
            print "======inside latex... exception", e
            output = "<h3>Student details for PRN %s not found! Can't generate a LaTeX file!</h3>" % (
                prn)
            return HttpResponse(output)

        if s is not None:
            print "==latex====s is not NOne"
            #pass the student object with all his entered info to the template generator
            t = loader.get_template('%s/template.tex' % RESUME_FORMAT)

            print "=====latex ===t ", t

            #add the basic info wala original object also
            student_data = tables.get_tables(s)
            #student_data['photo'] = RESUME_STORE + "photos/" + prn + ".png"
            student_data['photo'] = "%s.png" % (prn)

            pprint(student_data)
            c = Context(student_data)

            try:
                print " =latex==== inside the try"
                #every latex file goes into that prn's directory
                destination_dir = '%s/%s/' % (RESUME_STORE, prn)

                try:
                    chdir(destination_dir
                          )  #if we can't change into it, create it!
                except OSError:
                    print "===latex === Os Error aya tha.. making dIr"
                    mkdir(destination_dir)
                finally:
                    print "=== inside chdir ka finally"
                    chdir(FULL_PATH)

                resume_file = '%s/%s.tex' % (destination_dir, prn)
                #now store the person's generated resume-latex-code
                f = file(resume_file, 'w')
                #if the file exists, overwrite it ELSE  create it.

                f.write(t.render(c))
                f.close()

                #now update the .tex generation timestamp
                print "Updating the resume details timestamp with what has been done"
                print s
                print "Now is ", datetime.now()
                r = resume.objects.get_or_create(prn=s)

                print "====latex======== resume made  ", r
                #because we called get_or_create, we will get a tuple containing the record and a bool value telling whether it was created or fetched
                r[0].last_tex_generated = datetime.now()
                print r[0].last_tex_generated
                r[0].save()
                """#for now postponed to next release
                #now add this file to version control

                hg_command = "hg add %s; hg commit -u laresumex -m 'updated by %s' " % (resume_file,user);
                return_status = get_done(hg_command);
                """
                return_status = True
            except Exception as e:
                print '=====latex============ Exception was ', e
                return_status = False
            finally:
                if return_status is False:
                    output = "<h3>Couldn't generate your .TEX file! Return code was %d </h3>" % return_status
                else:
                    output = "<h3>Done!</h3>"
        else:
            output = "<h3>Student details for PRN %s not found!</h3>" % (prn)
    else:
        output = "<h3>Hey, pass me a PRN man!</h3>"

    return HttpResponse(output)
Exemplo n.º 5
0
def pisapdf(request, prn):
    if prn is not None:
        s = student.objects.get(pk=prn)
    else:
        return HttpResponse("Pass me a prn, dude!")

    try:
        #have we ever recorded a pdf creation for this student ?
        r, new_record_created = resume.objects.get_or_create(prn=s)
        pdf_file_name = "%s/%s/%s.pdf" % (RESUME_STORE, prn, prn)
        got_file = False

        if not new_record_created:
            #yeah we have already created, but does it exist ?
            if (path.exists(pdf_file_name)) and (datetime.fromtimestamp(
                    path.getmtime(pdf_file_name)) >= s.last_update):
                #the file exists and is fresher than the student's update time stamp.
                pdf_file = open(pdf_file_name)
                got_file = True
                debugger("Using old file at %s" % pdf_file_name)

        #the file doesn't exist OR the file is stale than the student data OR no record of ever creating a pdf for this user exists:
        debugger("No old file found, creating fresh!")
        if not got_file:
            try:
                data = tables.get_tables(s)
                t = loader.get_template('moderncv/pdfview.html')
                c = Context(data)
                c.update({'pagesize': 'A4'})
                html = t.render(c)

                result = StringIO.StringIO()
                pdf = pisa.pisaDocument(
                    StringIO.StringIO(html.encode("utf-8", 'replace')), result)
                #save the file in temp location
                f = open("/tmp/%s.pdf" % prn, 'w+b')
                f.write(result.getvalue())
                f.close()

                del result  #to clean memory
                #move the pdf to permanent location
                destination_dir = '%s/%s/' % (RESUME_STORE, prn)
                try:
                    debugger("Trying to change in %s" % destination_dir)
                    chdir(destination_dir
                          )  #if we can't change into it, create it!
                except OSError:
                    mkdir(destination_dir)
                finally:
                    chdir(FULL_PATH)

                copy_pdf_command = "cp -v /tmp/%s.pdf %s/%s/%s.pdf" % (
                    prn, RESUME_STORE, prn, prn)
                #copy the .pdf to the user's directory in STORE so that we can reuse it
                get_done(copy_pdf_command)
                print "Updating timestamp for the PDF generation in our records"
                r.last_pdf_generated = datetime.now()
                r.save()
                print "Using newly created pdf file at %s" % pdf_file_name
            except Exception as e:
                traceback.print_exc()
                print "Exception occurred when creating a fresh pdf : %s" % e
                return HttpResponse(
                    "Error when generating the resume for %s " % prn)

    except Exception as e:
        traceback.print_exc()
        print "Exception occurred when in pisapdf : %s" % e
        return HttpResponse("Error when getting resume for %s " % prn)

    #open the pdf file
    print "Opening the file at : %s" % pdf_file_name
    resume_pdf = open(pdf_file_name)
    #prepare the file to be sent
    response = HttpResponse(resume_pdf.read(), mimetype="application/pdf")
    resume_pdf.close()
    #name the file properly
    response[
        'Content-Disposition'] = "attachment; filename=SICSR_%s_resume.pdf" % s.fullname

    return response
Exemplo n.º 6
0
def latex(request,prn):
    if 'username' not in request.session:
            request.session['redirect'] = request.get_full_path();
            return our_redirect('/ldap_login/')
    '''generates the resume and puts it into the resume store for version control'''
    #the current user from session;
    if prn != request.session['username']:
        return HttpResponse('Please mind your own resume...')
    if prn is not None:
    	try:
            s = student.objects.get(pk=str(prn))
            print "=============== inside Latex.. found S .....",s
        except Exception as e:
            print "======inside latex... exception",e
            output = "<h3>Student details for PRN %s not found! Can't generate a LaTeX file!</h3>" % (prn);
            return HttpResponse(output);
        
        if s is not None:
            print "===latex=== is not NOne"
            #pass the student object with all his entered info to the template generator
            t = loader.get_template('%s/template.tex' % RESUME_FORMAT);
            
            print "=====latex ===t ",t

            #add the basic info wala original object also
            student_data=tables.get_tables(s)
            #student_data['photo'] = RESUME_STORE + "photos/" + prn + ".png"  
            student_data['photo'] = "%s.png" % (prn);

            pprint(student_data);
            c = Context(student_data);
             
            try:
                print " =latex==== inside the try"
                #every latex file goes into that prn's directory
                destination_dir = '%s/%s/' % (RESUME_STORE, prn)

                try:
                    chdir(destination_dir) #if we can't change into it, create it!
                except OSError:
                    print "===latex === Os Error aya tha.. making dIr"
                    mkdir(destination_dir);
                finally:
                    print "=== inside chdir ka finally"
                    chdir(FULL_PATH);
                 
                resume_file = '%s/%s.tex' % (destination_dir, prn)
                #now store the person's generated resume-latex-code
                f = file(resume_file,'w'); #if the file exists, overwrite it ELSE  create it.
               
                f.write(t.render(c));
                f.close();
                
                #now update the .tex generation timestamp
                print "Updating the resume details timestamp with what has been done";
                print s;
                print "Now is ", datetime.now();
                r = resume.objects.get_or_create(prn=s);

                print "====latex======== resume made  ",r
                #because we called get_or_create, we will get a tuple containing the record and a bool value telling whether it was created or fetched
                r[0].last_tex_generated = datetime.now();
                print r[0].last_tex_generated
                r[0].save();

                """#for now postponed to next release
                #now add this file to version control

                hg_command = "hg add %s; hg commit -u laresumex -m 'updated by %s' " % (resume_file,user);
                return_status = get_done(hg_command);
                """
                return_status = True;
            except Exception as e:
               print '=====latex============ Exception was ', e;
               return_status = False;
            finally:
                if return_status is False:
                    output = "<h3>Couldn't generate your .TEX file! Return code was %d </h3>" % return_status;
                else:
                    output = "<h3>Done!</h3>";
        else:
            output = "<h3>Student details for PRN %s not found!</h3>" % (prn);
    else:
       output = "<h3>Hey, pass me a PRN man!</h3>";
    
    return HttpResponse(output);
Exemplo n.º 7
0
def pisapdf(request,prn,return_PDF_directly=True):
    '''generates a PDF resume using the HTML template by using the pisaPDF generation library.
       if return_PDF_directly is True, it will return the PDF in the request
       if return_PDF_directly is False, it will simply return the filesystem path for the PDF.
    '''
    if prn is not None:
        s = student.objects.get(pk=prn);
    else:
        return HttpResponse("Pass me a prn, dude!");

    try:
        #have we ever recorded a pdf creation for this student ?
        r,new_record_created = resume.objects.get_or_create(prn=s);
        pdf_file_name = "%s/%s.pdf" % (RESUME_STORE, prn);
        got_file = False;

        if not new_record_created:
            #yeah we have already created, but does it exist ?
            if (path.exists(pdf_file_name)) and (datetime.fromtimestamp(path.getmtime(pdf_file_name)) >= s.last_update):
                #the file exists and is fresher than the student's update time stamp.
                pdf_file = open(pdf_file_name);
                got_file = True;
                debugger("Using old file at %s" % pdf_file_name);

        #the file doesn't exist OR the file is stale than the student data OR no record of ever creating a pdf for this user exists:
        debugger("No old file found, creating fresh!")
        if not got_file:
            try:
                data = tables.get_tables(s);
                t = loader.get_template('moderncv/pdfview.html')
                c = Context(data);
                c.update({'pagesize':'A4'});
                html = t.render(c)
                
                result = StringIO.StringIO();
                pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("utf-8",'replace')),result);
                #save the file in temp location
                f = open("/tmp/%s.pdf" % prn,'w+b');
                f.write(result.getvalue());
                f.close();

                del result #to clean memory
                #move the pdf to permanent location
                destination_dir = '%s/%s/' % (RESUME_STORE, prn)

                try:
                     debugger("Trying to change in %s" % destination_dir);
                     chdir(destination_dir) #if we can't change into it, create it!
                except OSError:
                     mkdir(destination_dir);
                finally:
                     chdir(FULL_PATH);            
                
                copy_pdf_command = "cp -v /tmp/%s.pdf %s/%s.pdf" % (prn, RESUME_STORE,prn); #copy the .pdf to the user's directory in STORE so that we can reuse it
                get_done(copy_pdf_command);
                print "Updating timestamp for the PDF generation in our records"
                r.last_pdf_generated = datetime.now();
                r.save();
                print "Using newly created pdf file at %s" % pdf_file_name
            except Exception as e:
                traceback.print_exc();
                print "Exception occurred when creating a fresh pdf : %s" % e;
                return HttpResponse("Error when generating the resume for %s " % prn);
   
    except Exception as e:
       traceback.print_exc();
       print "Exception occurred when in pisapdf : %s" % e;
       return HttpResponse("Error when getting resume for %s " % prn );

    if return_PDF_directly is True:
        #open the pdf file
        print "Opening the file at : %s" % pdf_file_name
        resume_pdf = open(pdf_file_name);
        #prepare the file to be sent
        response = HttpResponse(resume_pdf.read(), mimetype="application/pdf");
        resume_pdf.close();
        #name the file properly
        response['Content-Disposition'] = "attachment; filename=SICSR_%s_resume.pdf" % s.fullname;
    else:
        response = pdf_file_name

    return response;