···22import os
33import random
44import time
55+from typing import Type, Union
5667from django.apps import apps as django_apps
78from django.core.exceptions import ImproperlyConfigured
···1112from options.constants import CONVERTER, FLOAT, INT, STR
121313141414-def get_option_model():
1515+def get_option_model() -> Type:
1516 """Return the Notification model that is active in this project."""
1617 from options.settings import DEFAULT_OPTION_MODEL
1718···2829 )
293030313131-def get_user_option_model():
3232+def get_user_option_model() -> Type:
3233 """Return the Notification model that is active in this project."""
3334 from options.settings import DEFAULT_USER_OPTION_MODEL
3435···4647 )
474848494949-def convert_value(value, value_type):
5050+def convert_value(value: str, value_type: int) -> Union[str, int, float]:
5051 """Converts the given value to the given type."""
5152 default_values = {INT: 0, FLOAT: 1.0, STR: ""}
5253 try:
···11+from typing import Sequence, Union
22+13from django.conf import settings
24from django.core.exceptions import ValidationError
35from django.db import models
···2123 blank=True,
2224 db_index=True,
2325 )
2626+ help_text = models.TextField(verbose_name=_("help text"), blank=True, null=True)
2427 type = models.PositiveIntegerField(choices=TYPE_CHOICES, default=STR)
2528 value = models.CharField(
2629 null=True, blank=True, default=None, max_length=256, verbose_name=_("value")
···3437 class Meta:
3538 abstract = True
36393737- def __str__(self):
4040+ def __str__(self) -> str:
3841 return f"{self.public_name}"
39424040- def get_value(self):
4343+ def get_value(self) -> Union[int, str, float, Sequence]:
4144 """Gets the value with the proper type. If the type is not
4245 valid it would return the default value for the field, to avoid
4346 problems with manual database modifications.
···5154 values = self.value.split(",")
5255 return [convert_value(value, self.type) for value in values]
53565454- def clean(self):
5757+ def clean(self) -> None:
5558 """Calls to the converter to check the type conversion. Added exception
5659 for lists, to check all values.
5760 """
+1-1
pyproject.toml
···11[tool.poetry]
22name = "django-simple-options"
33-version = "2.2.0"
33+version = "2.3.0"
44description = "Simple app to add configuration options to a Django project."
55readme = "README.rst"
66authors = ["Marcos Gabarda <hey@marcosgabarda.com>"]
+1-1
tests/test_options.py
···2727 self.assertEqual("42", value)
28282929 def test_float_conversion_options(self):
3030- name = "string_option"
3030+ name = "float_option"
3131 OptionFactory(name=name, value="42.5", type=FLOAT)
3232 value = Option.objects.get_value(name)
3333 self.assertIsInstance(value, float)