Skip to content

Commit

Permalink
Remove dependency to django-choices
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Jan 18, 2024
1 parent 38b873f commit eaeefb3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 26 deletions.
1 change: 0 additions & 1 deletion requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jsonschema
django~=3.2
django-admin-index
django-axes
django-choices
django-redis
django-rosetta
maykin-django-two-factor-auth
Expand Down
4 changes: 1 addition & 3 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ django-admin-index==3.1.0
django-axes==5.41.1
# via -r requirements/base.in
django-choices==2.0.0
# via
# -r requirements/base.in
# vng-api-common
# via vng-api-common
django-filter==2.4.0
# via
# -r requirements/base.in
Expand Down
17 changes: 8 additions & 9 deletions src/objects/api/constants.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from django.db import models
from django.utils.translation import gettext_lazy as _

from djchoices import ChoiceItem, DjangoChoices


class Operators(DjangoChoices):
exact = ChoiceItem("exact", _("equal to"))
gt = ChoiceItem("gt", _("greater than"))
gte = ChoiceItem("gte", _("greater than or equal to"))
lt = ChoiceItem("lt", _("lower than"))
lte = ChoiceItem("lte", _("lower than or equal to"))
icontains = ChoiceItem("icontains", _("case-insensitive partial match"))
class Operators(models.TextChoices):
exact = "exact", _("equal to")
gt = "gt", _("greater than")
gte = "gte", _("greater than or equal to")
lt = "lt", _("lower than")
lte = "lte", _("lower than or equal to")
icontains = "icontains", _("case-insensitive partial match")
12 changes: 4 additions & 8 deletions src/objects/api/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import date
from typing import Union

from djchoices import DjangoChoices
from django.db import models

from objects.typing import JSONValue

Expand Down Expand Up @@ -33,15 +33,11 @@ def is_number(value: str) -> bool:
return True


def display_choice_values_for_help_text(choices: DjangoChoices) -> str:
def display_choice_values_for_help_text(Choices: type[models.TextChoices]) -> str:
items = []

for key, value in choices.choices:
description = getattr(choices.get_choice(key), "description", None)
if description:
item = f"* `{key}` - ({value}) {description}"
else:
item = f"* `{key}` - {value}"
for key, value in Choices.choices:
item = f"* `{key}` - {value}"
items.append(item)

return "\n".join(items)
Expand Down
9 changes: 4 additions & 5 deletions src/objects/token/constants.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.db import models
from django.utils.translation import gettext_lazy as _

from djchoices import ChoiceItem, DjangoChoices


class PermissionModes(DjangoChoices):
read_only = ChoiceItem("read_only", _("Read-only"))
read_and_write = ChoiceItem("read_and_write", _("Read and write"))
class PermissionModes(models.TextChoices):
read_only = "read_only", _("Read-only")
read_and_write = "read_and_write", _("Read and write")

0 comments on commit eaeefb3

Please sign in to comment.