Skip to content

Commit 24827e3

Browse files
committed
make url choices configurable, settings.URL_CHOICES_FUNC
1 parent cb488cf commit 24827e3

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

ixxy_url_field/fields.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
from django import forms
55
from django.core.exceptions import ValidationError
66
from django.core.validators import URLValidator
7-
from django.core.cache import cache
87
from django.db import models
98
from django.db import IntegrityError
109
from django.template.defaultfilters import filesizeformat
1110
from django.utils.translation import ugettext_lazy as _
1211
from django.utils.encoding import smart_unicode
12+
from django.utils import importlib
1313

1414
from ixxy_url_field.choice_with_other import ChoiceWithOtherField
1515

@@ -27,18 +27,11 @@ def formfield(self, **kwargs):
2727
'form_class': IxxyURLFormField,
2828
}
2929
defaults.update(kwargs)
30-
cache_key = 'get_linklist_context'
31-
linklists = cache.get(cache_key)
32-
if not linklists:
33-
from cms.admin_views import get_linklist_context
34-
linklists = get_linklist_context()
35-
cache.set(cache_key, linklists)
36-
choices = []
37-
keys = ['links', 'documents', 'secure_documents', ]
38-
for key in keys:
39-
choices.extend([(link[1], link[0]) for link in linklists[key] or []])
40-
choices.append(['', ''])
41-
30+
from django.conf import settings
31+
mod_path, func_name = settings.URL_CHOICES_FUNC.rsplit('.', 1)
32+
mod = importlib.import_module(mod_path)
33+
choices_func = getattr(mod, func_name)
34+
choices = choices_func()
4235
required = not self.blank
4336
return ChoiceWithOtherField(choices=choices, required=required)
4437

0 commit comments

Comments
 (0)