Esempio n. 1
0
	def generate_slot_pdf(self,request,queryset):
		if len(queryset)>1:
			self.message_user(request,"Dude, weak! You cannot select more than one setup for generating PDFs")	
		else:
			setup = list(queryset)[0]		
			c = Candidate.objects.filter(setup=setup,slot=None)
			if c: #Candidates with no slot exist
				self.message_user(request,"Dude, weak! You cannot generate the PDF until all candidates are given slots. Please check the candidate table again. ")
			else: #All set. Ready to generate PDF
				num_slots=0			
				for candidate in Candidate.objects.filter(setup=setup):
					if candidate.slot>num_slots:
						num_slots=candidate.slot
				
				slots = [[] for x in range(0,num_slots)]	
				
				for candidate in Candidate.objects.filter(setup=setup):
					slots[int(candidate.slot)-1].append(candidate)					
	
				template = get_template("recruitments/slots_pdf_base.html")
				context = Context({'setup':setup,'slots':slots,'pagesize':'A4'})
				html = template.render(context)
				result = StringIO.StringIO()
				pdf = pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")),dest=result)
				
				#if not pdf.error:
				link = settings.MEDIA_ROOT + '/uploads/recruitments/slots.pdf'
				f = open(link ,"wb")
				f.write(result.getvalue())  
     				#return HttpResponse(result.getvalue(),mimetype='application/pdf')
   				
				self.message_user(request,"The PDF was generated successfully")	
Esempio n. 2
0
def render_to_pdf(template_src, context_dict, link):
    template = get_template(template_src)
    context = Context(context_dict)
    html = template.render(context)
    # return HttpResponse(html)
    result = StringIO.StringIO()
    pdf = pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), dest=result, link_callback=fetch_resources)
    # print result.getvalue()

    if not pdf.err:
        c = context_dict["candidate"]
        f = open(link, "wb")
        f.write(result.getvalue())
Esempio n. 3
0
def render_to_pdf(template_src, context_dict):
    '''
    Renderiza el template con el contexto.
    Envía al cliente la Respuesta HTTP del contenido PDF para
    el template renderizado.
    '''
    template = get_template(template_src)
    context = Context(context_dict)
    html = template.render(context)
    result = StringIO.StringIO()
    pdf = pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), result)
    if not pdf.err:
        return HttpResponse(result.getvalue(), mimetype='application/pdf')
    return HttpResponse('We had some errors<pre>%s</pre>' % cgi.escape(html))
Esempio n. 4
0
def render_to_pdf(template_src, context_dict):
    '''
    Renderiza el template con el contexto.
    Envía al cliente la Respuesta HTTP del contenido PDF para
    el template renderizado.
    '''
    template = get_template(template_src)
    context = Context(context_dict)
    html  = template.render(context)
    result = StringIO.StringIO()
    pdf = pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), result)
    if not pdf.err:
        return HttpResponse(result.getvalue(), mimetype='application/pdf')
    return HttpResponse('We had some errors<pre>%s</pre>' % cgi.escape(html))
Esempio n. 5
0
    def get(self, request, **kwargs):
        self.object = self.get_object()
        context = self.get_context_data(**kwargs)

        html = render_to_string(self.template_name, RequestContext(request, context))

        html = html.replace("""src="%s""" % settings.STATIC_URL, """src="%s/""" % settings.STATIC_ROOT)

        if "html" in request.GET:
            return HttpResponse(html)
        result = StringIO.StringIO()
        pdf = pisaDocument(StringIO.StringIO(html.encode("utf-8")), result, show_error_as_pdf=True, encoding="UTF-8")
        response = HttpResponse(result.getvalue(), mimetype='application/pdf')
        response["Content-Disposition"] = "filename=%s.pdf" % self.object.title.encode("utf-8")
        return response
Esempio n. 6
0
    def pdf(self, html):
        # logging.debug(html)
        result = StringIO.StringIO()
        path = os.path.join(os.path.dirname(__file__), "../../")
        css_file = "".join([path, "fs-resources/pdfreport.css"])

        css = file(css_file, "r").read()
        # logging.debug('css %s' % css)
        pdf = pisaDocument(StringIO.StringIO(html), result, default_css=css)

        if not pdf.err:
            logging.debug("PDF generated. Sending it to browser...")
            # logging.debug(result.getvalue())
            self.response.headers["Content-Disposition"] = "attachment; filename=MyTripReport.pdf"

            self.response.out.write(result.getvalue())
        else:
            self.response.out.write("We had some errors generating pdf report. Please try again after a few minutes.")
Esempio n. 7
0
def render_to_pdf(template_src, context_dict, filename='document'):
    '''
    Renderiza el template con el contexto.
    Envía al cliente la Respuesta HTTP del contenido PDF para
    el template renderizado.
    '''
    template = get_template(template_src)
    context = Context(context_dict)
    html = template.render(context)
    result = StringIO.StringIO()

    pdf = pisaDocument(StringIO.StringIO(html.encode("utf-8")), result, path=settings.REPORT_STATIC, encoding='utf-8')
    if not pdf.err:
        response = HttpResponse(mimetype='application/pdf')
        response['Content-Disposition'] = 'attachment; filename="%s.pdf"' % filename
        response.write(result.getvalue())
        return response
    return HttpResponse('We had some errors<pre>%s</pre>' % cgi.escape(html))
Esempio n. 8
0
    def pdf(self, html):
        #logging.debug(html)
        result = StringIO.StringIO()
        path = os.path.join(os.path.dirname(__file__), '../../')
        css_file = ''.join([path, 'fs-resources/pdfreport.css'])

        css = file(css_file, 'r').read()
        #logging.debug('css %s' % css)
        pdf = pisaDocument(StringIO.StringIO(html), result, default_css=css)

        if not pdf.err:
            logging.debug('PDF generated. Sending it to browser...')
            #logging.debug(result.getvalue())
            self.response.headers[
                'Content-Disposition'] = 'attachment; filename=MyTripReport.pdf'

            self.response.out.write(result.getvalue())
        else:
            self.response.out.write(
                'We had some errors generating pdf report. Please try again after a few minutes.'
            )