Merge lp:~openerp/openobject-client/property_attribute into lp:openobject-client

Proposed by Husen Daudi
Status: Rejected
Rejected by: Olivier Dony (Odoo)
Proposed branch: lp:~openerp/openobject-client/property_attribute
Merge into: lp:openobject-client
Diff against target: 90 lines (+29/-1)
3 files modified
bin/tools/__init__.py (+17/-0)
bin/widget/view/form_gtk/char.py (+6/-1)
bin/widget/view/tree_gtk/editabletree.py (+6/-0)
To merge this branch: bzr merge lp:~openerp/openobject-client/property_attribute
Reviewer Review Type Date Requested Status
Christophe CHAUVET (community) Needs Fixing
Olivier Dony (Odoo) Disapprove
OpenERP sa GTK client R&D Pending
Review via email: mp+41148@code.launchpad.net

Description of the change

Branch to add property attribute on chat field like.

<field name="name" property="upper"/>
<field name="name" property="lower"/>
<field name="name" property="numeric"/>

so that widget will accept only upper/lower or numeric values.

To test the feature you need to merge this server branch too:
https://code.launchpad.net/~openerp/openobject-server/property_attribute/+merge/41147

To post a comment you must log in.
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Hello Husen,

Thank you for the merge proposal(s). The implementation looks simple enough, however the upper/lower conversion doesn't look like it could work for non-ascii characters, which makes it a bit useless as OpenERP should be compatible with all kinds of alphabets.

But anyway even if that worked, I'm afraid we can't consider merging this at this point for 6.0, for a few reasons:

- there are no modules really needing this feature in the current official addons, so I think FP will not accept adding small features like this, as it just makes the system more complicated for no real added value (unless you know of a case where this is required in current addons?)

- forcing textfield content to uppercase/lowercase seems like it can be done more reliably at the model level, so that any write() to the model will be supported, not just those coming from a client that support these "properties".

- forcing textfield contents to numeric values looks more like it should be an integer field, as again it would be supported properly at model level

- finally, if we decided to implement this sort of special case at client-side, both clients would need to be modified to support it, and after RC2 it is too late to introduce such features.

Thanks a lot for taking the time to make the merge proposals, though.
I suppose you needed this feature for a customer project, and it perhaps makes sense to keep it for that project, but we cannot include it in the core at the moment.

I will close the proposals for now and perhaps we can re-consider this after release 6.0.

I hope you understand my point of view...

review: Disapprove
Revision history for this message
Christophe CHAUVET (christophe-chauvet) wrote :

Hi

That a great feature, for ours cutomers we often inherit create or write to put uppercase or lowercase on their profile, if we can just add property="upper" it really great.

But to convert in upper or lower, please use lower or upper python function on a unicode string [1], and don't substitute ascii code.

for numeric, it's more complexe and i don't think it a good idea to include it

You can add "title" [2] property

Regards,

[1] : http://stackoverflow.com/questions/727507/how-can-i-do-unicode-uppercase
[2] : http://docs.python.org/library/stdtypes.html?highlight=title#str.title

review: Needs Fixing
Revision history for this message
Christophe Simonis (OpenERP) (kangol) wrote :

What about just a specific widget?

<field name="foo" widget="char_upper"/>
<field name="bar" widget="char_lower"/>
<field name="baz" widget="char_capitalize"/>

In this case, no need to change the server.

Revision history for this message
Christophe CHAUVET (christophe-chauvet) wrote :

Hi Christophe

The code on the server is only one line on a RNG file, it's not very terrific ;)

But add widget it's not a bad idea

One thing is sure, i want this feature :)

Regards,

Revision history for this message
Albert Cervera i Areny - http://www.NaN-tic.com (albert-nan) wrote :

I think this should configurable. We've met some customers that would have enjoyed the application automatically convert text to upper case but in all and every field in the system. So I think this should be configurable globally and simply patch the server would be enough. With no need of changing client code.

Revision history for this message
Christophe CHAUVET (christophe-chauvet) wrote :

Hi Albert

Yes, i just spoke the possibility to have one, not by default on a official module

it more quickly for us to add one attribute in the XML, instead of add code in "create" or "write" method

Regards,

Revision history for this message
xrg (xrg) wrote :

On Saturday 08 January 2011, you wrote:
> Hi Albert
>
> Yes, i just spoke the possibility to have one, not by default on a official
> module
>
> it more quickly for us to add one attribute in the XML, instead of add code
> in "create" or "write" method

I like the idea, in general. That's why I had initially given it a ++ vote.

However, in any features that we decide to officially support (anything we put
in the RNG ) needs to be well thought of and "stay" for long. We cannot add
and then remove or redefine features like that.

So, suggested course:
We define the specification (in a blueprint, a RFC-style text or something), we
share our opinions on it and then we (all) agree to support it. In the feature
submission window of v6.1, we include it, eventually.

Revision history for this message
Husen Daudi (husendaudi) wrote :

Few more suggestions,

we can put property="regular_expression" for more generic validation,
property = "upper/lower/numeric"

In base modules for code fields in product/country we can use property="upper", generally code should be in upper case in most of the business packages.

Revision history for this message
xrg (xrg) wrote :

On Monday 10 January 2011, you wrote:
> In base modules for code fields in product/country we can use
> property="upper", generally code should be in upper case in most of the
> business packages.

Generally, in a notion that doesn't have to do with the technical side of
accepting the "property" attribute in the RNG...

... I would like to express my /hatred/ against people that use capital
letters all the time in business applications.

Please don't fall into the trap of following these typewriter-era people in
designing a modern ERP application. The mix of small+capital letters conveys
some kind of information (at least) which we don't want to loose.
(example: some applications do convert the emails to uppercase. That's wrong.)

Unmerged revisions

1694. By husen <husen@husen-laptop>

added property attribute to make char widget upper/lower/numeric case

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/tools/__init__.py'
2--- bin/tools/__init__.py 2010-10-12 16:53:15 +0000
3+++ bin/tools/__init__.py 2010-11-18 10:17:56 +0000
4@@ -25,6 +25,7 @@
5 import os
6 import time
7 from dateutil.relativedelta import relativedelta
8+import gtk
9
10 import rpc
11
12@@ -79,6 +80,22 @@
13 attrs['digits'] = eval(attrs['digits'])
14 return attrs
15
16+def convert_keyval(type, keyval):
17+
18+ numkeys = [getattr(gtk.keysyms, '_%d' % x) for x in range(0,10)]
19+ numkeys += [getattr(gtk.keysyms, 'KP_%d' % x) for x in range(0,10)]
20+
21+ if type == "upper" and keyval >= 97 and keyval <= 122:
22+ keyval = keyval - 32
23+ return keyval
24+ elif type == "lower" and keyval >= 65 and keyval <= 90:
25+ keyval = keyval + 32
26+ return keyval
27+ elif type == "numeric" and keyval not in numkeys:
28+ return 0
29+ else:
30+ return keyval
31+
32 #FIXME use spaces
33 def calc_condition(self,model,con):
34 if model and (con[0] in model.mgroup.fields):
35
36=== modified file 'bin/widget/view/form_gtk/char.py'
37--- bin/widget/view/form_gtk/char.py 2010-07-16 05:41:32 +0000
38+++ bin/widget/view/form_gtk/char.py 2010-11-18 10:17:56 +0000
39@@ -24,6 +24,7 @@
40
41 import common
42 import interface
43+import tools
44
45 class char(interface.widget_interface):
46 def __init__(self, window, parent, model, attrs={}):
47@@ -35,6 +36,7 @@
48 self.widget.set_visibility(not attrs.get('password', False))
49 self.widget.set_width_chars(5)
50
51+ self.widget.connect('key_press_event', self.key_press_cb)
52 self.widget.connect('populate-popup', self._menu_open)
53 self.widget.connect('activate', self.sig_activate)
54 self.widget.connect('focus-in-event', lambda x,y: self._focus_in())
55@@ -43,7 +45,10 @@
56 def set_value(self, model, model_field):
57 return model_field.set_client(model, self.widget.get_text() or False)
58
59-
60+ def key_press_cb(self, entry, event, *arg):
61+ type = self.attrs.get('property',False)
62+ event.keyval = tools.convert_keyval(type, event.keyval)
63+
64 def display(self, model, model_field):
65 if not model_field:
66 self.widget.set_text('')
67
68=== modified file 'bin/widget/view/tree_gtk/editabletree.py'
69--- bin/widget/view/tree_gtk/editabletree.py 2010-09-20 09:58:27 +0000
70+++ bin/widget/view/tree_gtk/editabletree.py 2010-11-18 10:17:56 +0000
71@@ -23,6 +23,7 @@
72 import parser
73 import observator
74 from tools.debug import debug
75+import tools
76
77 class EditableTreeView(gtk.TreeView, observator.Observable):
78
79@@ -174,6 +175,11 @@
80 def on_keypressed(self, entry, event, cell_value):
81 path, column = self.get_cursor()
82 store = self.get_model()
83+
84+ if column._type == 'char' and column.name in self.screen.fields and self.screen.fields[column.name].get('property',False):
85+ type = self.screen.fields[column.name].get('property', '')
86+ event.keyval = tools.convert_keyval(type, event.keyval)
87+
88 model = store.get_value(store.get_iter(path), 0)
89 if event.keyval in self.leaving_events:
90 shift_pressed = bool(gtk.gdk.SHIFT_MASK & event.state)