Code Monkey home page Code Monkey logo

dmitri-sintsov / django-jinja-knockout Goto Github PK

View Code? Open in Web Editor NEW
143.0 143.0 29.0 11.44 MB

Django datatables and widgets, both AJAX and traditional. Display-only ModelForms. ModelForms / inline formsets with AJAX submit and validation. Works with Django templates.

Home Page: https://django-jinja-knockout.readthedocs.org/

License: Other

Python 26.51% HTML 5.17% JavaScript 67.81% CSS 0.46% Shell 0.05%
ajax-form bootstrap3 bootstrap4 bootstrap5 datagrid datatable-serverside datatables django django-forms django-formsets django-framework knockoutjs

django-jinja-knockout's People

Contributors

bobsburgers avatar dmitri-sintsov avatar gitter-badger avatar kiwnix avatar melvyn-sopacua avatar sam-oylov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-jinja-knockout's Issues

Would you consider relicensing to a permissive license?

Can the license be changed back to BSD or perhaps changed to Apache 2.0 if you no longer want to use the BSD license.

This library is awesome, but unfortunately the GPL is arguably the worst family in terms of legal risks. No joke, I was once told by a project manager it would be cheaper to hire a javascript developer to build a react app and just use Django Rest Framework, than it would be to get their lawyers to 'approve' the use of this library because its GPL.

If the GPL change was an deliberate copyright/copyleft ethics driven choice, fair enough, its your code, and I respect your choice. But I can't tell from the commit message so all I can do is ask. ๐Ÿ˜„

Please Help - Middleware Error

Error related to middleware

DJK_MIDDLEWARE

TypeError: init() takes 1 positional argument but 2 were given

Unhandled exception in thread started by <_pydev_bundle.pydev_monkey._NewThreadStartupWithTrace object at 0x10c636940>
Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_monkey.py", line 589, in __call__
    return self.original_func(*self.args, **self.kwargs)
  File "/Users/Tushar/workspace/hcl/venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/Users/Tushar/workspace/hcl/venv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 140, in inner_run
    handler = self.get_handler(*args, **options)
  File "/Users/Tushar/workspace/hcl/venv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
    handler = super().get_handler(*args, **options)
  File "/Users/Tushar/workspace/hcl/venv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 65, in get_handler
    return get_internal_wsgi_application()
  File "/Users/Tushar/workspace/hcl/venv/lib/python3.6/site-packages/django/core/servers/basehttp.py", line 44, in get_internal_wsgi_application
    return import_string(app_path)
  File "/Users/Tushar/workspace/hcl/venv/lib/python3.6/site-packages/django/utils/module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "/Users/Tushar/workspace/hcl/venv/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/Tushar/workspace/hcl/hcl/hcl/wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/Users/Tushar/workspace/hcl/venv/lib/python3.6/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    return WSGIHandler()
  File "/Users/Tushar/workspace/hcl/venv/lib/python3.6/site-packages/django/core/handlers/wsgi.py", line 140, in __init__
    self.load_middleware()
  File "/Users/Tushar/workspace/hcl/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 39, in load_middleware
    mw_instance = middleware(handler)
TypeError: __init__() takes 1 positional argument but 2 were given

My Settings.py

"""
Django settings for hcl project.

Generated by 'django-admin startproject' using Django 2.0.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""

import os
import random
from distutils.version import LooseVersion

import environ
from django import get_version
from django.utils import timezone

root = environ.Path(__file__) - 0  # three folder back (/a/b/c/ - 3 = /)
get_env_variable = environ.Env(DEBUG=(bool, False), )
environ.Env.read_env()

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = get_env_variable('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = get_env_variable('DEBUG')

ALLOWED_HOSTS = []

# Application definition
JS_ERRORS_ALERT = DEBUG
# Requires proper setup of Django email error logging.
JS_ERRORS_LOGGING = not DEBUG

DJK_APPS = (
    'hcl',
    'models_',
    'event_app',
)

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django_jinja',
    'django_jinja.contrib._humanize',
    'django_jinja_knockout',
    'django_jinja_knockout._allauth',
    )+DJK_APPS+(
    'allauth',
    'allauth.account',
    # Required for socialaccount template tag library despite we do not use social login
    'allauth.socialaccount'
)

DJK_MIDDLEWARE = 'hcl.middleware.ContextMiddleware'

MIDDLEWARE = [
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
]

if LooseVersion(get_version()) >= LooseVersion('1.11'):
    MIDDLEWARE.append(DJK_MIDDLEWARE)
else:
    MIDDLEWARE_CLASSES = MIDDLEWARE
    MIDDLEWARE.extend([
        'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
        DJK_MIDDLEWARE,
    ])
AUTHENTICATION_BACKENDS = (
    # Needed to login by username in Django admin, regardless of `allauth`
    'django.contrib.auth.backends.ModelBackend',
    # `allauth` specific authentication methods, such as login by e-mail
    'allauth.account.auth_backends.AuthenticationBackend',
)

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse',
        }
    },
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': os.path.join(BASE_DIR, 'logs', 'django_log.sql'),
        },
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler',
            'include_html': True,
        }
    },
    'loggers': {
        'django': {
            'handlers': ['file', 'mail_admins'],
            'level': 'DEBUG',
            'propagate': True,
        },
    },
}

ROOT_URLCONF = 'hcl.urls'

try:
    # Django > 1.9
    from django.template.context_processors import i18n
    i18n_processor = 'django.template.context_processors.i18n'
except ImportError:
    from django.core.context_processors import i18n
    i18n_processor = 'django.core.context_processors.i18n'


TEMPLATES = [
    {
        "BACKEND": "django_jinja.backend.Jinja2",
        "APP_DIRS": True,
        "OPTIONS": {
            "match_extension": ".htm",
            "app_dirname": "jinja2",
            'context_processors': [
                i18n_processor,
                # For simple cases it is enough to include original template context processor (commented out).
                'hcl.context_processors.template_context_processor'
                # 'django_jinja_knockout.context_processors.template_context_processor'
            ]
        },
    },
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                # Next line is required only if project uses Django templates (DTL).
                'hcl.context_processors.template_context_processor'
            ],
        },
    },
]

WSGI_APPLICATION = 'hcl.wsgi.application'

# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

DATABASES = {
    'default': get_env_variable.db(),
    'sqllite': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    },
'TEST': {
            'NAME': ':memory:',
            # 'NAME': os.path.join(BASE_DIR, 'test.sqlite3'),
        },
}

# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    # 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Next setting is required so multiple Django instances running at the same host/IP with different ports
# do not interfere each other (apollo13).
SESSION_COOKIE_NAME = 'djk_sessionid'

# As this is the test application, registration with SMTP confirmation is not supported.
# Use:
""" python manage.py createsuperuser """
# or:
"""
python manage.py shell
from django.contrib.auth.models import User
user = User.objects.create_user('user', email='[email protected]', password='test123')
user.save()
exit()
"""

# For 'allauth'.
SITE_ID = 1
# Prevents infinite redirect when user has no permission to access current view.
ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS = False
ALLAUTH_DJK_URLS = True

# Login / logout for allauth.
LOGIN_URL = '/accounts/login/'
LOGIN_REDIRECT_URL = "/"
LOGOUT_URL = '/accounts/logout/'

# Pagination settings.
OBJECTS_PER_PAGE = 3 if DEBUG else 10

# unit testing settings
FIXTURE_DIRS = (
    os.path.join(BASE_DIR, 'fixtures'),
)

random.seed(timezone.now().timestamp())

Please help what am I missing ??

Default selection/Not required selection ForeignKeyGridWidget

I have 2 issues and solving either will do what I need. Everything shows up and works. I might be asking about features, but I feel like I am missing something obvious.

Marking fields as not required does not seem to work. The text is not bold so I can tell there is a change. I still get Select a valid choice. That choice is not one of the available choices.

'KoGridRelationView' referenced below.
registrar = models.ForeignKey(AccountRegistrarModel, on_delete=models.CASCADE, blank=True, null=True, verbose_name='Default Registrar')
widgets = {'registrar': ForeignKeyGridWidget(grid_options={ 'pageRoute': 'account_registrar_fk_widget', 'dialogOptions': {'size': 'size-wide'}, # Override default search field label (optional): 'searchPlaceholder': 'Search For account', 'required': False, }),

I see you did that here on line 38. but its for a different thing i think?
https://github.com/Dmitri-Sintsov/djk-sample/blob/3805ad9b9731df6933feda86a75e9aa3b616399a/club_app/forms.py

other thing I would like to do is set default options. Like there are 20 themes but the user has a favorite. This would also solve the above problem in a messy patch way with a universal default of none option.

Everything else has been so easy once I found it. But I have looked for a day or two now and I cant figure it out. Hope to make some pull requests soon best I can.

Request for help

Hi Dmitri, I'm new to django.
I'm using python 3.6.1 with django 1.11.2 and django_jinja_knockout from git (master).
I am trying to get a simple grid working, the simplest grid as described in the Usage section of the docs.
I am not overriding middleware.py or the context processor.
I have a breakpoint in template_context_process() in your library.
The break point gets hit on requests, such as http://127.0.0.1:8000/admin/

I have defined a url

url(r'^customer(?P<action>/?\w*)/$', SimpleCustomerGrid.as_view(), name='customer_grid',
         kwargs={'view_title': 'Simple customer grid'}),

and the view object is:

class SimpleCustomerGrid(KoGridView):
    model = Customer
    grid_fields = '__all__'
    # Remove next line to disable columns sorting:
    allowed_sort_orders = '__all__'

visiting the url
http://127.0.0.1:8000/customer/
gives this error:

AttributeError at /customer/

'WSGIRequest' object has no attribute 'client_routes'

and the breakpoint on template_context_process() is not being hit.
I have looked and looked for differences between what I'm doing and the sample app, and I can't find the problem. Why is a visit to /customer/ not triggering the breakpoint in template_context_process() ?

KoGridView grid_fields use m2m field throws Invalid JSON data

Hi, first of all, thanks for this work, it really helps to simplify stuff.

Now my question, it's possible to use and m2m field as a grid_fields in KoGridView? I ask this because I have an KoGridView and in grid_fields I want to display Django user groups like this:

grid_fields = [
        ("username", "Username"),
        ("first_name", "Name"),
        ("last_name", "Last Name"),
        ("groups", "Groups"),
    ]

But when it's time to render the KoGridView throws this error:

Invalid JSON data, key path: 0 / entries / 1 / groups, val type: django.db.models.fields.related_descriptors.create_forward_many_to_many_manager..ManyRelatedManager

I need to specify this differently in grid_fields? I also tried 'groups__name' but the result it's always None. Also tried to format it in get_row_str_fields() method, but same error comes.

How it's the correct way to achive this? The only way is with virtual fields?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.