暫無描述
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.

component.py 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # -*- coding: utf-8 -*-
  2. """ Main object to manipulate Editorial Model
  3. parent of all other EM editing classes
  4. @see EmClass, EmType, EmFieldGroup, EmField
  5. """
  6. from Lodel.utils.mlstring import MlString
  7. import logging
  8. logger = logging.getLogger('Lodel2.EditorialModel')
  9. class EmComponent(object):
  10. """ instaciate an EmComponent
  11. @param id_or_name int|str: name or id of the object
  12. @exception TypeError
  13. """
  14. def __init__(self, id_or_name):
  15. if self is EmComponent:
  16. raise EnvironmentError('Abstract class')
  17. if type(id_or_name) is int:
  18. self.id = id_or_name
  19. elif type(id_or_name) is str:
  20. self.name = id_or_name
  21. self.populate()
  22. else:
  23. raise TypeError('Bad argument: expecting <int> or <str>')
  24. """ Lookup in the database properties of the object to populate the properties
  25. """
  26. def populate(self):
  27. if self.id is None:
  28. where = "name = " + db.quote(self.name)
  29. else:
  30. where = "id = " + self.id
  31. row = db.query('*', self.table, where)
  32. if not row:
  33. # could have two possible Error message for id and for name
  34. raise EmComponentNotExistError("Bad id_or_name: could not find the component")
  35. self.name = row.name
  36. self.rank = int(row.rank)
  37. self.date_update = row.date_update
  38. self.date_create = row.date_create
  39. self.string = MlString.from_json(row.string)
  40. self.help = MlString.from_json(row.help)
  41. self.icon = row.icon
  42. return row
  43. """ write the representation of the component in the database
  44. @return bool
  45. """
  46. def save(self):
  47. pass
  48. """ delete this component data in the database
  49. @return bool
  50. """
  51. def delete(self):
  52. pass
  53. """ change the rank of the component
  54. @param int new_rank new position
  55. """
  56. def modify_rank(self, new_rank):
  57. pass
  58. """ set a string representation of the component for a given language
  59. @param lang str: iso 639-2 code of the language http://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
  60. @param text str: text to set
  61. @return bool
  62. """
  63. def set_string(self, lang, text):
  64. pass
  65. """ set the string representation of the component
  66. @param ml_string MlString: strings for all language
  67. @return bool
  68. """
  69. def set_strings(self, ml_string):
  70. pass
  71. """ get the string representation of the component for the given language
  72. @param lang str: iso 639-2 code of the language
  73. @return text str:
  74. """
  75. def get_string(self, lang):
  76. pass