Skip to content

Commit

Permalink
update to work with Django 1.9+
Browse files Browse the repository at this point in the history
  • Loading branch information
zeraien committed Mar 4, 2018
1 parent 57b4d57 commit 6b0b805
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ dist
MANIFEST
.idea
django_url_framework.egg-info/
duf_test/
env-test/
3 changes: 2 additions & 1 deletion django_url_framework/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
VERSION = (0, 3, 11)
VERSION = (0, 3, 12)
default_app_config = 'django_url_framework.apps.URLFrameworkAppConfig'

try:
from django_url_framework.site import Site
Expand Down
7 changes: 7 additions & 0 deletions django_url_framework/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy


class URLFrameworkAppConfig(AppConfig):
name = 'django_url_framework'
verbose_name = ugettext_lazy("Django URL Framework")
11 changes: 6 additions & 5 deletions django_url_framework/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from django.http import *
import re
import sys

from django.template.context import make_context
from django.utils.safestring import SafeUnicode
import warnings
from django_url_framework.helper import ApplicationHelper
Expand Down Expand Up @@ -561,12 +563,9 @@ def __wrapped_render(self, dictionary = {}, *args, **kwargs):
else:
template_name = self._template_string % template_replacement_data
kwargs['template_name'] = template_name

if 'context_instance' not in kwargs:
kwargs['context_instance'] = RequestContext(self._request)

self._template_context.update(dictionary)

if getattr(self, '_before_render_runonce', False) == False and getattr(self._action_func,'disable_filters', False) == False:
self._before_render_runonce = True
before_render_response = self._before_render()
Expand All @@ -580,7 +579,9 @@ def __wrapped_render(self, dictionary = {}, *args, **kwargs):
# if obj is not None:
# populate_xheaders(self._request, self._response, obj.__class__, obj.pk)

self._response.content = loader.render_to_string(dictionary=self._template_context, *args, **kwargs)
self._response.content = loader.render_to_string(template_name=kwargs['template_name'],
context=self._template_context,
request=self._request)
return self._response

_render = __wrapped_render
Expand Down
33 changes: 16 additions & 17 deletions django_url_framework/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import imp
import os
from functools import wraps

from django.apps import apps
from django.conf import settings

from django_url_framework.helper import ApplicationHelper
Expand Down Expand Up @@ -40,36 +42,35 @@ def autodiscover(self, include_apps = [], exclude_apps = []):
exclude_apps = (exclude_apps,)

if len(include_apps) == 0:
include_apps = settings.INSTALLED_APPS
include_apps = apps.app_configs.keys()

for app in settings.INSTALLED_APPS:
for app_config in apps.app_configs.values():

must_skip = False
if app.endswith('django_url_framework'):
app_name = app_config.name
if app_name.endswith('django_url_framework'):
continue

for inc in include_apps:
if re.search(inc, app):
if re.search(inc, app_name):
must_skip = False
break
else:
must_skip = True
for excl in exclude_apps:
if re.search(excl, app):
if re.search(excl, app_name):
must_skip = True
break
if must_skip:
continue
try:
available_controllers = []
app_path = import_module(app).__path__
if app_path[0][-1] != os.path.sep:
app_path[0] = app_path[0]+os.path.sep

for f in dircache.listdir(app_path[0]):
app_path = app_config.path
for f in dircache.listdir(app_path):
if f.endswith('_controller.py'):
available_controllers.append(f[:-14])
self.load_controllers(app_path, available_controllers)
except AttributeError, e:
except AttributeError as e:
self.logger.exception(e)
continue

Expand All @@ -79,15 +80,14 @@ def load_controllers(self, app_path, controllers):
for controller_file in controllers:
"""Load controller"""
try:
found_controller = imp.find_module('%s_controller' % controller_file, app_path)
except ImportError, e:
found_controller = imp.find_module('%s_controller' % controller_file, [app_path])
except ImportError:
self.logger.warning("Failed to find proper controller in %s" % controller_file, exc_info=True)
continue
else:
controller_module = imp.load_module('%s_controller' % controller_file, *found_controller)
self.logger.debug("Loaded controller from %s" % controller_file)
for controller_class_name in dir(controller_module):
# test_name = '%sController' % ''.join([i.title() for i in controller_file.split('_')])
if not controller_class_name.endswith('Controller'):
continue

Expand All @@ -102,9 +102,8 @@ def load_controllers(self, app_path, controllers):

"""Load helper"""
try:
found_helper = imp.find_module('%s_helper' % controller_file, app_path)
except ImportError, e:
self.logger.debug("No helper found for %s" % controller_name)
found_helper = imp.find_module('%s_helper' % controller_file, [app_path])
except ImportError:
continue
else:
helper_module = imp.load_module('%s_helper' % controller_file, *found_helper)
Expand Down

0 comments on commit 6b0b805

Please sign in to comment.