class MyViewA(Page): grok.context(Interface) grok.name('myview') grok.layer(IDefaultLayer) def render(self): return "MYVIEW"
class MyViewB(Page): grok.context(Interface) grok.name('myview') grok.layer(IAnotherLayer) def render(self): return "MYVIEW"
class ContentProvider(grok.ContentProvider): grok.name('foo') grok.context(Interface) grok.template('contentprovider') def render(self): """There's also a template!
class LayeredPot(grok.ContentProvider): grok.name('pot') grok.context(Interface) grok.layer(IBoneLayer) def render(self): return u"Layered pot"
class CaveView(grok.View): grok.context(Cave) def render(self): return self.static['resource.css']()
class AOneLayout(Layout): grok.context(One) grok.layer(IALayer) def render(self): return "Layout A for context One"
class ViewOne(Page): grok.context(Interface) def render(self): return "MyView on regular layout"
class LayoutOne(Layout): grok.context(One) def render(self): return "Layout One"
class BOneLayout(Layout): grok.context(One) grok.layer(IBLayer) def render(self): return "Layout B for context One"
class Painting(grok.View): grok.context(zope.interface.Interface) grok.require(ViewPainting) def render(self): return 'What a beautiful painting.'
class BLayout(Layout): grok.context(B) grok.layer(IAnotherLayer) def render(self): return "B Layout"
class A2Layout(Layout): grok.context(A) grok.layer(IAnotherLayer) def render(self): return "A2 Layout"
class ALayout(Layout): grok.context(A) grok.layer(IDefaultLayer) def render(self): return "A Layout"
class BogusView(grok.View): grok.context(zope.interface.Interface) @grok.require(Bogus) def render(self): pass
class MyView(Page): grok.context(Interface) grok.layer(IALayer) def render(self): return "MyView on IALayouer"
class BTwoLayout(Layout): grok.context(Two) grok.layer(IBLayer) def render(self): return "Layout B for context Two"
class Food(grok.View): grok.context(Mammoth)
When providing a skin **name**, it will be injected in the URLs: >>> index_view.url(skin='foobar') 'http://127.0.0.1/++skin++foobar/herd/manfred/test' """ import six import grokcore.view as grok from zope.container.contained import Contained class Mammoth(Contained): pass grok.context(Mammoth) class Index(grok.View): def render(self): return self.url() class Another(grok.View): def render(self): return self.url() class YetAnother(grok.View): pass
class BaseView(grok.View): grok.template('basetemplate') grok.context(object)
class Index(grok.View): grok.context(zope.interface.Interface) def render(self): return u"Hi"
class PublicNudity(grok.View): grok.context(zope.interface.Interface) grok.require(grok.Public) def render(self): return 'Everybody can see this.'
class ATwoLayout(Layout): grok.context(Two) grok.layer(IALayer) def render(self): return "Layout A for context Two"
>>> index_view.url(skin=AnotherURLTestingSkin) 'http://127.0.0.1/++skin++anotherurltesting/herd/manfred/test' When providing a skin **name**, it will be injected in the URLs: >>> index_view.url(skin='foobar') 'http://127.0.0.1/++skin++foobar/herd/manfred/test' """ import grokcore.view as grok from zope.container.contained import Contained class Mammoth(Contained): pass grok.context(Mammoth) class Index(grok.View): def render(self): return self.url() class Another(grok.View): def render(self): return self.url() class YetAnother(grok.View): pass class Multiplier(grok.View): def update(self, age=0): self.age = age
class CaveView(grok.View): grok.context(Cave)
class ClubContentProvider(grok.ContentProvider): grok.name('manage.clubmen') grok.context(Club) def render(self): pass
class CaveView(grok.View): grok.context(Interface)
class LayoutTwo(Layout): grok.context(One) grok.provides(ILayoutTwo) def render(self): return "Layout Two"
class Pot(grok.ContentProvider): grok.context(Interface) def render(self): return u"Soup pot"
class ViewTwo(Page): grok.context(Interface) layout(ILayoutTwo) def render(self): return "MyView on layout two"
class LandingPage(ApplicationForm): grok.context(interface.IInvoiceUploader) grok.name("index") grok.require("zope.Public") fields = Fields(interface.IInvoice) def update(self): resource.style.need() @action("Senden") def handel_save(self): data, errors = self.extractData() if errors: self.flash(u'Es sind leider Fehler aufgetreten') return if data['anrede'] == '': self.flash(u'Bitte wählen Sie eine Anrede aus.') return if data['email'] != '': checkmail = re.compile( r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$").match if not bool(checkmail(data['email'])): self.flash( u'Bitte tragen Sie eine gültige E-Mail Adresse ein.') return if data['datenschutz'] is False: self.flash( u'Bitte bestätigen Sie die Datenschutzerklärung der UKH.') return for x in data['anlagen']: if x == NO_VALUE: self.flash(u'Sie haben keine Dateien zum Upload ausgewählt!') return output_path = settings.get('output_path') pdfstreams = [] pdf_fn = UploadPdf(data, None) for attachment in data.get('anlagen'): print attachment.filename if "pdf" in attachment.filename: pdfstreams.append(attachment) elif "heic" in attachment.filename: from backports.tempfile import TemporaryDirectory with TemporaryDirectory() as tmpdirname: ifn = '%s/%s' % (tmpdirname, attachment.filename) ofn = '%s/%s.jpg' % (tmpdirname, attachment.filename) import pdb pdb.set_trace() with open(ifn, 'wb') as heic: heic.write(attachment.read()) subprocess.call(["heif-convert", ifn, ofn]) with open(ofn, 'rb') as f: rgbimage = Image.open(f) jpegimage = StringIO() rgbimage.save(jpegimage, format="JPEG") jpegimage.seek(0) pdfimage = img2pdf.convert(jpegimage) pdfstreams.append(StringIO(pdfimage)) elif "jpeg" in attachment.filename or 'jpg' or 'png' in attachment.filename: pilimage = Image.open(attachment) if pilimage.mode == "RGBA": rgbimage = pilimage.convert("RGB") else: rgbimage = pilimage jpegimage = StringIO() rgbimage.save(jpegimage, format="JPEG") jpegimage.seek(0) pdfimage = img2pdf.convert(jpegimage) pdfstreams.append(StringIO(pdfimage)) deckblatt = PdfFileReader(pdf_fn) fn_base = datetime.now().strftime('%Y%m%d_%H%M%S') for i, reader in enumerate(map(PdfFileReader, pdfstreams)): output_file = "%s/%s_%s.pdf" % (output_path, fn_base, i) logger.info('Write File %s' % output_file) writer = PdfFileMerger() with open(output_file, 'wb') as output: writer.append(deckblatt) writer.append(reader) writer.write(output) #for n in range(reader.getNumPages()): # writer.addPage(reader.getPage(n)) # writer.write(output) self.flash(u'Vielen Dank, wir haben Ihre Dateien erhalten.') self.redirect(self.application_url())