Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

classtypes.py 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. # -*- coding: utf-8 -*-
  2. object_uid = 'lodel_id'
  3. object_em_class_id = 'class_id'
  4. object_em_type_id = 'type_id'
  5. relation_uid = 'id_relation'
  6. relation_superior = 'superior'
  7. relation_subordinate = 'subordinate'
  8. relation_name = 'relation_name'
  9. common_fields = {
  10. object_uid: {
  11. 'fieldtype': 'pk',
  12. 'internal': 'autosql',
  13. 'immutable' : True,
  14. 'string': '{"___": "", "fre": "identifiant lodel", "eng": "lodel identifier"}'
  15. },
  16. object_em_class_id : {
  17. 'fieldtype': 'emuid',
  18. 'is_id_class': True,
  19. 'internal': 'automatic',
  20. 'immutable' : True,
  21. 'string': '{"___": "", "fre": "identifiant de la classe", "eng": "class identifier"}'
  22. },
  23. object_em_type_id : {
  24. 'fieldtype': 'emuid',
  25. 'is_id_class': False,
  26. 'internal': 'automatic',
  27. 'immutable' : True,
  28. 'string': '{"___": "", "fre": "identifiant de la type", "eng": "type identifier"}'
  29. },
  30. 'string': {
  31. 'fieldtype': 'char',
  32. 'max_length': 128,
  33. 'internal': 'automatic',
  34. 'nullable': True,
  35. 'immutable' : False,
  36. 'string': '{"___": "", "fre": "Représentation textuel", "eng": "String representation"}',
  37. },
  38. 'creation_date': {
  39. 'fieldtype': 'datetime',
  40. 'now_on_create': True,
  41. 'internal': 'autosql',
  42. 'immutable' : True,
  43. 'string': '{"___": "", "fre": "Date de création", "eng": "Creation date"}',
  44. },
  45. 'modification_date': {
  46. 'fieldtype': 'datetime',
  47. 'now_on_create': True,
  48. 'now_on_update': True,
  49. 'internal': 'autosql',
  50. 'immutable' : True,
  51. 'string': '{"___": "", "fre": "Date de modification", "eng": "Modification date"}',
  52. }
  53. }
  54. relations_common_fields = {
  55. relation_uid: {
  56. 'fieldtype': 'pk',
  57. 'internal': 'autosql',
  58. 'immutable' : True,
  59. },
  60. 'nature': {
  61. 'fieldtype': 'naturerelation',
  62. 'immutable' : True,
  63. },
  64. 'depth': {
  65. 'fieldtype': 'integer',
  66. 'internal': 'automatic',
  67. 'immutable' : True,
  68. },
  69. 'rank': {
  70. 'fieldtype': 'rank',
  71. 'internal': 'automatic',
  72. 'immutable' : True,
  73. },
  74. relation_superior : {
  75. 'fieldtype': 'leo',
  76. 'superior': True,
  77. 'immutable' : True,
  78. },
  79. relation_subordinate: {
  80. 'fieldtype': 'leo',
  81. 'superior': False,
  82. 'immutable' : True,
  83. },
  84. relation_name: {
  85. 'fieldtype': 'namerelation',
  86. 'max_length': 128,
  87. 'immutable' : True,
  88. }
  89. }
  90. def pk_name():
  91. for name, option in common_fields.items():
  92. if option['fieldtype'] == 'pk':
  93. return name
  94. ## EmNature (Class)
  95. #
  96. # constant name for the nature of type hierarchy
  97. class EmNature(object):
  98. PARENT = 'parent'
  99. TRANSLATION = 'translation'
  100. IDENTITY = 'identity'
  101. @classmethod
  102. def getall(cls):
  103. return [cls.PARENT, cls.TRANSLATION, cls.IDENTITY]
  104. ## EmClassType (Class)
  105. #
  106. # Representation of the classTypes
  107. #
  108. # Defines 3 generic classtype : entity, entry and person
  109. # - entity : to define editorial content
  110. # - entry : to define keywords
  111. # - person : to define people (in the real world, this classtype will only have one class and one type)
  112. #
  113. # The hierarchy dict fixes the possible hierarchical links the types of each classtype can have :
  114. # - 'attach' : what type of superior a type can have
  115. # - 'classtype' a type can have superiors of the same classtype
  116. # - 'type' a type can only have superiors of the same type
  117. # - automatic : possible superiors
  118. # - False : possible superiors must be defined
  119. # - True : possible superiors can not be defined, they will be enforced by the ME automatically
  120. # - maxdepth : maximum depth
  121. # - maxchildren : maximum children
  122. #
  123. # Classtypes contains default internal fields too
  124. #
  125. class EmClassType(object):
  126. entity = {
  127. 'name': 'entity',
  128. 'hierarchy': {
  129. EmNature.PARENT: {
  130. 'attach': 'classtype',
  131. 'automatic': False,
  132. 'maxdepth': -1,
  133. 'maxchildren': -1
  134. },
  135. EmNature.TRANSLATION: {
  136. 'attach': 'type',
  137. 'automatic': False,
  138. 'maxdepth': 1,
  139. 'maxchildren': -1
  140. },
  141. },
  142. 'default_fields': {}
  143. }
  144. entry = {
  145. 'name': 'entry',
  146. 'hierarchy': {
  147. EmNature.PARENT: {
  148. 'attach': 'type',
  149. 'automatic': False,
  150. },
  151. EmNature.TRANSLATION: {
  152. 'attach': 'type',
  153. 'automatic': False,
  154. 'maxdepth': 1,
  155. 'maxchildren': -1
  156. },
  157. },
  158. 'default_fields': {}
  159. }
  160. person = {
  161. 'name': 'person',
  162. 'hierarchy': {
  163. EmNature.IDENTITY: {
  164. 'attach': 'classtype',
  165. 'automatic': True,
  166. 'maxdepth': -1,
  167. 'maxchildren': 1
  168. },
  169. },
  170. 'default_fields': {}
  171. }
  172. ## @brief return a classtype from its name
  173. # @param cls
  174. # @param classtype str : A classtype name
  175. # @return None if no classtype with this name, else return a dict containing classtype informations
  176. @classmethod
  177. def get(cls, classtype):
  178. try:
  179. return getattr(cls, classtype.lower())
  180. except AttributeError:
  181. return None
  182. ## @brief Get all the classtype
  183. # @return A list of dict representing classtypes
  184. @classmethod
  185. def getall(cls):
  186. return [cls.entity, cls.entry, cls.person]
  187. ## @brief Return possible nature of relations for a classtype name
  188. #
  189. # @param classtype_name str: The classtype name
  190. # @return A list of EmNature names (list of str)
  191. @staticmethod
  192. def natures(classtype_name):
  193. if not isinstance(classtype_name, str):
  194. raise TypeError("Excepted <class str> but got %s" % str(type(classtype_name)))
  195. try:
  196. classtype = getattr(EmClassType, classtype_name)
  197. except AttributeError:
  198. raise AttributeError("Unknown classtype : '%s'" % classtype_name)
  199. return classtype['hierarchy'].keys()