1. Luke Plant
  2. django-livesettings


Hynek Cernoch  committed 8e2a043

Fixed PercentValue by set it deprecated. Closes #29

  • Participants
  • Parent commits 3a6bc0f
  • Branches default

Comments (0)

Files changed (4)

File docs/about.rst

View file
     * Duration
     * Float
     * Integer
-    * Percent
     * Positive Integer
     * String
     * Long string

File docs/usage.rst

View file
     {   1: {   'DB': False,
                'SETTINGS': {   u'MyApp': {   u'DECIMAL_TEST': u'34.0923443',
                                              u'MEASUREMENT_SYSTEM': u'["metric"]',
-                                             u'PERCENT_TEST': u'0.251'}}}}
+                                             u'STRING_TEST': u'Orange'}}}}
 In order to restrict or enable DB access, use the following line in your settings::

File livesettings/tests.py

View file
         test_empty_value_type(DurationValue, protocol)
         test_empty_value_type(FloatValue, protocol)
         test_empty_value_type(IntegerValue, protocol)
-        test_empty_value_type(PercentValue, protocol)
         test_empty_value_type(PositiveIntegerValue, protocol)
         test_empty_value_type(StringValue, protocol)
         test_empty_value_type(LongStringValue, protocol)
         test_empty_value_type(PasswordValue, protocol)
         # verify completness of the test
         classes_to_test = set(getattr(livesettings.values, k) for k in livesettings.values.__all__ if \
-                not k in ('BASE_GROUP', 'ConfigurationGroup', 'Value', 'SortedDotDict'))
+                not k in ('BASE_GROUP', 'ConfigurationGroup', 'Value', 'SortedDotDict', 'PercentValue'))
         self.assertEqual(protocol, classes_to_test, msg='The tested classes have been not all exactly the same as expected')
     def test_csrf(self):

File livesettings/values.py

View file
             return unicode(value)
+# Deprecated PercentValue does not work good and can not be fixed
+# without duplicating long modified parts of Django. #29
+# It is better to Replace PercentValue(...) by DecimalValue(... min_value=0, max_value=100, max_decimal_places=2)
+# and easily divide result value by 100 in the user application.
 class PercentValue(Value):
     class field(forms.DecimalField):
         def __init__(self, *args, **kwargs):
+            import warnings
+            warnings.warn(
+                "class livesettings.PercentValue is deprecated. It should be replaced in config.py by " \
+                "DecimalValue(... min_value=0, max_value=100) and the result divided by 100 in the app.",
+                DeprecationWarning
+            )
             kwargs['required'] = False
             forms.DecimalField.__init__(self, 100, 0, 5, 2, *args, **kwargs)