コード例 #1
0
 def preview(self):
     rw = dReportWriter()
     rw.ReportFormFile = "invoice.rfxml"
     rw.OutputFile = "invoice.pdf"
     rw.UseTestCursor = True
     rw.bindEvent(dabo.dEvents.ReportEnd, self.onReportEnd)
     rw.ProgressControl = self.progress
     self.progress.ReportWriter = rw
     rw.write()
コード例 #2
0
ファイル: invoice_progressControl.py プロジェクト: xfxf/dabo
 def preview(self):
     rw = dReportWriter()
     rw.ReportFormFile = "invoice.rfxml"
     rw.OutputFile = "invoice.pdf"
     rw.UseTestCursor = True
     rw.bindEvent(dabo.dEvents.ReportEnd, self.onReportEnd)
     rw.ProgressControl = self.progress
     self.progress.ProcessObject = rw
     rw.write()
コード例 #3
0
def initProperties(self):
	app = self.Application
	self.FontSize = app.PreferenceManager.getValue("fontsize")
	from dabo.dReportWriter import dReportWriter
	self.ReportForm = None
	self.DataSet = []
	self.ReportWriter = dReportWriter(Encoding=dabo.defaultEncoding)
	self.SizerBorder = 7
	self.BorderResizable = False
	self.bizObj = dabo.biz.dBizobj
	self.recordNumber = 1
	self.MinimumSize = (233, 381)
	self.MaximumSize = (233, 381)
コード例 #4
0
	def initProperties(self):
		super(FrmReportBase, self).initProperties()
		## Do this import here: in case prerequisites aren't installed, the app
		## will still start.
		from dabo.dReportWriter import dReportWriter

		if self.ReportName:
			self.Caption = self.ReportName
		else:
			self.Caption = "Run Report"
		self.Modal = True
		self.ReportForm = None
		self.DataSet = []
		self.ReportWriter = dReportWriter(Encoding=dabo.defaultEncoding)
		self.SizerBorder = 7
コード例 #5
0
def mkpdf(ds, sample=False):
    """
    Return a pdf made from the passed dataset.
    """

    from cStringIO import StringIO

    static = '%s/static/expense_reim/'% request.folder
    xmlfile  = '%s/exp_reim.rfxml' % static

    # buffer to create pdf in
    buffer = StringIO()

    # generate the pdf in the buffer, using the layout and data
    rw = dReportWriter(OutputFile=buffer, ReportFormFile=xmlfile, Cursor=ds)
    rw.write()

    # get the pdf out of the buffer
    pdf = buffer.getvalue()
    buffer.close()

    return pdf
コード例 #6
0
ファイル: views.py プロジェクト: kamni/veyepar
def episode_pdfs(request, show_id, episode_id=None, rfxml='test.rfxml'):
    """
    Generates a pdf 
    for all episodes in a show or just one episode
    layout defined by rfxml
    """
    try:
        from dabo.dReportWriter import dReportWriter
    except ImportError:
        raise Http404("Dabo is not installed")
    
    show=get_object_or_404(Show,id=show_id)
    client = show.client

    if episode_id:
        episodes=Episode.objects.filter(id=episode_id)
    else:
        episodes=Episode.objects.filter(show=show, 
                location__active=True).order_by('location__id','start')
                # start__day=2,
                # location__name='Hays Cape'
                # location__name='Barbie Tootle'
                # location__name='Cartoon 1'
                # location__name='Cartoon 2'
                # ).order_by('location','start')

    if "day" in request.GET:
        episodes = episodes.filter( start__day=request.GET['day'] )
    if "date" in request.GET:
        episodes = episodes.filter( start__startswith=request.GET['date'] )

    base  = os.path.dirname(__file__)
    rfxmlfile  = os.path.join(base,'templates', rfxml+".rfxml")
     
    # buffer to create pdf in
    buffer = StringIO()

    # nonstandard font.  (not sure what standard is.)
    # fontfile = get_templete_abspath('badges/fonts/FreeSans.ttf')
    # pdfmetrics.registerFont(TTFont("FreeSans", fontfile))
    
    ds=[]
    for ep in episodes:
        if ep.location:
            location_name=ep.location.name
        else:
            location_name='None'
        ds.append({'episode_id':ep.id,
          'episode_conf_key':ep.conf_key,
          'episode_primary':ep.conf_key,
          'episode_name':ep.name,
          'episode_authors':ep.authors,
          'episode_emails':
            ep.emails if request.user.is_authenticated() else '',
          'episode_start':ep.start,
          'episode_duration':ep.duration,
          'episode_end':ep.end,
          'episode_released':ep.released,
          'location_name':location_name,
          'client_name':client.name,
          'show_name':show.name,
          })
        
    # generate the pdf in the buffer, using the layout and data
    rw = dReportWriter(OutputFile=buffer, ReportFormFile=rfxmlfile, Cursor=ds)
    rw.write()

    # get the pdf out of the buffer
    pdf = buffer.getvalue()
    buffer.close()

    response = HttpResponse(mimetype='application/pdf')
    e_id = episode_id if episode_id else 'all'
    filename = '_'.join( [client.slug, show.slug, e_id, rfxml] )
    response['Content-Disposition'] = \
      'filename=%s.pdf' % ( filename )
    response.write(pdf)
    return response
コード例 #7
0
ファイル: Form.py プロジェクト: xfxf/dabo
    def onQuickReport(self, evt):
        # May not have records if called via toolbar button
        if not self.enableQuickReport():
            dabo.ui.exclaim(_("Sorry, there are no records to report on."),
                            title=_("No Records"))
            return

        showAdvancedQuickReport = self.ShowAdvancedQuickReport
        showExpandedQuickReport = self.ShowExpandedQuickReport

        class ReportFormatDialog(dabo.ui.dOkCancelDialog):
            def initProperties(self):
                self.Caption = "Quick Report"
                self.mode = None
                self.records = None
                self.saveNamedReportForm = False

            def addControls(self):
                self.addObject(dabo.ui.dRadioList,
                               RegID="radMode",
                               Caption="Mode",
                               Orientation="Row",
                               Choices=["List Format", "Expanded Format"],
                               ValueMode="Key",
                               Keys={
                                   "list": 0,
                                   "expanded": 1
                               },
                               SaveRestoreValue=True)
                self.Sizer.append1x(self.radMode)
                self.Sizer.appendSpacer(12)

                if not showExpandedQuickReport:
                    self.radMode.enableKey("expanded", False)
                    self.radMode.Value = "list"  ## in case the setting was saved at 'expanded' previously.

                self.addObject(
                    dabo.ui.dRadioList,
                    RegID="radRecords",
                    Caption="Report On",
                    Orientation="Row",
                    Choices=["All records in dataset", "Just current record"],
                    ValueMode="Key",
                    Keys={
                        "all": 0,
                        "one": 1
                    },
                    SaveRestoreValue=True)
                self.Sizer.append1x(self.radRecords)
                self.Sizer.appendSpacer(12)

                if showAdvancedQuickReport:
                    self.addObject(dabo.ui.dButton,
                                   RegID="btnAdvanced",
                                   Caption="Advanced")
                    self.Sizer.append(self.btnAdvanced, halign="center")
                    self.btnAdvanced.bindEvent(dEvents.Hit, self.onAdvanced)

            def onAdvanced(self, evt):
                if dabo.ui.areYouSure(
                        "Would you like to save the report form xml "
                        "(rfxml) to your application's reports directory? If you say "
                        "'yes', you'll be able to modify the file and it will be used "
                        "as the Quick Report from now on (it will no longer be auto-"
                        "generated). The file will be generated when you click 'Yes'."
                        "\n\nGenerate the report form file?",
                        cancelButton=False):
                    self.saveNamedReportForm = True

            def runOK(self):
                self.mode = self.radMode.Value
                self.records = self.radRecords.Value

        # Name the dialog unique to the active page, so that the user's settings
        # will save and restore uniquely. They may want to usually print just the
        # current record in expanded format when on the edit page, and a list
        # format otherwise, for example.
        name = "FrmQuickReport_%s" % self.PageFrame.SelectedPage.Caption
        d = ReportFormatDialog(self, NameBase=name)
        d.show()
        mode = d.mode
        records = d.records
        saveNamedReportForm = d.saveNamedReportForm
        d.release()

        if mode is not None:
            # Run the report
            biz = self.getBizobj()
            rfxml = self.getReportForm(mode)

            if saveNamedReportForm:
                filename = os.path.join(
                    self.Application.HomeDirectory, "reports",
                    "datanav-%s-%s.rfxml" % (biz.DataSource, mode))
                if not os.path.exists(
                        os.path.join(self.Application.HomeDirectory,
                                     "reports")):
                    os.mkdir(
                        os.path.join(self.Application.HomeDirectory,
                                     "reports"))
                open(filename, "w").write(rfxml)

            if records == "all":
                cursor = biz.getDataSet()
            else:
                cursor = biz.getDataSet(rowStart=biz.RowNumber, rows=1)
            outputfile = reportUtils.getTempFile()

            try:
                import dabo.dReportWriter as drw
            except ImportError:
                dabo.ui.stop(
                    "Error importing dReportWriter. Check your terminal output."
                )
                return

            rw = drw.dReportWriter(OutputFile=outputfile,
                                   ReportFormXML=rfxml,
                                   Cursor=cursor,
                                   Encoding=biz.Encoding)
            try:
                rw.write()
            except (UnicodeDecodeError, ), e:
                #error_string = traceback.format_exc()
                error_string = ustr(e)
                row_number = rw.RecordNumber
                dabo.ui.stop(
                    "There was a problem having to do with the Unicode encoding "
                    "of your table, and ReportLab's inability to deal with any encoding "
                    "other than UTF-8. Sorry, but currently we don't have a resolution to "
                    "the problem, other than to recommend that you convert your data to "
                    "UTF-8 encoding. Here's the exact error message received:\n\n%s"
                    "\n\nThis occurred in Record %s of your cursor." %
                    (ustr(e), row_number))
                return

            # Now, preview using the platform's default pdf viewer:
            reportUtils.previewPDF(outputfile)
コード例 #8
0
ファイル: Form.py プロジェクト: biobot500/addabaji-ci
	def onQuickReport(self, evt):
		# May not have records if called via toolbar button
		if not self.enableQuickReport():
			dabo.ui.exclaim(_("Sorry, there are no records to report on."),
					title=_("No Records"))
			return

		showAdvancedQuickReport = self.ShowAdvancedQuickReport
		showExpandedQuickReport = self.ShowExpandedQuickReport

		class ReportFormatDialog(dabo.ui.dOkCancelDialog):
			def initProperties(self):
				self.Caption = "Quick Report"
				self.mode = None
				self.records = None
				self.saveNamedReportForm = False

			def addControls(self):
				self.addObject(dabo.ui.dRadioList, RegID="radMode",
						Caption="Mode",
						Orientation="Row",
						Choices=["List Format", "Expanded Format"],
						ValueMode="Key",
						Keys={"list":0, "expanded":1},
						SaveRestoreValue=True)
				self.Sizer.append1x(self.radMode)
				self.Sizer.appendSpacer(12)

				if not showExpandedQuickReport:
					self.radMode.enableKey("expanded", False)
					self.radMode.Value = "list"  ## in case the setting was saved at 'expanded' previously.

				self.addObject(dabo.ui.dRadioList, RegID="radRecords",
						Caption="Report On",
						Orientation="Row",
						Choices=["All records in dataset",
								"Just current record"],
						ValueMode="Key",
						Keys={"all":0, "one":1},
						SaveRestoreValue=True)
				self.Sizer.append1x(self.radRecords)
				self.Sizer.appendSpacer(12)

				if showAdvancedQuickReport:
					self.addObject(dabo.ui.dButton, RegID="btnAdvanced", Caption="Advanced")
					self.Sizer.append(self.btnAdvanced, halign="center")
					self.btnAdvanced.bindEvent(dEvents.Hit, self.onAdvanced)

			def onAdvanced(self, evt):
				if dabo.ui.areYouSure("Would you like to save the report form xml "
						"(rfxml) to your application's reports directory? If you say "
						"'yes', you'll be able to modify the file and it will be used "
						"as the Quick Report from now on (it will no longer be auto-"
						"generated). The file will be generated when you click 'Yes'."
						"\n\nGenerate the report form file?", cancelButton=False):
					self.saveNamedReportForm = True

			def runOK(self):
				self.mode = self.radMode.Value
				self.records = self.radRecords.Value

		# Name the dialog unique to the active page, so that the user's settings
		# will save and restore uniquely. They may want to usually print just the
		# current record in expanded format when on the edit page, and a list
		# format otherwise, for example.
		name = "FrmQuickReport_%s" % self.PageFrame.SelectedPage.Caption
		d = ReportFormatDialog(self, NameBase=name)
		d.show()
		mode = d.mode
		records = d.records
		saveNamedReportForm = d.saveNamedReportForm
		d.release()

		if mode is not None:
			# Run the report
			biz = self.getBizobj()
			rfxml = self.getReportForm(mode)

			if saveNamedReportForm:
				filename = os.path.join(self.Application.HomeDirectory, "reports",
						"datanav-%s-%s.rfxml" % (biz.DataSource, mode))
				if not os.path.exists(os.path.join(self.Application.HomeDirectory, "reports")):
					os.mkdir(os.path.join(self.Application.HomeDirectory, "reports"))
				open(filename, "w").write(rfxml)

			if records == "all":
				cursor = biz.getDataSet()
			else:
				cursor = biz.getDataSet(rowStart=biz.RowNumber, rows=1)
			outputfile = reportUtils.getTempFile()

			try:
				import dabo.dReportWriter as drw
			except ImportError:
				dabo.ui.stop("Error importing dReportWriter. Check your terminal output.")
				return

			rw = drw.dReportWriter(OutputFile=outputfile,
					ReportFormXML=rfxml,
					Cursor=cursor,
					Encoding=biz.Encoding)
			try:
				rw.write()
			except (UnicodeDecodeError,), e:
				#error_string = traceback.format_exc()
				error_string = ustr(e)
				row_number = rw.RecordNumber
				dabo.ui.stop("There was a problem having to do with the Unicode encoding "
						"of your table, and ReportLab's inability to deal with any encoding "
						"other than UTF-8. Sorry, but currently we don't have a resolution to "
						"the problem, other than to recommend that you convert your data to "
						"UTF-8 encoding. Here's the exact error message received:\n\n%s"
						"\n\nThis occurred in Record %s of your cursor." % (ustr(e), row_number))
				return

			# Now, preview using the platform's default pdf viewer:
			reportUtils.previewPDF(outputfile)
コード例 #9
0
def mkpdf(ds, sample=False):
    """
    Return a pdf made from the passed dataset.
    Sample - True when creating a sample badge, 
             includes graphics and perf lines.
    """

    try: from cStringIO import StringIO
    except: err_missing('cStringIO library not installed;')

    try:
	from reportlab.pdfbase import pdfmetrics
	from reportlab.pdfbase.ttfonts import TTFont
    except: err_missing('python-reportlab library missing;')

    try: from dabo.dReportWriter import dReportWriter
    except: err_missing('Dabo Reportwriter not installed.')

    import os

    static_path = '%sstatic/badges/'% request.folder
    xmlfile  = '%s/badge_full.rfxml' % static_path

    # buffer to create pdf in
    buffer = StringIO()

    # register fonts (hardcoded is lame.)  
    # reportlab has some code, trying to figure out how to use it.)
    
    # check the fonts are installed on the system;  error page if not:

    if not (os.access(TRUETYPE_PATH,os.R_OK)|os.access(GSFONTS_PATH,os.R_OK)):
	err_missing('Missing fonts; unable to generate badge(s).')
                 
    pdfmetrics.registerFont(TTFont("FreeSans", "%s/FreeSans.ttf" % TRUETYPE_PATH))

# what happens here if these font paths don't exist?
#  will pdfmetrics handle the error gracefully, or do you need try/except here?
    afmFile = os.path.join(GSFONTS_PATH, 'n019004l.afm')
    pfbFile = os.path.join(GSFONTS_PATH, 'n019004l.pfb')
    justFace = pdfmetrics.EmbeddedType1Face(afmFile, pfbFile)
    faceName = 'NimbusSanL-Bold' # pulled from AFM file
    pdfmetrics.registerTypeFace(justFace)
    justFont = pdfmetrics.Font('NimbusSanL-Bold',
                               faceName,
                               'WinAnsiEncoding')
    pdfmetrics.registerFont(justFont) 

    afmFile = os.path.join(GSFONTS_PATH, 'n019003l.afm')
    pfbFile = os.path.join(GSFONTS_PATH, 'n019003l.pfb')
    justFace = pdfmetrics.EmbeddedType1Face(afmFile, pfbFile)
    faceName = 'NimbusSanL-Regu' # pulled from AFM file
    pdfmetrics.registerTypeFace(justFace)
    justFont = pdfmetrics.Font('NimbusSanL-Regu',
                               faceName,
                               'WinAnsiEncoding')
    pdfmetrics.registerFont(justFont) 
    # end of register fonts code.

    for row in ds:

        # make a barcode for each row, add it to the dataset
        wad=ds_to_wad(row)
        row['barcode']=mk_barcode(wad)
    
        # bod: badge on demand.  
        # set bod in each row
        row['bod']=not sample


    # generate the pdf in the buffer, using the layout and data
    try:
        rw = dReportWriter(OutputFile=buffer, ReportFormFile=xmlfile, Cursor=ds)
        rw.write()
    except:
        err_missing('ReportWriter write failing... ')

    # get the pdf out of the buffer
    pdf = buffer.getvalue()
    buffer.close()

    return pdf