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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. t = dbo.table
  34. req = dbo.sel
  35. print(t.c.__dict__)
  36. if self.id is None:
  37. req.where(t.c.name == self.name)
  38. else:
  39. req.where(dbo.col.id == self.id)
  40. sqlresult = dbo.rexec(req)
  41. print (sqlresult)
  42. # Transformation du résultat en une liste de dictionnaires
  43. records = sqlresult.fetchall()
  44. print (records)
  45. for record in records:
  46. selected_lines.append(dict(zip(record.keys(), record)))
  47. if not row:
  48. # could have two possible Error message for id and for name
  49. raise EmComponentNotExistError("Bad id_or_name: could not find the component")
  50. self.name = row.name
  51. self.rank = int(row.rank)
  52. self.date_update = row.date_update
  53. self.date_create = row.date_create
  54. self.string = MlString.from_json(row.string)
  55. self.help = MlString.from_json(row.help)
  56. self.icon = row.icon
  57. return row
  58. """ write the representation of the component in the database
  59. @return bool
  60. """
  61. def save(self):
  62. pass
  63. """ delete this component data in the database
  64. @return bool
  65. """
  66. def delete(self):
  67. pass
  68. """ change the rank of the component
  69. @param int new_rank new position
  70. """
  71. def modify_rank(self, new_rank):
  72. pass
  73. """ set a string representation of the component for a given language
  74. @param lang str: iso 639-2 code of the language http://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
  75. @param text str: text to set
  76. @return bool
  77. """
  78. def set_string(self, lang, text):
  79. pass
  80. """ set the string representation of the component
  81. @param ml_string MlString: strings for all language
  82. @return bool
  83. """
  84. def set_strings(self, ml_string):
  85. pass
  86. """ get the string representation of the component for the given language
  87. @param lang str: iso 639-2 code of the language
  88. @return text str:
  89. """
  90. def get_string(self, lang):
  91. pass
  92. class EmComponentNotExistError(Exception):
  93. pass