Просмотр исходного кода

Extra documentation for setting migrations.

Rafał Pitoń 11 лет назад
Родитель
Сommit
ca992271ac

+ 39 - 2
docs/developers/settings.rst

@@ -17,8 +17,45 @@ Both types of settings can accessed as attributes of ``misago.conf.settings`` ob
    Not all high level settings values are available at all times. Some settings ("lazy settings"), are evaluated to ``True`` or ``None`` immediately upon load. This means while they can be checked to see if they have value or not, but require you to use special ``get_lazy_setting(setting)`` getter to actually obtain their real value.
 
 
-Defining Custom Settings
-========================
+Defining Custom DB Settings
+===========================
+
+.. note::
+   Current Misago 0.6 migrations are south-based placeholders that will be replaced with new migrations introduced in Django 1.7 before release. For this reason this instruction focuses exclusively on usage of utility function provided by Misago.
+
+In order to define or change high-level (stored in database) settings you have to add new rows to ``conf_settingsgroup`` and ``conf_settings`` database tables. This can be done by plenty of different ways, but preffered one is by creating new data migration and using functions from ``misago.conf.migrationutils`` module.
+
+
+migrate_settings_group
+----------------------
+
+.. function:: migrate_settings_group(orm, group_fixture, old_group_key=None)
+
+This function uses south supplied ORM instance to insert/update settings group in database according to provided dict contianing its name, description and contained settings. If new group should replace old one, you can provide its key in ``old_group_key`` argument.
+
+The ``group_fixture`` dict should define following keys:
+
+* **key** - string with settings group key.
+* **name** - string with settings group name.
+* **description** - optional string with short settings group description.
+* **settings** - tuple containing dics describing settings belonging to this group.
+
+Each dict in ``settings`` tuple should define following keys:
+
+* **setting** - string with internal setting name.
+* **name** - string with displayed setting name.
+* **description** - optional string with small setting help message.
+* **legend** - optional string indicating that before displaying this setting in form, new fieldset should be opened and this value should be used in its legend element.
+* **python_type** - optional string defining type of setting's value. Can be either "string", "int", "bool" or "list". If omitted "string" is used by default.
+* **value** - list, integer or string with default value for this setting.
+* **form_field** - What form field should be used to change this setting. Can be either "text", "textarea", "select", "radio", "yesno" or "checkbox". If not defined, "text" is used. "checkbox" should be used exclusively for multiple choices list.
+* **field_extra** - dict that defines extra attributes of form field. For "select", "radio" and "checkbox" fields this dict should contain "choices" key with tuple of tuples that will be used for choices in input. For "string" settings you can define "min_length" and "max_length" extra specifying minmal and maximal lenght of entered text. For integer settings you can specify minimal and maximal range in which value should fall by "min_value" and "max_value".
+
+
+with_conf_models
+----------------
+
+
 
 
 Misago Settings Reference

+ 1 - 1
misago/core/migrations/0002_db_settings.py

@@ -3,7 +3,7 @@ from south.utils import datetime_utils as datetime
 from south.db import db
 from south.v2 import DataMigration
 from django.db import models
-from misago.conf.migrationutils import with_conf_models, migrate_settings_group
+from misago.conf.migrationutils import migrate_settings_group, with_conf_models
 from misago.core.migrationutils import ugettext_lazy as _
 
 

+ 3 - 3
misago/users/migrations/0002_db_settings.py

@@ -3,7 +3,7 @@ from south.utils import datetime_utils as datetime
 from south.db import db
 from south.v2 import DataMigration
 from django.db import models
-from misago.conf.migrationutils import with_conf_models, migrate_settings_group
+from misago.conf.migrationutils import migrate_settings_group, with_conf_models
 from misago.core.migrationutils import ugettext_lazy as _
 
 
@@ -137,7 +137,7 @@ class Migration(DataMigration):
                         'field_extra': {
                             'choices': (
                                 ('no', _("Don't watch")),
-                                ('watch', _("Put on watched threads list")),
+                                ('', _("Put on watched threads list")),
                                 ('watch_email', _("Put on watched threads "
                                                   "list and e-mail user when "
                                                   "somebody replies")),
@@ -152,7 +152,7 @@ class Migration(DataMigration):
                         'field_extra': {
                             'choices': (
                                 ('no', _("Don't watch")),
-                                ('watch', _("Put on watched threads list")),
+                                ('', _("Put on watched threads list")),
                                 ('watch_email', _("Put on watched threads "
                                                   "list and e-mail user when "
                                                   "somebody replies")),