Эх сурвалжийг харах

HUE-3287 [core] Django 1.11 upgrade
- To upgrade Django 1.7, following changes are needed:

- South (database migration tool) has been removed, South module is now integrated in Django 1.7
- GenericRelation field name: related_name became related_query_name
- BooleanFields do not accept null values, in Django 1.6 it was not the case. We can use NullBooleanField.
- post_syncdb has been renamed to post_migrate
- syncdb renamed to makemigrations
- StrAndUnicode does not exist in django.utils.encoding use python_2_unicode_compatible
- find_management_module has been removed

Prakash Ranade 8 жил өмнө
parent
commit
88a7c0553d

+ 2 - 2
apps/beeswax/src/beeswax/models.py

@@ -275,7 +275,7 @@ class SavedQuery(models.Model):
 
 
   is_redacted = models.BooleanField(default=False)
   is_redacted = models.BooleanField(default=False)
 
 
-  doc = generic.GenericRelation(Document, related_name='hql_doc')
+  doc = generic.GenericRelation(Document, related_query_name='hql_doc')
 
 
   class Meta:
   class Meta:
     ordering = ['-mtime']
     ordering = ['-mtime']
@@ -509,7 +509,7 @@ class MetaInstall(models.Model):
   """
   """
   Metadata about the installation. Should have at most one row.
   Metadata about the installation. Should have at most one row.
   """
   """
-  installed_example = models.BooleanField()
+  installed_example = models.BooleanField(default=False)
 
 
   @staticmethod
   @staticmethod
   def get():
   def get():

+ 1 - 1
apps/jobsub/src/jobsub/models.py

@@ -76,7 +76,7 @@ class CheckForSetup(models.Model):
   whether jobsub_setup has run succesfully.
   whether jobsub_setup has run succesfully.
   """
   """
   # Pre-Hue2 setup
   # Pre-Hue2 setup
-  setup_run = models.BooleanField()
+  setup_run = models.BooleanField(default=False)
   # What kind of setup have we done?
   # What kind of setup have we done?
   setup_level = models.IntegerField(default=0)
   setup_level = models.IntegerField(default=0)
 
 

+ 1 - 1
apps/oozie/src/oozie/models.py

@@ -125,7 +125,7 @@ class Job(models.Model):
                                 help_text=_t('Parameters used at the submission time (e.g. market=US, oozie.use.system.libpath=true).'))
                                 help_text=_t('Parameters used at the submission time (e.g. market=US, oozie.use.system.libpath=true).'))
   is_trashed = models.BooleanField(default=False, db_index=True, verbose_name=_t('Is trashed'), blank=True, # Deprecated
   is_trashed = models.BooleanField(default=False, db_index=True, verbose_name=_t('Is trashed'), blank=True, # Deprecated
                                    help_text=_t('If this job is trashed.'))
                                    help_text=_t('If this job is trashed.'))
-  doc = generic.GenericRelation(Document, related_name='oozie_doc')
+  doc = generic.GenericRelation(Document, related_query_name='oozie_doc')
   data = models.TextField(blank=True, default=json.dumps({}))  # e.g. data=json.dumps({'sla': [python data], ...})
   data = models.TextField(blank=True, default=json.dumps({}))  # e.g. data=json.dumps({'sla': [python data], ...})
 
 
   objects = JobManager()
   objects = JobManager()

+ 1 - 1
apps/pig/src/pig/models.py

@@ -57,7 +57,7 @@ class PigScript(Document):
       'hadoopProperties': []
       'hadoopProperties': []
   }))
   }))
 
 
-  doc = generic.GenericRelation(Doc, related_name='pig_doc')
+  doc = generic.GenericRelation(Doc, related_query_name='pig_doc')
 
 
   isV2 = False
   isV2 = False
 
 

+ 2 - 2
apps/useradmin/src/useradmin/models.py

@@ -293,8 +293,8 @@ def update_app_permissions(**kwargs):
             uptodate,
             uptodate,
             available - len(added) - updated - uptodate))
             available - len(added) - updated - uptodate))
 
 
-models.signals.post_syncdb.connect(update_app_permissions)
-models.signals.post_syncdb.connect(get_default_user_group)
+models.signals.post_migrate.connect(update_app_permissions)
+models.signals.post_migrate.connect(get_default_user_group)
 
 
 
 
 def install_sample_user():
 def install_sample_user():

+ 2 - 2
desktop/Makefile

@@ -99,8 +99,8 @@ $(DESKTOP_DB): $(BLD_DIR_BIN)/hue
 	  rm -f $@ ; \
 	  rm -f $@ ; \
 	fi
 	fi
 	@echo "--- Syncing/updating database at $@"
 	@echo "--- Syncing/updating database at $@"
-	@$(ENV_PYTHON) $(BLD_DIR_BIN)/hue syncdb --noinput
-	@$(ENV_PYTHON) $(BLD_DIR_BIN)/hue migrate --merge
+	@$(ENV_PYTHON) $(BLD_DIR_BIN)/hue makemigrations --noinput
+	@$(ENV_PYTHON) $(BLD_DIR_BIN)/hue migrate
 
 
 # Targets that simply recurse into all of the applications
 # Targets that simply recurse into all of the applications
 ENV_INSTALL_TARGETS := $(APPS:%=.recursive-env-install/%)
 ENV_INSTALL_TARGETS := $(APPS:%=.recursive-env-install/%)

+ 45 - 0
desktop/core/ext-py/Django-1.7/django/middleware/security.py

@@ -0,0 +1,45 @@
+# This code is picked from Django 1.8 truck from https://github.com/django/django/blob/master/django/middleware/security.py
+import re
+
+from django.conf import settings
+from django.http import HttpResponsePermanentRedirect
+
+
+class SecurityMiddleware(object):
+    def __init__(self, get_response=None):
+        self.sts_seconds = settings.SECURE_HSTS_SECONDS
+        self.sts_include_subdomains = settings.SECURE_HSTS_INCLUDE_SUBDOMAINS
+        self.content_type_nosniff = settings.SECURE_CONTENT_TYPE_NOSNIFF
+        self.xss_filter = settings.SECURE_BROWSER_XSS_FILTER
+        self.redirect = settings.SECURE_SSL_REDIRECT
+        self.redirect_host = settings.SECURE_SSL_HOST
+        self.redirect_exempt = [re.compile(r) for r in settings.SECURE_REDIRECT_EXEMPT]
+        self.get_response = get_response
+
+    def process_request(self, request):
+        path = request.path.lstrip("/")
+        if (self.redirect and not request.is_secure() and
+                not any(pattern.search(path)
+                        for pattern in self.redirect_exempt)):
+            host = self.redirect_host or request.get_host()
+            return HttpResponsePermanentRedirect(
+                "https://%s%s" % (host, request.get_full_path())
+            )
+
+    def process_response(self, request, response):
+        if (self.sts_seconds and request.is_secure() and
+                'strict-transport-security' not in response):
+            sts_header = "max-age=%s" % self.sts_seconds
+
+            if self.sts_include_subdomains:
+                sts_header = sts_header + "; includeSubDomains"
+
+            response["strict-transport-security"] = sts_header
+
+        if self.content_type_nosniff and 'x-content-type-options' not in response:
+            response["x-content-type-options"] = "nosniff"
+
+        if self.xss_filter and 'x-xss-protection' not in response:
+            response["x-xss-protection"] = "1; mode=block"
+
+        return response

+ 10 - 1
desktop/core/src/desktop/lib/django_forms.py

@@ -28,7 +28,7 @@ from django.forms.fields import MultiValueField, CharField, ChoiceField, Boolean
 from django.forms.widgets import MultiWidget, Select, TextInput, Textarea, HiddenInput, Input
 from django.forms.widgets import MultiWidget, Select, TextInput, Textarea, HiddenInput, Input
 from django.utils import formats
 from django.utils import formats
 from django.utils.safestring import mark_safe
 from django.utils.safestring import mark_safe
-from django.utils.encoding import StrAndUnicode, force_unicode
+from django.utils.encoding import python_2_unicode_compatible, force_unicode
 
 
 import desktop.lib.i18n
 import desktop.lib.i18n
 from desktop.lib.i18n import smart_str
 from desktop.lib.i18n import smart_str
@@ -36,6 +36,15 @@ from desktop.lib.i18n import smart_str
 
 
 LOG = logging.getLogger(__name__)
 LOG = logging.getLogger(__name__)
 
 
+try:
+  from django.utils.encoding import StrAndUnicode
+except ImportError:
+  from django.utils.encoding import python_2_unicode_compatible
+
+  @python_2_unicode_compatible
+  class StrAndUnicode(object):
+    def __str__(self):
+      return self.code
 
 
 class SplitDateTimeWidget(forms.MultiWidget):
 class SplitDateTimeWidget(forms.MultiWidget):
   """
   """

+ 1 - 1
desktop/core/src/desktop/manage_entry.py

@@ -36,7 +36,7 @@ def entry():
   _deprecation_check(sys.argv[0])
   _deprecation_check(sys.argv[0])
 
 
   from django.core.exceptions import ImproperlyConfigured
   from django.core.exceptions import ImproperlyConfigured
-  from django.core.management import execute_from_command_line, find_commands, find_management_module
+  from django.core.management import execute_from_command_line, find_commands
   from django.core.management import LaxOptionParser
   from django.core.management import LaxOptionParser
   from django.core.management.base import BaseCommand
   from django.core.management.base import BaseCommand
 
 

+ 4 - 4
desktop/core/src/desktop/management/commands/test.py

@@ -26,7 +26,7 @@ from django.core.management.base import BaseCommand
 from django.test.utils import get_runner
 from django.test.utils import get_runner
 from django_nose import runner
 from django_nose import runner
 
 
-import south.management.commands
+#import south.management.commands
 import sys
 import sys
 import textwrap
 import textwrap
 import logging
 import logging
@@ -74,9 +74,9 @@ class Command(BaseCommand):
     args = argv[2:] # First two are "desktop" and "test"
     args = argv[2:] # First two are "desktop" and "test"
 
 
     # Patch South things in
     # Patch South things in
-    south.management.commands.patch_for_test_db_setup()
-    south_logger = logging.getLogger('south')
-    south_logger.setLevel(logging.INFO)
+    #south.management.commands.patch_for_test_db_setup()
+    #south_logger = logging.getLogger('south')
+    #south_logger.setLevel(logging.INFO)
 
 
     if len(args) == 0:
     if len(args) == 0:
       print self.help
       print self.help

+ 2 - 2
desktop/core/src/desktop/models.py

@@ -944,7 +944,7 @@ class Document2QuerySet(QuerySet, Document2QueryMixin):
 
 
 class Document2Manager(models.Manager, Document2QueryMixin):
 class Document2Manager(models.Manager, Document2QueryMixin):
 
 
-  def get_query_set(self):
+  def get_queryset(self):
     return Document2QuerySet(self.model, using=self._db)
     return Document2QuerySet(self.model, using=self._db)
 
 
   # TODO prevent get() in favor of this
   # TODO prevent get() in favor of this
@@ -1077,7 +1077,7 @@ class Document2(models.Model):
 
 
   parent_directory = models.ForeignKey('self', blank=True, null=True, related_name='children', on_delete=models.CASCADE)
   parent_directory = models.ForeignKey('self', blank=True, null=True, related_name='children', on_delete=models.CASCADE)
 
 
-  doc = generic.GenericRelation(Document, related_name='doc_doc') # Compatibility with Hue 3
+  doc = generic.GenericRelation(Document, related_query_name='doc_doc') # Compatibility with Hue 3
 
 
   objects = Document2Manager()
   objects = Document2Manager()
 
 

+ 1 - 1
desktop/core/src/desktop/settings.py

@@ -191,7 +191,7 @@ INSTALLED_APPS = [
     'django_extensions',
     'django_extensions',
 
 
     # 'debug_toolbar',
     # 'debug_toolbar',
-    'south', # database migration tool
+    #'south', # database migration tool
 
 
     # i18n support
     # i18n support
     'babeldjango',
     'babeldjango',

+ 2 - 2
tools/app_reg/build.py

@@ -58,8 +58,8 @@ def make_syncdb():
   statuses = []
   statuses = []
   hue_exec = os.path.join(common.INSTALL_ROOT, 'build', 'env', 'bin', 'hue')
   hue_exec = os.path.join(common.INSTALL_ROOT, 'build', 'env', 'bin', 'hue')
   if os.path.exists(hue_exec):
   if os.path.exists(hue_exec):
-    statuses.append( runcmd([ hue_exec, 'syncdb', '--noinput' ]) )
-    statuses.append( runcmd([ hue_exec, 'migrate', '--merge' ]) )
+    statuses.append( runcmd([ hue_exec, 'makemigrations', '--noinput' ]) )
+    statuses.append( runcmd([ hue_exec, 'migrate' ]) )
   return not any(statuses)
   return not any(statuses)
 
 
 def make_collectstatic():
 def make_collectstatic():