Skip to content

Commit

Permalink
Remove unsupport django compatibility code and cleanup some imports (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris7 authored May 20, 2018
1 parent 7f4c59b commit 94b5bdd
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 110 deletions.
12 changes: 1 addition & 11 deletions wooey/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
from . import version
import os
if version.DJANGO_VERSION >= version.DJ17:
default_app_config = 'wooey.apps.WooeyConfig'
else:
if os.environ.get('TESTING') != 'True' and os.environ.get('WOOEY_BOOTSTRAP') != 'True':
from . import settings as wooey_settings
# we need to call from within wooey_settings so the celery/etc vars are setup
if not wooey_settings.settings.configured:
wooey_settings.settings.configure()
from .apps import WooeyConfig
WooeyConfig().ready()
default_app_config = 'wooey.apps.WooeyConfig'
5 changes: 1 addition & 4 deletions wooey/backend/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ def bootstrap(env=None, cwd=None):
# do the same with urls
shutil.move(os.path.join(project_base_dir, 'urls.py'), os.path.join(project_base_dir, 'urls', 'django_urls.py'))
env['DJANGO_SETTINGS_MODULE'] = '.'.join([project_name, 'settings', 'user_settings'])
if django_compat.DJANGO_VERSION >= django_compat.DJ17:
subprocess.call(['python', 'manage.py', 'migrate'], env=env, cwd=project_root)
else:
subprocess.call(['python', 'manage.py', 'syncdb', '--noinput'], env=env, cwd=project_root)
subprocess.call(['python', 'manage.py', 'migrate'], env=env, cwd=project_root)
subprocess.call(['python', 'manage.py', 'createcachetable'], env=env, cwd=project_root)
subprocess.call(['python', 'manage.py', 'collectstatic', '--noinput'], env=env, cwd=project_root)
sys.stdout.write("Please enter the project directory {0}, and run python manage.py createsuperuser and"
Expand Down
4 changes: 2 additions & 2 deletions wooey/conf/project_template/settings/wooey_settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .django_settings import *
from wooey.version import DJANGO_VERSION, DJ17, DJ110
from wooey.version import DJANGO_VERSION, DJ110
from django.utils.translation import ugettext_lazy as _

INSTALLED_APPS += (
Expand All @@ -23,7 +23,7 @@
('fr', _('French')),
('ja', _('Japanese')),
('nl', _('Dutch')),
('zh-hans' if DJANGO_VERSION >= DJ17 else 'zh-cn', _('Simplified Chinese')),
('zh-hans', _('Simplified Chinese')),
]

NEW_MIDDLEWARE = []
Expand Down
39 changes: 0 additions & 39 deletions wooey/django_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,6 @@
except RuntimeError:
pass

# JSON compatibility fixes
if DJANGO_VERSION < DJ17:
import json
from django.http import HttpResponse


class JsonResponse(HttpResponse):
"""
JSON response
# from https://gist.github.com/philippeowagner/3179eb475fe1795d6515
"""

def __init__(self, content, mimetype='application/json', status=None, content_type=None, **kwargs):
super(JsonResponse, self).__init__(
content=json.dumps(content),
mimetype=mimetype,
status=status,
content_type=content_type,
)


else:
from django.http import JsonResponse

if DJANGO_VERSION < DJ19:
from django.template.base import TagHelperNode, parse_bits
else:
Expand All @@ -40,18 +16,3 @@ def __init__(self, content, mimetype='application/json', status=None, content_ty
get_template_from_string = Engine.get_default().from_string
else:
from django.template.loader import get_template_from_string


if DJANGO_VERSION < DJ17:
from django.forms.util import flatatt, format_html

else:
from django.forms.utils import flatatt, format_html

def get_cache(cache):
if DJANGO_VERSION < DJ17:
from django.core.cache import get_cache
return get_cache(cache)
else:
from django.core.cache import caches
return caches[cache]
10 changes: 5 additions & 5 deletions wooey/forms/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
__author__ = 'chris'
import copy
import json
import six
import os
from collections import OrderedDict

import six
from django import forms
from django.forms.utils import flatatt, format_html
from django.http.request import QueryDict
from django.utils.safestring import mark_safe

from .scripts import WooeyForm
from . import config
from ..backend import utils
from ..models import ScriptParameter, ScriptVersion
from ..django_compat import flatatt, format_html
from .scripts import WooeyForm
from .. import version
from ..backend import utils
from ..models import ScriptVersion


def mutli_render(render_func, appender_data_dict=None):
Expand Down
10 changes: 5 additions & 5 deletions wooey/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from celery import states
from django.db import models
from django.conf import settings
from django.core.cache import caches as django_cache
from django.core.files.storage import SuspiciousFileOperation
from django.core.urlresolvers import reverse
from django.contrib.auth.models import Group
Expand All @@ -21,7 +22,6 @@
from . mixins import UpdateScriptsMixin, ModelDiffMixin, WooeyPy2Mixin
from .. import settings as wooey_settings
from .. backend import utils
from .. import django_compat

# TODO: Handle cases where celery is not setup but specified to be used
tasks = importlib.import_module(wooey_settings.WOOEY_CELERY_TASKS)
Expand Down Expand Up @@ -100,7 +100,7 @@ class ScriptVersion(ModelDiffMixin, WooeyPy2Mixin, models.Model):
# parameters, but even a huge site may only have a few thousand parameters to query though.
script_version = models.CharField(max_length=50, help_text='The script version.', blank=True, default='1')
script_iteration = models.PositiveSmallIntegerField(default=1)
script_path = models.FileField() if django_compat.DJANGO_VERSION >= django_compat.DJ17 else models.FileField(upload_to=wooey_settings.WOOEY_SCRIPT_DIR)
script_path = models.FileField()
default_version = models.BooleanField(default=False)
script = models.ForeignKey('Script', related_name='script_version')
checksum = models.CharField(max_length=40, blank=True)
Expand Down Expand Up @@ -248,7 +248,7 @@ def update_realtime(self, stdout='', stderr='', delete=False):
self.stderr = stderr
self.save()
elif wooey_cache is not None:
cache = django_compat.get_cache(wooey_cache)
cache = django_cache[wooey_cache]
if delete:
cache.delete(self.get_realtime_key())
else:
Expand All @@ -257,7 +257,7 @@ def update_realtime(self, stdout='', stderr='', delete=False):
def get_realtime(self):
wooey_cache = wooey_settings.WOOEY_REALTIME_CACHE
if wooey_cache is not None:
cache = django_compat.get_cache(wooey_cache)
cache = django_cache[wooey_cache]
out = cache.get(self.get_realtime_key())
if out:
return json.loads(out)
Expand Down Expand Up @@ -571,7 +571,7 @@ def __str__(self):


class WooeyFile(WooeyPy2Mixin, models.Model):
filepath = models.FileField(max_length=500) if django_compat.DJANGO_VERSION >= django_compat.DJ17 else models.FileField(max_length=500, upload_to=wooey_settings.WOOEY_SCRIPT_DIR)
filepath = models.FileField(max_length=500)
filepreview = models.TextField(null=True, blank=True)
filetype = models.CharField(max_length=255, null=True, blank=True)
size_bytes = models.IntegerField(null=True)
Expand Down
8 changes: 2 additions & 6 deletions wooey/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,10 @@ def test_jobs(self):
new_job.submit_to_celery(rerun=True)
# check that we overwrite our output
new_output = sorted([i.pk for i in UserFile.objects.filter(job=new_job)])
# Django 1.6 has a bug where they are reusing pk numbers
if version.DJANGO_VERSION >= version.DJ17:
self.assertNotEqual(old_output, new_output)
self.assertNotEqual(old_output, new_output)
self.assertEqual(len(old_output), len(new_output))
# check the old entries are gone
if version.DJANGO_VERSION >= version.DJ17:
# Django 1.6 has a bug where they are reusing pk numbers, so once again we cannot use this check
self.assertEqual([], list(UserFile.objects.filter(pk__in=old_output)))
self.assertEqual([], list(UserFile.objects.filter(pk__in=old_output)))

file_previews = utils.get_file_previews(job)
for group, files in file_previews.items():
Expand Down
8 changes: 4 additions & 4 deletions wooey/views/authentication.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import absolute_import
from django.views.generic import CreateView
from django.http import HttpResponseRedirect
from django.contrib.auth import login, authenticate, get_user_model
from django.core.urlresolvers import reverse
from django.forms.models import modelform_factory
from django.contrib.auth import login, authenticate, get_user_model
from django.http import HttpResponseRedirect
from django.http import JsonResponse
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import force_text
from django.views.generic import CreateView

from .. import settings as wooey_settings
from ..django_compat import JsonResponse


class WooeyRegister(CreateView):
Expand Down
17 changes: 8 additions & 9 deletions wooey/views/favorite.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from django.views.generic import DetailView, TemplateView
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, HttpResponseNotFound, HttpResponseBadRequest
from django.core.urlresolvers import reverse
from django.conf import settings
from django.views.decorators.csrf import ensure_csrf_cookie
from django.contrib.contenttypes.models import ContentType

from ..django_compat import JsonResponse

from django.contrib.auth.decorators import login_required
from django.contrib.contenttypes.models import ContentType
from django.http import (
HttpResponseForbidden,
HttpResponseNotFound,
HttpResponseBadRequest,
JsonResponse,
)
from django.views.decorators.csrf import ensure_csrf_cookie

from ..models import Favorite

Expand Down
19 changes: 7 additions & 12 deletions wooey/views/views.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
from __future__ import absolute_import, unicode_literals
from collections import defaultdict
import datetime as dt

from django.views.generic import DetailView, TemplateView, View
from django.template.loader import render_to_string
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.conf import settings
from django.forms import FileField
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import force_text
from django.http import JsonResponse
from django.template import RequestContext
from django.contrib.auth import get_user_model
from django.http import Http404

from django.contrib.contenttypes.models import ContentType
from django.template.loader import render_to_string
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _
from django.views.generic import DetailView, TemplateView, View

from ..backend import utils
from ..models import WooeyJob, Script, UserFile, Favorite, ScriptVersion
from .. import settings as wooey_settings
from ..django_compat import JsonResponse


class WooeyScriptBase(DetailView):
Expand Down
23 changes: 10 additions & 13 deletions wooey/views/wooey_celery.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
from __future__ import absolute_import
import six

from django.core.urlresolvers import reverse
from django.views.generic import DetailView, TemplateView
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import force_text
from django.template.defaultfilters import escape

from celery import app, states

celery_app = app.app_or_default()

from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.db.models import Q
from django.http import JsonResponse
from django.template.defaultfilters import escape
from django.template.loader import render_to_string
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _
from django.views.generic import DetailView, ListView

from ..models import WooeyJob, UserFile, Favorite
from .. import settings as wooey_settings
from ..backend.utils import valid_user, get_file_previews
from ..django_compat import JsonResponse
from django.db.models import Q
from django.views.generic import ListView
from django.template.loader import render_to_string

celery_app = app.app_or_default()

SPANBASE = "<span title='{}' class='glyphicon {}'></span> "
MAXIMUM_JOBS_NAVBAR = 10
Expand Down

0 comments on commit 94b5bdd

Please sign in to comment.