Discussion:
[Erp5-dev] own workflow state catalogged in own table, its translation - how to?
Łukasz Nowak
2008-09-11 09:55:11 UTC
Permalink
Hello,

We are using our own workflow state - operation_state.

I created my own table for this state in catalog: ventisopstate.

Searching/sorting is working for this operation_state column. So far so
good.

But I wanted to be able to sort/search by this state translated title.

So I've copy&pasted:
* z_related_translated_validation_state
=> ?z_related_translated_operation_state

* z_related_translated_validation_state_title =>
z_related_translated_operation_state_title

Modified both scripts, updated sql_catalog_related_keys.

So columns using this state are automatically recognised as
searchable/sortable.

But invoking such simple script:

return context.portal_catalog(
portal_type='Production Order',
translated_operation_state_title='Finished',
)

Gives me attached traceback.

Ok - I understand, that no column is found in those tables, as there is
no such column. But what else shall I do, to have my own table in this
query? I've analysed catalog properties, but no property is looking good
to configure this... Where can I read more about it (except code - I'll
do it anyway if anything else fails...)

Regards,
Luke
--
?ukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...'' I am only craftsman.

-------------- next part --------------
Traceback (innermost last):

Module ZPublisher.Publish, line 114, in publish
112 | missing_name,
113 | dont_publish_class,
114>| request, bind=1)
115 |
116 | if result is not response:

Module ZPublisher.mapply, line 88, in mapply
086 |
087 | args=tuple(args)
088>| if debug is not None: return debug(object,args,context)
089 | else: return object(*args)

Module ZPublisher.Publish, line 40, in call_object
038 |
039 |def call_object(object, args, request):
040>| result=apply(object,args) # Type s<cr> to step into published object.
041 | return result
042 |

Module Shared.DC.Scripts.Bindings, line 311, in __call__
309 | def __call__(self, *args, **kw):
310 | '''Calls the script.'''
311>| return self._bindAndExec(args, kw, None)
312 |
313 | def __render_with_namespace__(self, namespace):

Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec
346 | exec bindcode
347 | bound_data = bound_data[0]
348>| return self._exec(bound_data, args, kw)
349 | finally:
350 | security.removeContext(self)

Module Products.PythonScripts.PythonScript, line 324, in _exec
322 | f = new.function(fcode, g, None, fadefs)
323 |
324>| result = f(*args, **kw)
325 | if keyset is not None:
326 | # Store the result in the cache.

Module None, line 2, in test_py
- <PythonScript at /erp5/portal_skins/custom/test_py> - Line 2
000 |return context.portal_catalog(
001>| portal_type='Production Order',
002 | translated_operation_state_title='Finished',
003 |)
Module Products.ERP5Catalog.CatalogTool, line 620, in searchResults
618 | #LOG("searchResult", INFO, catalog_id)
619 | # LOG("searchResult", INFO, ZCatalog.searchResults(self, query=query, sql_catalog_id=catalog_id, src__=1, **kw))
620>| return ZCatalog.searchResults(self, query=query, sql_catalog_id=catalog_id, **kw)
621 |
622 | __call__ = searchResults

Module Products.ZSQLCatalog.ZSQLCatalog, line 1054, in searchResults
1052 | catalog = self.getSQLCatalog(sql_catalog_id)
1053 | if catalog is not None:
1054>| return apply(catalog.searchResults, (REQUEST,used), kw)
1055 | return []
1056 |

Module Products.ZSQLCatalog.SQLCatalog, line 2160, in searchResults
2158 | # The used argument is deprecated and is ignored
2159 | method = getattr(self, self.sql_search_results)
2160>| return self.queryResults(method, REQUEST=REQUEST, used=used, **kw)
2161 |
2162 | __call__ = searchResults

Module Products.ZSQLCatalog.SQLCatalog, line 2154, in queryResults
2152 | #LOG('queryResults',0,'kw: %s' % str(kw))
2153 | #LOG('queryResults',0,'from_table_list: %s' % str(query['from_table_list']))
2154>| return sql_method(src__=src__, **kw)
2155 |
2156 | def searchResults(self, REQUEST=None, used=None, **kw):

Module Products.ERP5Type.patches.DA, line 220, in DA__call__
218 |# if 'portal_ids' in query:
219 |# LOG("DA query", INFO, "query = %s" %(query,))
220>| result=DB__.query(query, self.max_rows_)
221 | except:
222 | LOG("DA call raise", ERROR, "DB = %s, c = %s, query = %s" %(DB__, c, query), error=sys.exc_info())

Module Products.ZMySQLDA.db, line 295, in query
293 |
294 | def query(self, *args, **kw):
295>| return self._access_db(method_id='query', args=args, kw=kw)
296 |
297 | def string_literal(self, *args, **kw):

Module Products.ZMySQLDA.db, line 286, in _access_db
284 | transactions=self._transactions)
285 | self._pool_set(ident, db)
286>| return getattr(db, method_id)(*args, **kw)
287 |
288 | def tables(self, *args, **kw):

Module Products.ZMySQLDA.db, line 421, in query
419 | qs = "%s LIMIT %d" % (qs,max_rows)
420 | r=0
421>| c = self._query(qs)
422 | if desc is not None:
423 | if c and (c.describe() != desc):

Module Products.ZMySQLDA.db, line 396, in _query
394 | except OperationalError, m:
395 | if m[0] in query_syntax_error:
396>| raise OperationalError(m[0], '%s: %s' % (m[1], query))
397 | if m[0] in lock_error:
398 | raise ConflictError('%s: %s: %s' % (m[0], m[1], query))
OperationalError: (1054, 'Unknown column \'ventisopstate.operation_state\' in \'where clause\': SELECT DISTINCT\n catalog.path, catalog.uid \nFROM\n catalog AS catalog, translation AS related_translation_0 \nWHERE \n 1 = 1 \n AND (((((related_translation_0.translated_message = \'Finished\'))))) AND (((((catalog.portal_type = \'Production Order\'))))) AND (((catalog.security_uid IN (147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196)) OR (((((((catalog.viewable_owner = \'ERP5TypeTestCase\'))))))))) AND (related_translation_0.original_message = ventisopstate.operation_state\n AND related_translation_0.message_context = "operation_state_title"\n AND related_translation_0.language = \'en\')\nLIMIT 1000')
Jérome Perrin
2008-09-12 12:23:14 UTC
Permalink
Post by Łukasz Nowak
Hello,
We are using our own workflow state - operation_state.
I created my own table for this state in catalog: ventisopstate.
Searching/sorting is working for this operation_state column. So far so
good.
But I wanted to be able to sort/search by this state translated title.
* z_related_translated_validation_state
=> ?z_related_translated_operation_state
* z_related_translated_validation_state_title =>
z_related_translated_operation_state_title
Modified both scripts, updated sql_catalog_related_keys.
Hello,

What did you add in ??sql_catalog_related_keys ?
My guess is that you should add ?ventisopstate table in the related key
definition, so that the query builder adds it in the FROM clause.
Maybe something like:

translated_operation_state_title
| ??ventisopstate/translation/translated_message/z_related_translated_operation_state_title

J?rome
Post by Łukasz Nowak
So columns using this state are automatically recognised as
searchable/sortable.
return context.portal_catalog(
portal_type='Production Order',
translated_operation_state_title='Finished',
)
Gives me attached traceback.
Ok - I understand, that no column is found in those tables, as there is
no such column. But what else shall I do, to have my own table in this
query? I've analysed catalog properties, but no property is looking good
to configure this... Where can I read more about it (except code - I'll
do it anyway if anything else fails...)
Regards,
Luke
_______________________________________________
Erp5-dev mailing list
Erp5-dev at erp5.org
http://mail.nexedi.com/mailman/listinfo/erp5-dev
Łukasz Nowak
2008-09-12 12:58:56 UTC
Permalink
Hello,
Post by Łukasz Nowak
Post by Łukasz Nowak
Hello,
We are using our own workflow state - operation_state.
I created my own table for this state in catalog: ventisopstate.
Searching/sorting is working for this operation_state column. So far so
good.
But I wanted to be able to sort/search by this state translated title.
* z_related_translated_validation_state
=> ?z_related_translated_operation_state
* z_related_translated_validation_state_title =>
z_related_translated_operation_state_title
Modified both scripts, updated sql_catalog_related_keys.
Hello,
What did you add in ??sql_catalog_related_keys ?
My guess is that you should add ?ventisopstate table in the related key
definition, so that the query builder adds it in the FROM clause.
translated_operation_state_title
| ??ventisopstate/translation/translated_message/z_related_translated_operation_state_title
I did have:

translated_operation_state |
translation/translated_message/z_related_translated_operation_state

translated_operation_state_title |
translation/translated_message/z_related_translated_operation_state_title


After changing to:
?translated_operation_state |
venitsopstate/translation/translated_message/z_related_translated_operation_state

translated_operation_state_title |
ventisopstate/translation/translated_message/z_related_translated_operation_state_title

only part of traceback changed to:

OperationalError: (1054, "Unknown column
'related_ventisopstate_0.translation' in 'where clause': SELECT\n
COUNT(DISTINCT catalog.uid) FROM\n catalog AS catalog WHERE\n 1 = 1\n
AND (1) AND (1) AND (1) AND (1) AND (1) AND (1) AND (1) AND (1) AND (1)
AND (1) AND (((((catalog.portal_type = 'Production Order'))))) AND (1)
AND (((((related_ventisopstate_0.translation = 'finished'))))) AND
(((catalog.security_uid IN (147, 148, 149, 150, 151, 152, 153, 154, 155,
156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183,
184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196)) OR
(((((((catalog.viewable_owner = 'ERP5TypeTestCase'))))))))) AND (1) AND
(1) AND (1) AND (((((catalog.parent_uid = '1152'))))) AND (1)\nLIMIT 1")

Regards,
Luke
--
?ukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...'' I am only craftsman.
Jérome Perrin
2008-09-12 13:57:46 UTC
Permalink
Post by Łukasz Nowak
Hello,
Post by Łukasz Nowak
Post by Łukasz Nowak
Hello,
We are using our own workflow state - operation_state.
I created my own table for this state in catalog: ventisopstate.
Searching/sorting is working for this operation_state column. So far so
good.
But I wanted to be able to sort/search by this state translated title.
* z_related_translated_validation_state
=> ?z_related_translated_operation_state
* z_related_translated_validation_state_title =>
z_related_translated_operation_state_title
Modified both scripts, updated sql_catalog_related_keys.
Hello,
What did you add in ??sql_catalog_related_keys ?
My guess is that you should add ?ventisopstate table in the related key
definition, so that the query builder adds it in the FROM clause.
translated_operation_state_title
| ??ventisopstate/translation/translated_message/z_related_translated_operation_state_title
translated_operation_state |
translation/translated_message/z_related_translated_operation_state
translated_operation_state_title |
translation/translated_message/z_related_translated_operation_state_title
?translated_operation_state |
venitsopstate/translation/translated_message/z_related_translated_operation_state
translated_operation_state_title |
ventisopstate/translation/translated_message/z_related_translated_operation_state_title
Then ?z_related_translated_operation_state_title method will receive
table_0 and table_1 arguments. ?table_0 will
be ?"related_ventisopstate_0" or whatever alias the query generator
associated to ?ventisopstate table, and table_1 the alias for
translation table. Then you'll have to use <dtml-var ?table_0> instead
of "??ventisopstate", and ?<dtml-var ?table_1> instead of
"translation" (or maybe it was? <dtml-var ?table_0>).

J?rome
Post by Łukasz Nowak
OperationalError: (1054, "Unknown column
'related_ventisopstate_0.translation' in 'where clause': SELECT\n
COUNT(DISTINCT catalog.uid) FROM\n catalog AS catalog WHERE\n 1 = 1\n
AND (1) AND (1) AND (1) AND (1) AND (1) AND (1) AND (1) AND (1) AND (1)
AND (1) AND (((((catalog.portal_type = 'Production Order'))))) AND (1)
AND (((((related_ventisopstate_0.translation = 'finished'))))) AND
(((catalog.security_uid IN (147, 148, 149, 150, 151, 152, 153, 154, 155,
156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183,
184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196)) OR
(((((((catalog.viewable_owner = 'ERP5TypeTestCase'))))))))) AND (1) AND
(1) AND (1) AND (((((catalog.parent_uid = '1152'))))) AND (1)\nLIMIT 1")
Regards,
Luke
Łukasz Nowak
2008-09-17 14:29:03 UTC
Permalink
Hello,

Ok - I made it. It is top-posted, sorry.

So - I've got my own table ventisopstate, which is catalogging
operation_state on some portal types.

desc ventisopstate;
+-----------------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+---------------------+------+-----+---------+-------+
| uid | bigint(20) unsigned | NO | PRI | NULL | |
| operation_state | varchar(255) | YES | MUL | NULL | |
+-----------------+---------------------+------+-----+---------+-------+

operation_state is one of my workflow's variable name.

I wanted to be able to search/sort - use catalog - for
translated_operation_state and translated_operation_state_title.

That's what I have in my sql_catalog_related_keys:

translated_operation_state |
ventisopstate,translation/translated_message/z_related_translated_operation_state
translated_operation_state_title |
ventisopstate,translation/translated_message/z_related_translated_operation_state_title

My z_related_translated_operation_state:

Arguments:
table_0
table_1

Body:

<dtml-var table_1>.original_message = <dtml-var table_0>.operation_state
AND <dtml-var table_1>.message_context = "operation_state"
AND <dtml-var table_1>.language = <dtml-sqlvar
"Localizer.get_selected_language()" type="string">
AND <dtml-var table_0>.uid = catalog.uid

My ?z_related_translated_operation_state_title:

Arguments:
table_0
table_1

Body:

<dtml-var table_1>.original_message = <dtml-var table_0>.operation_state
AND <dtml-var table_1>.message_context = "operation_state_title"
AND <dtml-var table_1>.language = <dtml-sqlvar
"Localizer.get_selected_language()" type="string">
AND <dtml-var table_0>.uid = catalog.uid

I wasn't able to do it without directly relating to catalog table
(passing this as argument to not applies). But it is working, query runs
quite fast and its src__=1 looks corrects.

So - this is that solution. Thank you Jerome for tip. Is that good
enough for wikipage, or shall I wait for mentioned somewhere catalog
configuration change?

Regards,
Luke
Post by Jérome Perrin
Post by Łukasz Nowak
Hello,
Post by Łukasz Nowak
Post by Łukasz Nowak
Hello,
We are using our own workflow state - operation_state.
I created my own table for this state in catalog: ventisopstate.
Searching/sorting is working for this operation_state column. So far so
good.
But I wanted to be able to sort/search by this state translated title.
* z_related_translated_validation_state
=> ?z_related_translated_operation_state
* z_related_translated_validation_state_title =>
z_related_translated_operation_state_title
Modified both scripts, updated sql_catalog_related_keys.
Hello,
What did you add in ??sql_catalog_related_keys ?
My guess is that you should add ?ventisopstate table in the related key
definition, so that the query builder adds it in the FROM clause.
translated_operation_state_title
| ??ventisopstate/translation/translated_message/z_related_translated_operation_state_title
translated_operation_state |
translation/translated_message/z_related_translated_operation_state
translated_operation_state_title |
translation/translated_message/z_related_translated_operation_state_title
?translated_operation_state |
venitsopstate/translation/translated_message/z_related_translated_operation_state
translated_operation_state_title |
ventisopstate/translation/translated_message/z_related_translated_operation_state_title
Then ?z_related_translated_operation_state_title method will receive
table_0 and table_1 arguments. ?table_0 will
be ?"related_ventisopstate_0" or whatever alias the query generator
associated to ?ventisopstate table, and table_1 the alias for
translation table. Then you'll have to use <dtml-var ?table_0> instead
of "??ventisopstate", and ?<dtml-var ?table_1> instead of
"translation" (or maybe it was? <dtml-var ?table_0>).
J?rome
Post by Łukasz Nowak
OperationalError: (1054, "Unknown column
'related_ventisopstate_0.translation' in 'where clause': SELECT\n
COUNT(DISTINCT catalog.uid) FROM\n catalog AS catalog WHERE\n 1 = 1\n
AND (1) AND (1) AND (1) AND (1) AND (1) AND (1) AND (1) AND (1) AND (1)
AND (1) AND (((((catalog.portal_type = 'Production Order'))))) AND (1)
AND (((((related_ventisopstate_0.translation = 'finished'))))) AND
(((catalog.security_uid IN (147, 148, 149, 150, 151, 152, 153, 154, 155,
156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183,
184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196)) OR
(((((((catalog.viewable_owner = 'ERP5TypeTestCase'))))))))) AND (1) AND
(1) AND (1) AND (((((catalog.parent_uid = '1152'))))) AND (1)\nLIMIT 1")
Regards,
Luke
_______________________________________________
Erp5-dev mailing list
Erp5-dev at erp5.org
http://mail.nexedi.com/mailman/listinfo/erp5-dev
--
?ukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...'' I am only craftsman.
Jérome Perrin
2008-09-17 15:30:21 UTC
Permalink
Post by Łukasz Nowak
(...)
<dtml-var table_1>.original_message = <dtml-var table_0>.operation_state
AND <dtml-var table_1>.message_context = "operation_state_title"
AND <dtml-var table_1>.language = <dtml-sqlvar
"Localizer.get_selected_language()" type="string">
AND <dtml-var table_0>.uid = catalog.uid
I wasn't able to do it without directly relating to catalog table
(passing this as argument to not applies). But it is working, query runs
quite fast and its src__=1 looks corrects.
Hello,

You don't have to hard code "catalog" there, it is passed to the Z SQL
Method as "query_table" argument. This mean you can replace "catalog" by
<dtml-var query_table>.
Post by Łukasz Nowak
So - this is that solution. Thank you Jerome for tip. Is that good
enough for wikipage, or shall I wait for mentioned somewhere catalog
configuration change?
Yes, it is good.

J?rome

Loading...