No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

classtypes.py 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # -*- coding: utf-8 -*-
  2. ## EmNature (Class)
  3. #
  4. # constant name for the nature of type hierarchy
  5. class EmNature(object):
  6. PARENT = 'parent'
  7. TRANSLATION = 'translation'
  8. IDENTITY = 'identity'
  9. @classmethod
  10. def getall(cls):
  11. return [cls.PARENT, cls.TRANSLATION, cls.IDENTITY]
  12. ## EmClassType (Class)
  13. #
  14. # Representation of the classTypes
  15. #
  16. # Defines 3 generic classtype : entity, entry and person
  17. # - entity : to define editorial content
  18. # - entry : to define keywords
  19. # - person : to define people (in the real world, this classtype will only have one class and one type)
  20. #
  21. # The hierarchy dict fixes the possible hierarchical links the types of each classtype can have :
  22. # - 'attach' : what type of superior a type can have
  23. # - 'classtype' a type can have superiors of the same classtype
  24. # - 'type' a type can only have superiors of the same type
  25. # - automatic : possible superiors
  26. # - False : possible superiors must be defined
  27. # - True : possible superiors can not be defined, they will be enforced by the ME automatically
  28. # - maxdepth : maximum depth
  29. # - maxchildren : maximum children
  30. #
  31. class EmClassType(object):
  32. entity = {
  33. 'name': 'entity',
  34. 'hierarchy': {
  35. EmNature.PARENT: {
  36. 'attach': 'classtype',
  37. 'automatic': False,
  38. 'maxdepth': -1,
  39. 'maxchildren': -1
  40. },
  41. EmNature.TRANSLATION: {
  42. 'attach': 'type',
  43. 'automatic': False,
  44. 'maxdepth': 1,
  45. 'maxchildren': -1
  46. },
  47. },
  48. }
  49. entry = {
  50. 'name': 'entry',
  51. 'hierarchy': {
  52. EmNature.PARENT: {
  53. 'attach': 'type',
  54. 'automatic': False,
  55. },
  56. EmNature.TRANSLATION: {
  57. 'attach': 'type',
  58. 'automatic': False,
  59. 'maxdepth': 1,
  60. 'maxchildren': -1
  61. },
  62. },
  63. }
  64. person = {
  65. 'name': 'person',
  66. 'hierarchy': {
  67. EmNature.IDENTITY: {
  68. 'attach': 'classtype',
  69. 'automatic': True,
  70. 'maxdepth': -1,
  71. 'maxchildren': 1
  72. },
  73. },
  74. }
  75. @classmethod
  76. def getall(cls):
  77. return [cls.entity, cls.entry, cls.person]
  78. ## natures (Method)
  79. #
  80. # Return possible nature of relations for a classtype name
  81. #
  82. # @param classtype str: The classtype name
  83. # @return A list of EmNature names (list of str)
  84. @staticmethod
  85. def natures(classtype_name):
  86. if not isinstance(classtype_name, str):
  87. raise TypeError("Excepted <class str> but got %s" % str(type(classtype_name)))
  88. try:
  89. classtype = getattr(EmClassType, classtype_name)
  90. except AttributeError:
  91. raise AttributeError("Unknown classtype : '%s'" % classtype_name)
  92. return classtype['hierarchy'].keys()