Changeset 15880 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 11 Dec 2019, 12:02:09 (5 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/browser/pdf.py
r15834 r15880 802 802 if not getattr(doc, 'kofa_nodate', False): 803 803 tz = getattr(queryUtility(IKofaUtils), 'tzinfo', pytz.utc) 804 #tz = getUtility(IKofaUtils).tzinfo805 804 today = now(tz).strftime('%d/%m/%Y %H:%M:%S %Z') 806 805 canvas.drawString(2.2*cm, 0.5 * inch, … … 811 810 canvas.kofa_footer_text = doc.kofa_footer 812 811 canvas.restoreState() 813 canvas.restoreState()814 812 815 813 # Metadata … … 820 818 821 819 def create_pdf(self, data, headerline=None, title=None, author=None, 822 footer='', note=None, sigs_in_footer=[], topMargin=1.5): 820 footer='', note=None, sigs_in_footer=[], topMargin=1.5, 821 letterhead_path=None): 823 822 """Returns a binary data stream which is a PDF document. 824 823 """ 825 824 pdf_stream = StringIO() 826 825 bottomMargin = len(sigs_in_footer) and 1.9*inch or 1.2*inch 827 topMargin += title.count('\n') * 0.2 826 if letterhead_path: 827 topMargin += 1.2 828 else: 829 topMargin += title.count('\n') * 0.2 828 830 doc = SimpleDocTemplate( 829 831 pdf_stream, … … 841 843 doc.kofa_footer = footer 842 844 doc.sigs_in_footer = sigs_in_footer 845 doc.letterhead_path = letterhead_path 843 846 if note is not None: 844 847 html = format_html(note) … … 859 862 pagesize = landscape(A4) 860 863 864 class LetterPDFCreator(PDFCreator): 865 """A utility to help with generating PDF docs with an original letterhead. 866 """ 867 grok.name('letter') 868 letterhead_pos = [0, 0] 869 870 def paint_background(self, canvas, doc): 871 """Paint letterhead background of a PDF. 872 873 The `doc` is expected to be some reportlab SimpleDocTemplate 874 or similar object. 875 876 This is a callback method that will be called from reportlab 877 when creating PDFs with :meth:`create_pdf`. 878 """ 879 canvas.saveState() 880 width, height = doc.width, doc.height 881 width += doc.leftMargin + doc.rightMargin 882 height += doc.topMargin + doc.bottomMargin 883 884 # Letterhead 885 if doc.letterhead_path is not None: 886 canvas.saveState() 887 canvas.drawImage(doc.letterhead_path, 888 self.letterhead_pos[0], self.letterhead_pos[1], 889 width=width, height=height) 890 canvas.restoreState() 891 892 # Footer 893 if getattr(doc, 'sigs_in_footer', False): 894 self._drawSignatureBoxes( 895 canvas, width, height, doc.sigs_in_footer) 896 #canvas.line(2.2*cm, 0.62*inch, width-2.2*cm, 0.62*inch) 897 canvas.setFont("Helvetica", 9) 898 if not getattr(doc, 'kofa_nodate', False): 899 tz = getattr(queryUtility(IKofaUtils), 'tzinfo', pytz.utc) 900 today = now(tz).strftime('%d/%m/%Y %H:%M:%S %Z') 901 #canvas.drawString(2.2*cm, 0.5 * inch, 902 # translate(_(u'Date: ${a}', mapping = {'a': today}))) 903 canvas.drawString(2.2*cm, 0.3 * inch, 904 translate(_(u'Date: ${a}', mapping = {'a': today}))) 905 # set canves attributes needed to render `page x of y` 906 canvas.kofa_footer_x_pos = width-2.2*cm 907 #canvas.kofa_footer_y_pos = 0.5 * inch 908 canvas.kofa_footer_y_pos = 0.3 * inch 909 canvas.kofa_footer_text = doc.kofa_footer 910 canvas.restoreState() 911 912 # Metadata 913 title = getattr(doc, 'kofa_title', '') 914 canvas.setAuthor(getattr(doc, 'kofa_author', 'Unknown')) 915 canvas.setSubject(title) 916 canvas.setCreator(u'WAeUP Kofa') 917 return 918 919 861 920 class A3LandscapePDFCreator(LandscapePDFCreator): 862 921 """A utility to help with generating PDF docs in -
main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py
r15865 r15880 22 22 import pytz 23 23 import sys 24 import os 24 25 import textwrap 25 26 from cStringIO import StringIO … … 543 544 def render(self): 544 545 students_utils = getUtility(IStudentsUtils) 546 letterhead_path = os.path.join( 547 os.path.dirname(__file__), 'static', 'letterhead_admission.jpg') 548 if not os.path.exists(letterhead_path): 549 letterhead_path = None 545 550 return students_utils.renderPDFAdmissionLetter(self, 546 self.context.student, omit_fields=self.omit_fields) 551 self.context.student, omit_fields=self.omit_fields, 552 letterhead_path=letterhead_path) 547 553 548 554 class StudentBaseManageFormPage(KofaEditFormPage): -
main/waeup.kofa/trunk/src/waeup/kofa/students/fileviewlets.py
r15833 r15880 24 24 IExtFileStore, IFileStoreNameChooser, IKofaObject, IKofaUtils) 25 25 from waeup.kofa.utils.helpers import string_from_bytes, file_size 26 from waeup.kofa.browser import DEFAULT_IMAGE_PATH27 26 28 27 from waeup.kofa.students.interfaces import IStudent, IStudentsUtils -
main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py
r15790 r15880 145 145 146 146 def renderPDFAdmissionLetter(view, student=None, omit_fields=(), 147 pre_text=None, post_text=None,): 147 pre_text=None, post_text=None, 148 letterhead_path=None): 148 149 """Render pdf admission letter. 149 150 """ -
main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py
r15879 r15880 859 859 860 860 def renderPDFAdmissionLetter(self, view, student=None, omit_fields=(), 861 pre_text=None, post_text=None,): 861 pre_text=None, post_text=None, 862 letterhead_path=None): 862 863 """Render pdf admission letter. 863 864 """ … … 865 866 return 866 867 style = getSampleStyleSheet() 867 creator = self.getPDFCreator(student) 868 if letterhead_path: 869 creator = getUtility(IPDFCreator, name='letter') 870 else: 871 creator = getUtility(IPDFCreator) 868 872 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 869 873 data = [] … … 912 916 pdf_stream = creator.create_pdf( 913 917 data, None, doc_title, author=author, footer=footer_text, 914 note=post_text )918 note=post_text, letterhead_path=letterhead_path) 915 919 return pdf_stream 916 920
Note: See TracChangeset for help on using the changeset viewer.