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.

components.py 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. from Database.sqlwrapper import SqlWrapper
  8. from Database.sqlobject import SqlObject
  9. import logging
  10. import sqlalchemy as sql
  11. logger = logging.getLogger('Lodel2.EditorialModel')
  12. class EmComponent(object):
  13. """ instaciate an EmComponent
  14. @param id_or_name int|str: name or id of the object
  15. @exception TypeError
  16. """
  17. def __init__(self, id_or_name):
  18. SqlWrapper.start()
  19. if self is EmComponent:
  20. raise EnvironmentError('Abstract class')
  21. if type(id_or_name) is int:
  22. self.id = id_or_name
  23. elif type(id_or_name) is str:
  24. self.id = None
  25. self.name = id_or_name
  26. self.populate()
  27. else:
  28. raise TypeError('Bad argument: expecting <int> or <str>')
  29. """ Lookup in the database properties of the object to populate the properties
  30. """
  31. def populate(self):
  32. dbo = SqlObject(self.table)
  33. req = dbo.sel
  34. if self.id is None:
  35. req.where(dbo.col.name == self.name)
  36. else:
  37. req.where(dbo.col.id == self.id)
  38. sqlresult = dbo.rexec(req)
  39. # Transformation du résultat en une liste de dictionnaires
  40. records = sqlresult.fetchall()
  41. print (records)
  42. for record in records:
  43. selected_lines.append(dict(zip(record.keys(), record)))
  44. if not row:
  45. # could have two possible Error message for id and for name
  46. raise EmComponentNotExistError("Bad id_or_name: could not find the component")
  47. self.name = row.name
  48. self.rank = int(row.rank)
  49. self.date_update = row.date_update
  50. self.date_create = row.date_create
  51. self.string = MlString.from_json(row.string)
  52. self.help = MlString.from_json(row.help)
  53. self.icon = row.icon
  54. return row
  55. """ write the representation of the component in the database
  56. @return bool
  57. """
  58. def save(self):
  59. pass
  60. """ delete this component data in the database
  61. @return bool
  62. """
  63. def delete(self):
  64. pass
  65. """ change the rank of the component
  66. @param int new_rank new position
  67. """
  68. def modify_rank(self, new_rank):
  69. pass
  70. """ set a string representation of the component for a given language
  71. @param lang str: iso 639-2 code of the language http://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
  72. @param text str: text to set
  73. @return bool
  74. """
  75. def set_string(self, lang, text):
  76. pass
  77. """ set the string representation of the component
  78. @param ml_string MlString: strings for all language
  79. @return bool
  80. """
  81. def set_strings(self, ml_string):
  82. pass
  83. """ get the string representation of the component for the given language
  84. @param lang str: iso 639-2 code of the language
  85. @return text str:
  86. """
  87. def get_string(self, lang):
  88. pass
  89. class EmComponentNotExistError(Exception):
  90. pass