[Zope3-Users] Using z3c.table in a grok view?

2008-06-01 Thread Adam Summers
Hi, forgive the double posting. My membership to grok-dev hasn't been  
approved yet...





Hi there,

I'm trying to get a better feel for grok so that I  can evaluate for  
an upcoming project - so far, its been a relatively painless  
experience!


However, I've been using Paul Carduner's guide to the z3c packages (http://carduner.net/docs/z3c-tutorial/ 
) and thought I would try out using z3c.table, and have hit a  
stumbling block


I have a view, thus:

class Index(grok.View):
grok.context(gehar)

def __init__(self, context, request):
super(Index, self).__init__(context, request)
self.tableView = table.Table(context, request)

(note I can't have Index inherit z3c.table.Table, as Table's  
render() method causes conflicts with my index.pt)

and in my corresponding index.pt I can have the following:

p Here is the table from z3c.table /p
  div tal:replace=structure python:view.tableView.renderTable() /


So far, so good -- no table gets displayed though, as I haven't  
registered columns as named multiadapters. This is where things go  
pear shaped.


I have in my code the following -- can someone see what I'm doing  
wrong?


from z3c.table import table, column

class NameColumn(column.GetAttrColumn, grok.MultiAdapter):
grok.name('nameCol')
grok.adapts(table.interfaces.ITable)
grok.provides(table.interfaces.IColumn)
header = u'Name'
attrname = 'who'
weight = 1

Once I get an answer, I can write it up as a howto.

Thanks in advance for any help :)
Regards,
Adam




--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] formlib vs z3c.form

2007-12-06 Thread Adam Summers


Hi,

A quick, blind question.

I've been evaluating grok and am very impressed at how easy it makes the 
whole development process.


How hard is it to get grok to play nicely with z3c.form et al? Has 
anyone any examples?


Thanks and Regards,
Adam



Christophe Combelles wrote:

Chris Withers a écrit :

Chris Withers wrote:

I need something like formlib so want to give it a spin.

Is there a good how-to or example anywhere?


Kapil rightly pointed out off-list that z3c.form is the latest and 
greatest.


Which one is best and where do I go for docs/examples?


The main doc is the doctest, you can read it just here:
http://pypi.python.org/pypi/z3c.form

The second doc is the code of z3c.formdemo.
http://pypi.python.org/pypi/z3c.formdemo

you will also find some interesting informations here:
http://pcardune.blogspot.com/2007/05/using-z3c-pagelettemplatelayout.html
http://www.lovelysystems.com/srichter/2006/09/20/the-skin-browser-and-lovely-systems-new-development-workflow/ 



But the most interesting source of information is the archive of this 
list. It's best if you have it localy, otherwise:

http://www.mail-archive.com/search?q=z3c.forml=zope3-users%40zope.org

If you carefully read all the previous questions asked about z3c.form 
on the list, you will first save an afternoon discovering why you need 
to derive IFormLayer in your skin, then another afternoon discovering 
how to implement an Add SubForm, and probably many others :)


I personnally suggest you to try z3c.form alone first, without any 
other z3c package. It will progressively help you understand why 
others are extremely useful (though not mandatory), such as 
z3c.formui, z3c.layer, and others.


Christophe



cheers,

Chris



___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Time for a Decimal field type in zope.schema?

2007-04-27 Thread Adam Summers

Hi,

Did the inclusion of Darryl's code ever get off the ground? I can't find
a Decimal in zope.schema in Zope3.3.1 ...

Regards,
Adam

Marius Gedminas wrote:

On Thu, 31 Aug 2006 20:29:49 +0700 Darryl Cousins
[EMAIL PROTECTED] wrote:
  

On Thu, 2006-08-31 at 15:07 +0300, Marius Gedminas wrote:


I am going to work on this today.
  

For what it may be worth, a Decimal field:

Code:
http://projects.treefernwebservices.co.nz/tfws.org.nz/file/trunk/src/tfws/field/field.py
Doctest:
http://www.tfws.org.nz/tfws.field.README.html



Looks nice.  Would you consider contributing it for the inclusion into the
Zope 3 core?  (I see that it is already licenced under the ZPL, but I do
not think I can just commit it into the Zope 3 repository under a different
name.)

I am attaching the diff showing my current working version, which mirrors
the existing zope.schema.Float field more closely.  As far as I can tell
your field/widget is better.  The only thing I do not see is a registration
for a IDisplayWidget.

Marius Gedminas
  



___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users



___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Should I be using a more basic form in Formlib than EditForm?

2006-12-30 Thread Adam Summers
Hi all,  


I have an edit form:
class claimEditForm(form.EditForm):
   form_fields = form.Fields(Iclaim).omit('__name__', '__parent__')

   @form.action(_(MyApply), condition=form.haveInputWidgets)   
   def handle_edit_action(self, action, data):

   if self.context.modify(data):
   self.status = _(uObject Updated)
   else:
   self.status = _(uNo Changes)

The object has a modify method, which looks like this:
   def modify(self, kw):
   fieldnames = getFieldNames(Iclaim)
   for k in kw.keys():
   if k not in fieldnames:
   raise Invalid(Invalid Field to set: %s, k)
   else:
   field = Iclaim[k]
   field.validate(kw[k])
   setattr(self, k, kw[k])
   self._completeValues() ###This method calculates some missing 
data for the object (if possible) or raises an error

   Iclaim.validateInvariants(self)
   return True

The thing I don't understand is this: The invariant method I have in the 
interface is being called twice.


First Pass through, object passed to my invariant is of type:
   FormData: zope.formlib.form.FormData instance at 0x3f07c10

Call stack is:
   debug_call [publish.py:114]   
   __call__ [form.py:773]   
   update [form.py:740]   
   handleSubmit [form.py:683]   
   validate [form.py:720]   
   checkInvariants [form.py:504]   
   validateInvariants [interface.py:583]   
   claimInvariants [interfaces.py:39]


(In certain cases the data will be invalid, because I need to prep a few 
fields via claim._completeValues() )


Second Pass through, object passed to my invariant function is of type:
   claim: as.claim.claim.claim object at 0x3591770

Call stack is:
   debug_call [publish.py:114]
   __call__ [form.py:773]
   update [form.py:754]
   success [form.py:598]
   handle_edit_action [forms.py:23] (This is my action being called 
now!)
   modify [claim.py:42] (At this point in the code, the 
as.claim.claim.claim object has been modified with the contents of the 
form)
   validateInvariants [interface.py:583]
   claimInvariants [interfaces.py:39]
 

My question is: In order to not have the variants checked before my data 
is prepped, should I really be using a form.EditForm as the base, or 
some other class?


Many thanks in advance, and a happy new year
Adam

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Re: Should I be using a more basic form in Formlib than EditForm?

2006-12-30 Thread Adam Summers




Once more, with formatting:

Hi all, 

I have an edit form:

class claimEditForm(form.EditForm):
  
 form_fields = form.Fields(Iclaim).omit('__name__', '__parent__')
  
  
 @form.action(_("MyApply"), condition=form.haveInputWidgets)  
 def handle_edit_action(self, action, data):
  
 if self.context.modify(data):
  
 self.status = _(u"Object Updated")
  
 else:
  
 self.status = _(u"No Changes")
  
  

The object has a modify method, which looks like this:


 def modify(self, kw):
  
 fieldnames = getFieldNames(Iclaim)
  
 for k in kw.keys():
  
 if k not in fieldnames:
  
 raise Invalid("Invalid Field to set: %s", k)
  
 else:
  
 field = Iclaim[k]
  
 field.validate(kw[k])
  
 setattr(self, k, kw[k])
  
 self._completeValues() ###This method calculates some missing
data for the ###object (if possible)
or raises an error
  
 Iclaim.validateInvariants(self)
  
 return True
  


The thing I don't understand is this: The invariant method I have in
the interface is being called twice.


First Pass through, object passed to my invariant is of type:

 FormData: zope.formlib.form.FormData instance at
0x3f07c10


Call stack is:

 debug_call [publish.py:114]
  __call__ [form.py:773]
  update [form.py:740]
  handleSubmit [form.py:683]
  validate [form.py:720]
  checkInvariants [form.py:504]
  validateInvariants [interface.py:583]
  claimInvariants [interfaces.py:39]


(In certain cases the data will be invalid, because I need to prep a
few fields via claim._completeValues() )


Second Pass through, object passed to my invariant function is of type:

 claim: as.claim.claim.claim object at 0x3591770


Call stack is:

 debug_call [publish.py:114]
__call__ [form.py:773]
update [form.py:754]
success [form.py:598]
handle_edit_action [forms.py:23] (This is my action
being called now!) 
modify [claim.py:42] (At this point in the code, the
as.claim.claim.claim object has been modified with the contents of the
form)
validateInvariants [interface.py:583]
claimInvariants [interfaces.py:39] 
  


My question is: In order to not have the variants checked before my
data is prepped, should I really be using a form.EditForm as the base,
or some other class?


Many thanks in advance, and a happy new year

Adam






___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] how to examine parent attributes in add process?

2006-12-30 Thread Adam Summers

Hi all,

I have an object which when editing, checks for some attributes in the 
parents containing folder by using the following type of code: (this is 
called during a form.Editform call)


   def _completeValues(self):
   if self.a is None  and  self.__parent__.def_c == self.c:
   my_a  = self.__parent__.def_c * 2
   setattr(self,'a',my_a)

Of course, for edits, this all works fine. However, how should I examine 
values in the containing object during an Adding process, where 
__parent__ would be None?


Thanks and Regards,
Adam


___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Custom Image Widget - Solution

2006-12-17 Thread Adam Summers




Hi Tom  all,

First of all, thanks for the help. Its much appreciated :) I understand
what you're suggesting, but I needed a way to do it without traversal.
For what I'm trying to do, the interface and implementation of the zope
objects need to be as simple as possible - anything fancy needs to be
(if possible) outside the interface/implementation (like in a widget)

I attached what I ended up doing for the widget and the form. Its
nothing radical, and very crude, but it works.

(The supdoc attribute in the form is defined as 
supDoc = List(title=_(u"Supporting Docs List"), value_type=Object(IImage, __name__='ImgItem', title=_(u"Image")))
 
 
anyway, hope this helps anyone who gets stuck on this sort of thing.

Again, thanks.
Adam

Tom Dossis wrote:

  Adam Summers wrote:
  
  
Hi Tom  Widget Afficionados.

Thanks for the help so far.

My problem is now this:

From this code (which Tom supplied), how do I code the logic (in
bold)  

def _toFieldValue(self, input):
data = "" self)._toFieldValue(input)
if data is not None:
img = Image(data)
notify(ObjectCreatedEvent(img))
return img
	*else: #data is None, ie. the File input field was left blank and we don't want to 
	#replace the current value of the Image Widget with an empty value.
	currentImg = the Image object which the field is being rendered for
	return currentImg 

*

I can't rely on

	field = self.context

image = field.get(field.context)


logic to find the data, because my schema can contain:

class Iclaim(IContained):

	"""Claim"""

	supDoc = List(title=_(u"Supporting Docs List"), value_type=Object(IImage, __name__='ImgItem', title=_(u"Image")))

	img = Object(IImage, title=_(u"Single img"), required=False)


And hence, the self.context.context points to the claim object, not
the list inside when rendering supDoc

  
  
Hi Adam,
You can rely on:

  field = self.context
  image = field.get(field.context)

because the widget is for an attribute object of type IImage.

Your supDoc attribute object is a List Type - not an IImage.
In this case you'd need another widget - for a list of IImage.

I wouldn't been too keen to tackle the html work effort and would
probably look at an alternative along the lines of...

class IImageList(IContainer):
  contains(zope.app.image.interfaces.IImage)

class IClaim(IContained):
  supDoc=Object(schema=IImageList)

Make supDoc traversable, then you wouldn't need the custom widget here
because you can store Images directly in supDoc view with the
browser:containerView's.
  




from zope.app.form import CustomWidgetFactory
from zope.app.form.browser.widget import DisplayWidget, SimpleInputWidget, 
renderElement
from zope.app.form.browser.sequencewidget import ListSequenceWidget, 
SequenceDisplayWidget
from zope.app.file.image import Image
from zope.app.form.interfaces import ConversionError
from base64 import b64encode, b64decode



class MyImageDisplayWidget(DisplayWidget):

def __call__(self):

mycontent = u(No Image)

if self._renderedValueSet() and self._data is not None:
mycontent = buildHTMLImg(self._data.data)
return mycontent

MyImageListDisplayWidget = CustomWidgetFactory(SequenceDisplayWidget, subwidget 
= MyImageDisplayWidget)

class MyImageInputWidget(SimpleInputWidget):
File Widget
type = 'file'

def _toFieldValue(self, input):
if (input is None or input == ''):
try:
imgData =  b64decode(self.request.form[self.name + 
'.data'])
return Image(imgData)
except AttributeError, e:
return self.context.missing_value
else:   
try:
seek = input.seek
read = input.read
except AttributeError, e:
raise ConversionError(_('Form input is not a file object'), 
e)
else:
seek(0)
data = read()
if data or getattr(input, 'filename', ''):
return Image(data)
else:
return self.context.missing_value


def __call__(self):
elem = renderElement(self.tag,
 type=self.type,
 name=self.name,
 id=self.name,
 extra=self.extra)
input_widget = elem

try: 
img_widget = buildHTMLImg(self._data.data)
elem = renderElement(self.tag,
 type='hidden',
 name=self.name+'.data',
 id=self.name,
 extra='value=' + b64enc

Re: [Zope3-Users] Custom Image Widget

2006-12-14 Thread Adam Summers




Hi Tom  Widget Afficionados.

Thanks for the help so far.

My problem is now this:

 From this code (which Tom supplied), how do I code the logic (in
bold)   

def _toFieldValue(self, input):
data = "" self)._toFieldValue(input)
if data is not None:
img = Image(data)
notify(ObjectCreatedEvent(img))
return img
	else: #data is None, ie. the File input field was left blank and we don't want to 
	#replace the current value of the Image Widget with an empty value.
	currentImg = the Image object which the field is being rendered for
	return currentImg 


I can't rely on 


  	field = self.context
  image = field.get(field.context)


logic to find the data, because my schema can contain:

class Iclaim(IContained):
	"""Claim"""
	supDoc = List(title=_(u"Supporting Docs List"), value_type=Object(IImage, __name__='ImgItem', title=_(u"Image")))
	img = Object(IImage, title=_(u"Single img"), required=False)

 And hence, the self.context.context points to the claim object, not
the list inside when rendering supDoc
Again, any help is much appreciated.
Regards,
Adam

Tom Dossis wrote:

  Adam Summers wrote:
  
  
Hi,

I have the following widgets.


class MyImageDisplayWidget(DisplayWidget):

   class_ = Image

   def __call__(self):
   mycontent = u"oops! no img"
   if self._renderedValueSet():
   mycontent = "img src="" class="moz-txt-link-rfc2396E" href="data:image/gif;base64,">"data:image/gif;base64, " +
b64encode(self._data.data) + " \" /"
   return mycontent

MyImageListDisplayWidget = CustomWidgetFactory(SequenceDisplayWidget,
subwidget = MyImageDisplayWidget)

class MyImageWidget(FileWidget):

   class_ = Image

   def _toFieldValue(self, input):
   value = super(MyImageWidget, self)._toFieldValue(input)
   return self.class_(value)

MyImageListWidget = CustomWidgetFactory(ListSequenceWidget, subwidget =
MyImageWidget)

I want to build a better input widget (MyImageWidget), so that we can do
the following:
   * If the field has no data, display a file input.
   * If the field has data, display the image.

I know that there are design shortcomings in this, but I need a simple
example (and I only use the files in lists anyway, so I can delete images).

Any pointers on how to go about this would be much appreciated; as always

  
  

Hi Adam,

I'm not exactly sure of your use case, but I've included a widget
implementation (see below) which you may find useful.  I've used this
widget for an attribute which is an IImage, e.g.

  


snip

  
class ImageInputWidget(FileWidget):

def _toFieldValue(self, input):
data = "" self)._toFieldValue(input)
if data is not None:
img = Image(data)
notify(ObjectCreatedEvent(img))
return img

def __call__(self):
input_widget = super(ImageWidget, self).__call__()
try:
image = ImageDisplayWidget(self.context, self.request)()
info = self.info()
return u'br /'.join([image, info, input_widget])
except AttributeError:
# This happens because the context is IAdding
return input_widge

/snippet


___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Custom Image Widget

2006-12-11 Thread Adam Summers

Hi,

I have the following widgets.


class MyImageDisplayWidget(DisplayWidget):

   class_ = Image

   def __call__(self):
   mycontent = uoops! no img
   if self._renderedValueSet():
   mycontent = img src=\data:image/gif;base64,  +
b64encode(self._data.data) +  \ /
   return mycontent

MyImageListDisplayWidget = CustomWidgetFactory(SequenceDisplayWidget,
subwidget = MyImageDisplayWidget)

class MyImageWidget(FileWidget):

   class_ = Image

   def _toFieldValue(self, input):
   value = super(MyImageWidget, self)._toFieldValue(input)
   return self.class_(value)

MyImageListWidget = CustomWidgetFactory(ListSequenceWidget, subwidget =
MyImageWidget)

I want to build a better input widget (MyImageWidget), so that we can do
the following:
   * If the field has no data, display a file input.
   * If the field has data, display the image.

I know that there are design shortcomings in this, but I need a simple
example (and I only use the files in lists anyway, so I can delete images).

Any pointers on how to go about this would be much appreciated; as always

Thanks and Regards,
Adam



___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] schema field for an Image?

2006-12-06 Thread Adam Summers

Hi,

Tom Dossis wrote:

Sascha Ottolski wrote:
  
I'm wondering if anything already exists, that would allow me to define 
a schema like (pseudo)


IPerson(Interface):

image = File(
max_size=100,
)

Person(Persistent):
implements(IPerson)

image = FileProperty(form_fields['image'])

with the result, that the image attribute behaves pretty much like an 
IImage, that is, has contentType and size associated with it, and might 
be easily displayed with the help of something like 
zope.app.file.browser.image.ImageData.


I already tried to create such a Property, as well as using 
schema.Object, but wasn't really successfull :-(



Hi Sacha, I've used something like this...

class IPerson(Interface):
  image=schema.Object(
schema=zope.app.file.interfaces.IImage,
required=False, # You may need this depending on validation needs..
)

class Person(Persistent):
  implements(IPerson)
  image=FieldProperty(IPerson['image'])


  
If I wanted to use formlib to build the form, and wanted to build a HTML 
widget for the image field that had a
file input for uploading, and if img already had content woudl display a 
thumbnail; how would I go about this? I'm afraid I'm lost because its 
schema.Object that the widget would apply to (but I'm not sure).


regards,
Adam



If you want to make the image attribute traversable (via the url) the
z3c.traverser package can do the job.

  
Of course, I can do all this by hand for each content object by adding 
a contentType attribute and providing some views, but I have the 
feeling that there would exist a smarter way to to this.


Adding to this, is there a way to register views with fuzzy names? 
Think of a class


Person:

resume = File()

Now, to help the logfile analyzer, I would like to have a view 
named resume.%s', so that if resume is a Word document, it could be 
accesed as /person1/resume.doc, if resume is PDF, access would 
be /person1/resume.pdf. I could register several views for common 
suffixes, but than there comes a buy with one no one thought of. May be 
this is a stupid idea anyway :-)



Have a look at zope.publisher.interfaces.IPublishTraverse to hook in
your own handler for traversing a Person object.

regards,
-Tom

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users
  



___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Examples

2006-02-08 Thread Adam Summers

Hi,

My two cents worth -

   A lot of time is spent saying Zope3 is different to Zope2 -- its 
better (and I wholeheartedly agree). However, there is a lot of stuff 
which is in the zope 2 books which is applicable to zope3, but is 
absent. eg: ZPT design, SQL integration. Is it possible for those 
relevant chapters to be merged in with the zope3 documentation?


Regards,
Adam

Stephan Richter wrote:

On Friday 13 January 2006 16:45, David Johnson wrote:
  

I'm having trouble getting comfortable with how to architect applications
in Zope 3.  Does anyone know of specific examples or sites that would
provide ideas?  For example, I've having trouble with SQL integration and
passing parameters with ZPT, building menus and navigation, and setting up
logins/managing users.



Did you read the books? They cover quite a bit of information. There are also 
several sample apps out there that you can use as examples.


Regards,
Stephan
  



___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Re: Zope 3 Marketing Competition? (was Re: [Zope3-dev] Re: Selecting a code name)

2006-02-07 Thread Adam Summers
Despite my silence, I have been watching this with interest - I think 
its a great way to get moving. +2 for me :)


Regards,
Adam

Paul Everitt wrote:

Stephan Richter wrote:

On Monday 06 February 2006 20:49, Gary Poster wrote:

How about we have a marketing competition? :-)


+1 from me plus everything else you said below.


Yep, it's a good idea.

--Paul

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users



___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Building PDF files using reportlab, with image objects in Zope3

2006-01-02 Thread Adam Summers

Hi,

I'm trying to build a report using zope3 + reportlab 1.20 that I want to 
contain some images from a container (which in the code below is called 
'item').


Has anyone done this? Can they suggest a technique?

Trying the following:
   images = []
   for docpage in item.values():
   f = tempfile.TemporaryFile()
   f.write(docpage.data)
   width, height = docpage.getImageSize()
   images.append( Image(f, width=width, height=height) )


Only gets me as far as an error (when the images list is placed on the 
list containing the document structure):
 File /home/Adam/z3/Zope3/src/zope/component/site.py, line 75, in 
queryMultiAdapter

   default)
 File /home/Adam/z3/Zope3/src/zope/interface/adapter.py, line 475, in 
queryMultiAdapter

   return factory(*objects)
 File /home/Adam/z3/products/ccard/pdf/card.py, line 58, in __init__
   images.append( Image(f, width=width, height=height) )
 File 
/usr/lib/python2.4/site-packages/reportlab/platypus/flowables.py, line 
318, in __init__

   self._setup(width,height,kind,0)
 File 
/usr/lib/python2.4/site-packages/reportlab/platypus/flowables.py, line 
327, in _setup

   if lazy=0: self._setup_inner()
 File 
/usr/lib/python2.4/site-packages/reportlab/platypus/flowables.py, line 
334, in _setup_inner

   if img: self.imageWidth, self.imageHeight = img.getSize()
 File /usr/lib/python2.4/site-packages/reportlab/lib/utils.py, line 
530, in getSize

   if (self._width is None or self._height is None):
AttributeError: ImageReader instance has no attribute '_width'

  Has anyone done what I want to? How? Any help would be much 
appreciated.


Regards,
Adam


___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] substitute for deprecated response.write()?

2005-12-28 Thread Adam Summers

Hi,

I was having a look at Phillipp's fabulous book (thanks!), and came 
across the code for publishing a PDF document to the browser (this is 
slightly modified from the book):


from zope.app import zapi
from zope.app.publisher.browser import BrowserView

from ccard.pdf.interfaces import IPDFPresentation

class PDFView(BrowserView):

 def __call__(self):
   pdf = zapi.getViewProviding(self.context, IPDFPresentation, 
self.request)

   filename = zapi.name(self.context) + '.pdf'
   response = self.request.response
   response.setHeader('Context-Disposition', 'attachment; filename=%s' 
% filena

me)
   response.setHeader('Content=Type', 'application/pdf')
   response.setHeader('Content-Length', len(pdf.data))
   response.write(pdf.data)

However, these days I get the error:

2005-12-28T15:29:56 ERROR SiteError 
http://localhost:8080/++skin++Boston/t2/Cred

itCard/pdf
Traceback (most recent call last):
 File /home/Adam/z3/Zope3/src/zope/publisher/publish.py, line 138, in 
publish

   result = publication.callObject(request, object)
 File 
/home/Adam/z3/Zope3/src/zope/app/publication/zopepublication.py, line 1

61, in callObject
   return mapply(ob, request.getPositionalArguments(), request)
 File /home/Adam/z3/Zope3/src/zope/publisher/publish.py, line 113, in 
mapply

   return debug_call(object, args)
 File /home/Adam/z3/Zope3/src/zope/publisher/publish.py, line 119, in 
debug_c

all
   return object(*args)
 File /home/Adam/z3/products/ccard/pdf/browser.py, line 15, in __call__
   response.write(pdf.data)
AttributeError: 'BrowserResponse' object has no attribute 'write'

What is the correct technique, now that BrowserResponse does not have 
write()


TIA, and Happy New Year
Adam



___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] substitute for deprecated response.write()?

2005-12-28 Thread Adam Summers

Hi,

   I am red faced (and blurry-eyed, its 1am here)- I found the answer 
in the archives, in September:


On Fri, Sep 16, 2005 at 11:50:19AM -0400, Stephan Richter wrote:


Just return the data; it is handled properly now.
 




Adam Summers wrote:


Hi,

I was having a look at Phillipp's fabulous book (thanks!), and came 
across the code for publishing a PDF document to the browser (this is 
slightly modified from the book):


from zope.app import zapi
from zope.app.publisher.browser import BrowserView

from ccard.pdf.interfaces import IPDFPresentation

class PDFView(BrowserView):

 def __call__(self):
   pdf = zapi.getViewProviding(self.context, IPDFPresentation, 
self.request)

   filename = zapi.name(self.context) + '.pdf'
   response = self.request.response
   response.setHeader('Context-Disposition', 'attachment; filename=%s' 
% filena

me)
   response.setHeader('Content=Type', 'application/pdf')
   response.setHeader('Content-Length', len(pdf.data))
   response.write(pdf.data)

However, these days I get the error:

2005-12-28T15:29:56 ERROR SiteError 
http://localhost:8080/++skin++Boston/t2/Cred

itCard/pdf
Traceback (most recent call last):
 File /home/Adam/z3/Zope3/src/zope/publisher/publish.py, line 138, 
in publish

   result = publication.callObject(request, object)
 File 
/home/Adam/z3/Zope3/src/zope/app/publication/zopepublication.py, line 1

61, in callObject
   return mapply(ob, request.getPositionalArguments(), request)
 File /home/Adam/z3/Zope3/src/zope/publisher/publish.py, line 113, 
in mapply

   return debug_call(object, args)
 File /home/Adam/z3/Zope3/src/zope/publisher/publish.py, line 119, 
in debug_c

all
   return object(*args)
 File /home/Adam/z3/products/ccard/pdf/browser.py, line 15, in __call__
   response.write(pdf.data)
AttributeError: 'BrowserResponse' object has no attribute 'write'

What is the correct technique, now that BrowserResponse does not have 
write()


TIA, and Happy New Year
Adam



___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users



___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users