fixtures.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import base64
  2. from misago.settings.models import Group, Setting
  3. from misago.utils import ugettext_lazy as _
  4. from misago.utils import get_msgid
  5. try:
  6. import cPickle as pickle
  7. except ImportError:
  8. import pickle
  9. settings_fixture = (
  10. # Basic options
  11. ('basic', {
  12. 'name': _("Basic Settings"),
  13. 'settings': (
  14. ('board_name', {
  15. 'value': "Misago",
  16. 'type': "string",
  17. 'input': "text",
  18. 'separator': _("Board Name"),
  19. 'name': _("Board Name"),
  20. }),
  21. ('board_header', {
  22. 'type': "string",
  23. 'input': "text",
  24. 'name': _("Board Header"),
  25. 'description': _("Some themes allow you to define text in board header. Leave empty to use Board Name instead."),
  26. }),
  27. ('board_header_postscript', {
  28. 'value': "Work in progress ",
  29. 'type': "string",
  30. 'input': "text",
  31. 'name': _("Board Header Postscript"),
  32. 'description': _("Additional text displayed in some themes board header after board name."),
  33. }),
  34. ('board_index_title', {
  35. 'type': "string",
  36. 'input': "text",
  37. 'separator': _("Board Index"),
  38. 'name': _("Board Index Title"),
  39. 'description': _("If you want to, you can replace page title content on Board Index with custom one."),
  40. }),
  41. ('board_index_meta', {
  42. 'type': "string",
  43. 'input': "text",
  44. 'name': _("Board Index Meta-Description"),
  45. 'description': _("Meta-Description used to describe your board's index page."),
  46. }),
  47. ('board_credits', {
  48. 'type': "string",
  49. 'input': "textarea",
  50. 'separator': _("Board Footer"),
  51. 'name': _("Custom Credit"),
  52. 'description': _("Custom Credit to display in board footer above software and theme copyright information. You can use HTML."),
  53. }),
  54. ('email_footnote', {
  55. 'type': "string",
  56. 'input': "textarea",
  57. 'separator': _("Board E-Mails"),
  58. 'name': _("Custom Footnote"),
  59. 'description': _("Custom Footnote to display in e-mail messages sent by board."),
  60. }),
  61. ),
  62. }),
  63. )
  64. def load_settings_group_fixture(group, fixture):
  65. model_group = Group(
  66. key=group,
  67. name=get_msgid(fixture['name']),
  68. description=get_msgid(fixture.get('description'))
  69. )
  70. model_group.save(force_insert=True)
  71. position = 0
  72. fixture = fixture.get('settings', ())
  73. for setting in fixture:
  74. value = setting[1].get('value')
  75. value_default = setting[1].get('default')
  76. # Convert boolean True and False to 1 and 0, otherwhise it wont work
  77. if setting[1].get('type') == 'boolean':
  78. value = 1 if value else 0
  79. value_default = 1 if value_default else 0
  80. # Store setting in database
  81. model_setting = Setting(
  82. setting=setting[0],
  83. group=model_group,
  84. value=value,
  85. value_default=value_default,
  86. type=setting[1].get('type'),
  87. input=setting[1].get('input'),
  88. extra=base64.encodestring(pickle.dumps(setting[1].get('extra', {}), pickle.HIGHEST_PROTOCOL)),
  89. position=position,
  90. separator=get_msgid(setting[1].get('separator')),
  91. name=get_msgid(setting[1].get('name')),
  92. description=get_msgid(setting[1].get('description')),
  93. )
  94. model_setting.save(force_insert=True)
  95. position += 1
  96. def load_settings_fixture(fixture):
  97. for group in fixture:
  98. load_settings_group_fixture(group[0], group[1])
  99. def load_fixture():
  100. load_settings_fixture(settings_fixture)