<commit_before># -*- coding: utf-8 -*-
from django import forms
from django.db import connection
from django.db.models.fields import Field
from django.core.urlresolvers import reverse, NoReverseMatch
from django.conf import settings
from django.forms.formsets import BaseFormSet, formset_factory
from django.utils.importlib import import_module
from django.utils.translation import ugettext as _

from django_qbe.utils import get_models
from django_qbe.widgets import CriteriaInput

try:
    module = "django.db.backends.%s" % settings.DATABASE_ENGINE
    base_mod = import_module("%s.base" % module)
    OPERATORS = base_mod.DatabaseWrapper.operators
    intros_mod = import_module("%s.introspection" % module)
    TABLE_NAMES = intros_mod.DatabaseIntrospection(connection).table_names()
except ImportError:
    OPERATORS = {}
    TABLE_NAMES = []

SORT_CHOICES = (
    ("", ""),
    ("asc", _("Ascending")),
    ("des", _("Descending")),
)


class QueryByExampleForm(forms.Form):
    show = forms.BooleanField(label=_("Show"), required=False)
    model = forms.CharField(label=_("Model"))
    field = forms.CharField(label=_("Field"))
    criteria = forms.CharField(label=_("Criteria"), required=False)
    sort = forms.ChoiceField(label=_("Sort"), choices=SORT_CHOICES,
                             required=False)
<commit_msg>Fixes #3. Now it support the old syntax with DATABASE_ENGINE and the new multi databases scheme.<commit_after># -*- coding: utf-8 -*-
from django import forms
from django.db import connection
from django.db.models.fields import Field
from django.core.urlresolvers import reverse, NoReverseMatch
from django.conf import settings
from django.forms.formsets import BaseFormSet, formset_factory
from django.utils.importlib import import_module
from django.utils.translation import ugettext as _

from django_qbe.utils import get_models
from django_qbe.widgets import CriteriaInput

OPERATORS = {}
TABLE_NAMES = []
DATABASES = None
try:
    DATABASES = settings.DATABASES
except AttributeError:
    # Backwards compatibility for Django versions prior to 1.1.
    DATABASES = {
        'default': {
            'ENGINE': "django.db.backends.%s" % settings.DATABASE_ENGINE,
            'NAME': settings.DATABASE_NAME,
        }
    }
for database, database_properties in DATABASES.items():
    module = database_properties['ENGINE']
    try:
        base_mod = import_module("%s.base" % module)
        intros_mod = import_module("%s.introspection" % module)
        table_names = intros_mod.DatabaseIntrospection(connection).table_names()
        OPERATORS.update(base_mod.DatabaseWrapper.operators)
        TABLE_NAMES.extend(table_names)
    except ImportError:
        pass

SORT_CHOICES = (
    ("", ""),
    ("asc", _("Ascending")),
    ("des", _("Descending")),
)


class QueryByExampleForm(forms.Form):
    show = forms.BooleanField(label=_("Show"), required=False)
    model = forms.CharField(label=_("Model"))
    field = forms.CharField(label=_("Field"))
    criteria = forms.CharField(label=_("Criteria"), required=False)
    sort = forms.ChoiceField(label=_("Sort"), choices=SORT_CHOICES,
                             required=False)

{'fraction_non_alphanumeric': 0.11419558359621451, 'fraction_numerical': 0.0015772870662460567, 'mean_word_length': 4.057416267942584, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6675542', 'n_tokens_mistral': 968, 'n_tokens_neox': 951, 'n_words': 212}