[schema] add CodeKeyword
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Sun, 19 Jul 2009 16:59:50 +0200
changeset 44 9403b833592d
parent 42 2ff35a51458d
child 45 3190f3dffaa1
[schema] add CodeKeyword
entities.py
migration/postcreate.py
schema.py
views.py
--- a/entities.py	Mon Jul 06 17:17:07 2009 +0200
+++ b/entities.py	Sun Jul 19 16:59:50 2009 +0200
@@ -42,3 +42,12 @@
         except IndexError:
             # XXX no state yet, due to notification before state has been set
             return self.name
+
+class CodeKeyword(Keyword):
+    id = 'CodeKeyword'
+    rest_attr = 'code'
+    fetch_attrs, fetch_order = fetch_config(['code','name'])
+
+    def dc_title(self):
+        return u'%s - %s' % (self.code, self.name)
+    dc_long_title = dc_title # what about state ?
--- a/migration/postcreate.py	Mon Jul 06 17:17:07 2009 +0200
+++ b/migration/postcreate.py	Sun Jul 19 16:59:50 2009 +0200
@@ -1,10 +1,12 @@
 # postcreate script. You could setup a workflow here for example
 # no explicit initial state for Keywords since it depends on the user's groups
-pending = add_state(_('validation pending'), 'Keyword')
-validated = add_state(_('keyword validated'), 'Keyword')
-rejected = add_state(_('keyword rejected'), 'Keyword')
-add_transition(_('validate keyword'), 'Keyword', (pending,), validated,
-               requiredgroups=('managers',))
-add_transition(_('reject keyword'), 'Keyword', (pending,), rejected,
-               requiredgroups=('managers',))
 
+for entity_name in ('Keyword', 'CodeKeyword'):
+    pending = add_state(_('validation pending'), entity_name)
+    validated = add_state(_('keyword validated'), entity_name)
+    rejected = add_state(_('keyword rejected'), entity_name)
+    add_transition(_('validate keyword'), entity_name, (pending,), validated,
+                   requiredgroups=('managers',))
+    add_transition(_('reject keyword'), entity_name, (pending,), rejected,
+                   requiredgroups=('managers',))
+
--- a/schema.py	Mon Jul 06 17:17:07 2009 +0200
+++ b/schema.py	Sun Jul 19 16:59:50 2009 +0200
@@ -54,6 +54,11 @@
     wf_info_for = ObjectRelation('TrInfo', cardinality='1*', composite='object')
 
 
+class CodeKeyword(Keyword):
+    """A CodeKeyword is a keyword with a code and a name
+    """
+    __specializes_schema__ = True
+    code = String(required=True, fulltextindexed=True, indexed=True, maxsize=128)
 
 class subkeyword_of(MetaUserRelationType):
     """a keyword can specialize another keyword"""
@@ -66,7 +71,9 @@
 
 # define in parent application which entity types may be linked to a keyword
 # by the applied_to relation
+
 class applied_to(MetaUserRelationType):
     """tagged objects"""
     fulltext_container = 'object'
     constraints = [RQLConstraint('S included_in CS, O is ET, CS classifies ET')]
+
--- a/views.py	Mon Jul 06 17:17:07 2009 +0200
+++ b/views.py	Sun Jul 19 16:59:50 2009 +0200
@@ -21,7 +21,9 @@
 uicfg.primaryview_section.tag_object_of(('*', 'applied_to', '*'), 'hidden')
 uicfg.primaryview_section.tag_subject_of(('*', 'applied_to', '*'), 'hidden')
 
+uicfg.actionbox_appearsin_addmenu.tag_object_of(('CodeKeyword', 'included_in', 'Classification'), True)
 uicfg.actionbox_appearsin_addmenu.tag_object_of(('Keyword', 'included_in', 'Classification'), True)
+uicfg.actionbox_appearsin_addmenu.tag_object_of(('CodeKeyword', 'subkeyword_of', 'CodeKeyword'), True)
 uicfg.actionbox_appearsin_addmenu.tag_object_of(('Keyword', 'subkeyword_of', 'Keyword'), True)
 uicfg.autoform_section.tag_object_of(('Keyword', 'in_state', '*'), 'generated')