How to fix the z search interface problem

Posted On: 01 Jun 2010 07:24 AM

Hi

Today I try to add Z search interface ID: item
there are
Warning: Compilation failed
Warning: exceptions.UnicodeEncodeError: 'ascii' codec can't encode characters in position 7-8: ordinal not in range(128)

Maybe the same problem becuase in MYSQLDB there are Chinese name?
Please help me to fix the problem with thanks

Alex

 

Posted On: 01 Jun 2010 08:05 AM

 


Do you know if this error is coming directly from MySQL or from within Plone?


Regards,

David L.
WebFaction Support
--
WebFaction - Smarter web hosting
http://webfaction.com - http://twitter.com/webfaction

 

Posted On: 01 Jun 2010 08:21 AM

Hi,

I wonder where is the error coming.
Here is the Exception Log (most recent first)
Time Username (User Id) Exception
03:17:42 kyholdings (kyholdings) PTRuntimeError: ['Compilation failed', "exceptions.UnicodeEncodeError: 'ascii' codec c...
02:21:04 kyholdings (kyholdings) PTRuntimeError: ['Compilation failed', "exceptions.UnicodeEncodeError: 'ascii' codec c...
02:20:39 kyholdings (kyholdings) PTRuntimeError: ['Compilation failed', "exceptions.UnicodeEncodeError: 'ascii' codec c...
02:20:05 kyholdings (kyholdings) PTRuntimeError: ['Compilation failed', "exceptions.UnicodeEncodeError: 'ascii' codec c...
01:39:59 kyholdings (kyholdings) PTRuntimeError: ['Compilation failed', "exceptions.UnicodeEncodeError: 'ascii' codec c...
01:39:13 kyholdings (kyholdings) PTRuntimeError: ['Compilation failed', "exceptions.UnicodeEncodeError: 'ascii' codec c...
01:37:30 kyholdings (kyholdings) ValueError: No <em>searchable objects</em> were selected


Could you find where is?
Best Wishes
Alex

 

 

 

 

Posted On: 01 Jun 2010 08:26 AM

Exception traceback


Time 2010/06/01 01:39:13.523 GMT-5
User Name (User Id) kyholdings (kyholdings)
Request URL http://www.kyholdings.com/item
Exception Type PTRuntimeError
Exception Value ['Compilation failed', "exceptions.UnicodeEncodeError: 'ascii' codec can't encode characters in position 7-8: ordinal not in range(128)"]

Traceback (innermost last):

Module ZPublisher.Publish, line 119, in publish
Module ZPublisher.mapply, line 88, in mapply
Module ZPublisher.Publish, line 42, in call_object
Module Shared.DC.Scripts.Bindings, line 313, in __call__
Module Shared.DC.Scripts.Bindings, line 350, in _bindAndExec
Module Products.PageTemplates.ZopePageTemplate, line 330, in _exec
Module Products.PageTemplates.ZopePageTemplate, line 427, in pt_render
Module Products.PageTemplates.PageTemplate, line 98, in pt_render
Module zope.pagetemplate.pagetemplate, line 111, in pt_render
Warning: Compilation failed
Warning: exceptions.UnicodeEncodeError: 'ascii' codec can't encode characters in position 7-8: ordinal not in range(128)
PTRuntimeError: ['Compilation failed', "exceptions.UnicodeEncodeError: 'ascii' codec can't encode characters in position 7-8: ordinal not in range(128)"]

 

Posted On: 01 Jun 2010 08:56 AM

In order to help, we need two things:
(1): Please give me the exact chinese string that you are trying to encode.

(2): Please isolate the function that is causing the error when you give it the chinese string. For example, what function can you call from inside of Python to give you the same error?

We need to reproduce this error from inside of Python, not from inside the web page. Then we can see what conversion is necessary.

Once you have the above, try making a python script and testing the effect of changing sys.setdefaultencoding('utf-8'). Does it help?

Regards,

Ryan S.
WebFaction Support
--
WebFaction - Smarter web hosting
http://webfaction.com - http://twitter.com/webfaction

 

 

Posted On: 01 Jun 2010 09:14 AM

Hi,

The Z SQL Method at /list_item works well:
SELECT * FROM `item` WHERE `货号` LIKE '%KYH%'
when I add Z Search
Page Template at /item not workable.

Please use my name and password as follow help to fix the problem:
.......

Thanks
Alex

 

 

Posted On: 01 Jun 2010 09:34 AM

Right. If log in, and then go to:

http://www.kyholdings.com/list_item

Then I have a button that says "Submit Query", which then performs this SQL:

SELECT * FROM `item` WHERE `货号` LIKE '%KYH%'

(which basically searches for a list of items by their product number (货号))

But if I go to:

http://www.kyholdings.com/item

Then I see the error that you see.

So, what is /item trying to do? What is the template trying to give it?

We know that 货号 can be represented by utf-8. What string are you trying to represent at /item that isn't working? Is it also 货号, or something else?

If /item was an empty template, it would have no problem. So, is there a certain string that you are trying to show, and when you add that string, it breaks?

If you just have a template at /item that shows huohao (货号), does it work?

Regards,

Ryan S.
WebFaction Support
--
WebFaction - Smarter web hosting
http://webfaction.com - http://twitter.com/webfaction

 

Posted On: 01 Jun 2010 11:58 AM

Hi Rayn,

Please check
*Page Template at ** /*
<http://www.kyholdings.com/manage_workspace>*item*<http://www.kyholdings.com/item/manage_workspace>
* * <http://www.kyholdings.com/externalEdit_/item> properties:

When you log in and check the *Page Template at **
/*<http://www.kyholdings.com/manage_workspace>
*item* <http://www.kyholdings.com/item/manage_workspace>*
***<http://www.kyholdings.com/externalEdit_/item>
Click the link: Browse HTML source<http://www.kyholdings.com/item/source.html>
It will show many strings.
<table border>
<tr>
<th>ConNo</th>
<th>货号</th>
<th>工厂货号</th>
<th>中文名称</th>
<th>中文规格</th>
<th>英文名称</th>
<th>英文规格</th>
<th>商品编码</th>
<th>商品大类</th>
<th>主要供应商</th>
<th>单位名称</th>
<th>生产工厂</th>
<th>包装种类</th>
<th>数量单位</th>
<th>内包装</th>
<th>内包装单位</th>
<th>外包装</th>
<th>净重</th>
<th>毛重</th>
<th>长</th>
<th>宽</th>
<th>高</th>
<th>体积</th>
<th>20尺柜装量</th>
<th>40尺柜装量</th>
<th>40尺高柜装量</th>
<th>散货装量</th>
<th>期初库存</th>
<th>现库存量</th>
<th>货币单位</th>
<th>人民币单价</th>
<th>图片</th>
<th>更多图片</th>
<th>包装方式 s</th>
<th>认证类型 s</th>
<th>条码 s</th>
<th>最少订量 s</th>
<th>有效期限 s</th>
<th>退税率</th>
<th>英文包装种类 s</th>
<th>英文数量单位 s</th>
<th>货币 s</th>
<th>外销价</th>
</tr>
<tal:x repeat="result batch" >

<tr>
<td><span tal:replace="result/ConNo">ConNo goes here</span></td>
<td><span tal:replace="result/货号">货号 goes here</span></td>
<td><span tal:replace="result/工厂货号">工厂货号 goes here</span></td>
<td><span tal:replace="result/中文名称">中文名称 goes here</span></td>
<td><span tal:replace="result/中文规格">中文规格 goes here</span></td>
<td><span tal:replace="result/英文名称">英文名称 goes here</span></td>
<td><span tal:replace="result/英文规格">英文规格 goes here</span></td>
<td><span tal:replace="result/商品编码">商品编码 goes here</span></td>
<td><span tal:replace="result/商品大类">商品大类 goes here</span></td>
<td><span tal:replace="result/主要供应商">主要供应商 goes here</span></td>
<td><span tal:replace="result/单位名称">单位名称 goes here</span></td>
<td><span tal:replace="result/生产工厂">生产工厂 goes here</span></td>
<td><span tal:replace="result/包装种类">包装种类 goes here</span></td>
<td><span tal:replace="result/数量单位">数量单位 goes here</span></td>
<td><span tal:replace="result/内包装">内包装 goes here</span></td>
<td><span tal:replace="result/内包装单位">内包装单位 goes here</span></td>
<td><span tal:replace="result/外包装">外包装 goes here</span></td>
<td><span tal:replace="result/净重">净重 goes here</span></td>
<td><span tal:replace="result/毛重">毛重 goes here</span></td>
<td><span tal:replace="result/长">长 goes here</span></td>
<td><span tal:replace="result/宽">宽 goes here</span></td>
<td><span tal:replace="result/高">高 goes here</span></td>
<td><span tal:replace="result/体积">体积 goes here</span></td>
<td><span tal:replace="result/20尺柜装量">20尺柜装量 goes here</span></td>
<td><span tal:replace="result/40尺柜装量">40尺柜装量 goes here</span></td>
<td><span tal:replace="result/40尺高柜装量">40尺高柜装量 goes
here</span></td>
<td><span tal:replace="result/散货装量">散货装量 goes here</span></td>
<td><span tal:replace="result/期初库存">期初库存 goes here</span></td>
<td><span tal:replace="result/现库存量">现库存量 goes here</span></td>
<td><span tal:replace="result/货币单位">货币单位 goes here</span></td>
<td><span tal:replace="result/人民币单价">人民币单价 goes here</span></td>
<td><span tal:replace="result/图片">图片 goes here</span></td>
<td><span tal:replace="result/更多图片">更多图片 goes here</span></td>
<td><span tal:replace="result/包装方式_s">包装方式_s goes here</span></td>
<td><span tal:replace="result/认证类型_s">认证类型_s goes here</span></td>
<td><span tal:replace="result/条码_s">条码_s goes here</span></td>
<td><span tal:replace="result/最少订量_s">最少订量_s goes here</span></td>
<td><span tal:replace="result/有效期限_s">有效期限_s goes here</span></td>
<td><span tal:replace="result/退税率">退税率 goes here</span></td>
<td><span tal:replace="result/英文包装种类_s">英文包装种类_s goes
here</span></td>
<td><span tal:replace="result/英文数量单位_s">英文数量单位_s goes
here</span></td>
<td><span tal:replace="result/货币_s">货币_s goes here</span></td>
<td><span tal:replace="result/外销价">外销价 goes here</span></td>
</tr>
</tal:x>
</table>


If i just have a template at /item that shows huohao (货号), it not work.

How can I do now?

Alex

 

 

Posted On: 01 Jun 2010 04:54 PM

Hi Alex,

The problem is that you cannot use Chinese in your TAL expressions.

For example, the following is OK:

<td><span tal:replace="result/ConNo">ConNo goes here</span></td>

But this is not OK:

<td><span tal:replace="result/货号">货号 goes here</span></td>

So, instead of using field names in your TAL, you will need to use field indices.

An easy way to do this is by simply looping through the fields:

<tal:x repeat="result batch" >
<tr tal:define="oddrow repeat/result/odd;"
tal:attributes="class python:test(oddrow,'odd','even')">
<tal:record repeat="r result">
<td tal:content="r">value goes here</td>
</tal:record>
</tr>
</tal:x>

I've set up a working example of this for you at:

http://kyholdings.webfactional.com/kyholdings/copy_of_item

Hope that helps!

Regards,

Sean F.
WebFaction Support
--
WebFaction - Smarter web hosting
http://webfaction.com - http://twitter.com/webfaction

 

 

 

Posted On: 02 Jun 2010 01:36 PM

Hi Sean,

Thanks for you method.
You example test well.
But How can I do it when I creat a new Z search template?
As you know I'm don't know any language of the webpage edit.

Is it means just past the line you write to my new method?
Do you have any simple document to put into proper foler to run just like
.py file no need me to do same work everytime?
Waiting for you reply soon.

Thanks
Alex


 

 

Posted On: 02 Jun 2010 03:51 PM

Attached is a generic template you can use to display any ZSQL method. To use
it:

1. Create a new page template in your ZMI.

2. Paste the content of the generic template into your new page template.

3. Change the word 'zsqlmethod' to the ID of the ZSQL method that you want to
display.

4. Save your changes.

When that is done, your page template will automatically display the field
names and query results.

That's the limit of what we can do to assist you with this - if you need any
further customization, you will either need to hire a developer or learn how
to develop for Zope and Plone yourself.

Hope that helps!

Regards,

Sean F.
WebFaction Support
--
WebFaction - Smarter web hosting
http://webfaction.com - http://twitter.com/webfaction


Attachments generic_zsql_template.pt (2.31 KB)

 

Posted On: 02 Jun 2010 11:18 PM

Hi Sean,

Great.
It's working well.
Please help me to close the ticket with thanks.


Alex

 

 

Posted On: 03 Jun 2010 03:08 AM

Hi Sean,

Sorry one thing more:
1. If I want to show not all of the field of the tabel: for example: only ConNo 货号
英文名称 英文规格
包装种类 数量单位 内包装 内包装单位 外包装 净重 毛重 长 宽 高

人民币单价 图片 更多图片 包装方式_s
英文包装种类_s 英文数量单位_s 货币_s 外销价

how to do the when creat the Z SQL method?
2. about the image, in mysql filed 图片 更多图片

show the name of the image
How can I show the image in test result or template page?
What's the way to put the image? creat a folder in the root?
3. Now the template page only have one place to show the result.
How can I personalized the template page? It means I want to show one 货号 in one page like attached image showed?

Waiting for your reply with thanks

Alex


 

 

Posted On: 03 Jun 2010 06:44 AM

Hello,

> Sorry one thing more:
> 1. If I want to show not all of the field of the tabel: for example: only ConNo 货号
> 英文名称 英文规格
> 包装种类 数量单位 内包装 内包装单位 外包装 净重 毛重 长 宽 高
> 人民币单价 图片 更多图片 包装方式_s
> 英文包装种类_s 英文数量单位_s 货币_s 外销价

Basically, all of these items (English Name, Specification, Packaging Type, Quantity Unit, etc...) are just items in a list being sent to the template. You can use Python to modify the list, and choose only the items you want. Reading the Plone and Python documentation can tell you how to do this.

> how to do the when creat the Z SQL method?

The ZSQL is working correctly. What you want to do is post-process the results in Python. In other words, take the output from the ZSQL and change it with Python into what you want, then send it to the template. You don't have to go directly from the database to the template.

> 2. about the image, in mysql filed 图片 更多图片
> show the name of the image
> How can I show the image in test result or template page?
> What's the way to put the image? creat a folder in the root?

I don't know where you are seeing this. That just says "images", and "more images". I don't understand how "more images" is a single MySQL field containing the name of a single image.

Anyway, yes you can create a folder in the root. Then get the information from the database about the images in Python, and then get the image URL in python too, and then use the template to show the output however you want it.

> 3. Now the template page only have one place to show the result.
> How can I personalized the template page? It means I want to show one 货号 in one page like attached image showed?

You just change the template code. When you understand Plone's templating language, you can do this easily.


Regards,

Ryan S.
WebFaction Support
--
WebFaction - Smarter web hosting
http://webfaction.com - http://twitter.com/webfaction

 

Posted On: 03 Jun 2010 08:02 AM

Hello Alex,

> Glad to receive your reply.
> Sorry I don't know any languge both the python and plone's template language.
> Could you please make me a sample so that I could copy to creat new document when only something changed?
> Just like Sean always help me to do.

No, Sean went above and beyond our normal server support to help you with a difficult and confusing problem. What you are trying to do now is very standard, and you will need to learn it yourself.

If you want to create a website with Plone, then you will need to learn Python and Plone's template language.

You can find a good book on python in Chinese here:

http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/pythonhtml/html/installing_python/index.html

After you have finished that book, you can read the Plone information here, also in Chinese:

http://czug.org/plone/zopen-plonebook/122655

Again, you should read the entire 指南

Hope that helps!

Regards,

Ryan S.
WebFaction Support
--
WebFaction - Smarter web hosting
http://webfaction.com - http://twitter.com/webfaction

 

 

Posted On: 03 Jun 2010 10:45 AM

Hello Alex,

> Thanks for your suggestion.
> I'm reading the guide(指南) already.
> But it will take time to realize it.
> Anyway I will learn the Plone and Python as you told me to do.
> But now there are something urgent to do.
> If possiable please help me this time.
> I also could learn something from yours.

I believe the reason is this line:

<tal:body define="results here/list_item;

which tells the page to display results from:

http://www.kyholdings.com/list_item

And http://www.kyholdings.com/item is a ZSQL query.

So, if you limit the results of the query to only get the items you want, then, the page should automatically adjust. But, I'm not very sure, because my experience is with Django, Cherrypy, Mako Templates, and SqlAlchemy, which is very different from Plone. So, to understand better, I would need to read the guide, too.

Hope that helps

Regards,

Ryan S.
WebFaction Support
--
WebFaction - Smarter web hosting
http://webfaction.com - http://twitter.com/webfaction