當前位置: 首頁>>代碼示例>>Python>>正文


Python django.get_version方法代碼示例

本文整理匯總了Python中django.get_version方法的典型用法代碼示例。如果您正苦於以下問題:Python django.get_version方法的具體用法?Python django.get_version怎麽用?Python django.get_version使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django的用法示例。


在下文中一共展示了django.get_version方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_cookie_samesite_django30

# 需要導入模塊: import django [as 別名]
# 或者: from django import get_version [as 別名]
def test_cookie_samesite_django30(self):
        # Raise DeprecationWarning for newer versions of Django
        with patch('django.get_version', return_value=DJANGO_SUPPORTED_VERSION):
            with self.assertRaises(DeprecationWarning) as exc:
                self.client.get('/cookies-test/')

            self.assertEqual(exc.exception.args[0], (
                'Your version of Django supports SameSite flag in the cookies mechanism. '
                'You should remove django-cookies-samesite from your project.'
            ))

        with patch('django_cookies_samesite.middleware.django.get_version', return_value=DJANGO_SUPPORTED_VERSION):
            with self.assertRaises(DeprecationWarning) as exc:
                self.client.get('/cookies-test/')

            self.assertEqual(exc.exception.args[0], (
                'Your version of Django supports SameSite flag in the cookies mechanism. '
                'You should remove django-cookies-samesite from your project.'
            )) 
開發者ID:jotes,項目名稱:django-cookies-samesite,代碼行數:21,代碼來源:test_middleware.py

示例2: get

# 需要導入模塊: import django [as 別名]
# 或者: from django import get_version [as 別名]
def get(self, request, *args, **kwargs):
        result = {
            'python_version': sys.version,
            'django_version': django.get_version(),
            'interesting_user_actions': extra_models.LoggedAction.objects \
                .exclude(action_type='set-candidate-not-elected') \
                .count(),
            'users_who_have_edited': User.objects \
                .annotate(edit_count=Count('loggedaction')) \
                .filter(edit_count__gt=0).count()
        }
        # Try to get the object name of HEAD from git:
        try:
            git_version = subprocess.check_output(
                ['git', 'rev-parse', '--verify', 'HEAD'],
                cwd=dirname(__file__),
                universal_newlines=True
            ).strip()
            result['git_version'] = git_version
        except (OSError, subprocess.CalledProcessError):
            pass
        return HttpResponse(
            json.dumps(result), content_type='application/json'
        ) 
開發者ID:mysociety,項目名稱:yournextrepresentative,代碼行數:26,代碼來源:api.py

示例3: __init__

# 需要導入模塊: import django [as 別名]
# 或者: from django import get_version [as 別名]
def __init__(self, settings=SETTINGS):
        """Initializes the Algolia engine."""

        try:
            app_id = settings['APPLICATION_ID']
            api_key = settings['API_KEY']
        except KeyError:
            raise AlgoliaEngineError(
                'APPLICATION_ID and API_KEY must be defined.')

        self.__auto_indexing = settings.get('AUTO_INDEXING', True)
        self.__settings = settings

        self.__registered_models = {}
        self.client = algoliasearch.Client(app_id, api_key)
        self.client.set_extra_header('User-Agent',
                                     'Algolia for Python (%s); Python (%s); Algolia for Django (%s); Django (%s)'
                                     % (CLIENT_VERSION, python_version(), VERSION, django_version)) 
開發者ID:algolia,項目名稱:algoliasearch-django,代碼行數:20,代碼來源:registration.py

示例4: test_migration_file_header_comments

# 需要導入模塊: import django [as 別名]
# 或者: from django import get_version [as 別名]
def test_migration_file_header_comments(self):
        """
        Test comments at top of file.
        """
        migration = type(str("Migration"), (migrations.Migration,), {
            "operations": []
        })
        dt = datetime.datetime(2015, 7, 31, 4, 40, 0, 0, tzinfo=utc)
        with mock.patch('django.db.migrations.writer.now', lambda: dt):
            writer = MigrationWriter(migration)
            output = writer.as_string()

        self.assertTrue(
            output.startswith(
                "# -*- coding: utf-8 -*-\n"
                "# Generated by Django %(version)s on 2015-07-31 04:40\n" % {
                    'version': get_version(),
                }
            )
        ) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:22,代碼來源:test_writer.py

示例5: test_migration_file_header_comments

# 需要導入模塊: import django [as 別名]
# 或者: from django import get_version [as 別名]
def test_migration_file_header_comments(self):
        """
        Test comments at top of file.
        """
        migration = type("Migration", (migrations.Migration,), {
            "operations": []
        })
        dt = datetime.datetime(2015, 7, 31, 4, 40, 0, 0, tzinfo=utc)
        with mock.patch('django.db.migrations.writer.now', lambda: dt):
            writer = MigrationWriter(migration)
            output = writer.as_string()

        self.assertTrue(
            output.startswith(
                "# Generated by Django %(version)s on 2015-07-31 04:40\n" % {
                    'version': get_version(),
                }
            )
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:21,代碼來源:test_writer.py

示例6: test_migration_file_header_comments

# 需要導入模塊: import django [as 別名]
# 或者: from django import get_version [as 別名]
def test_migration_file_header_comments(self):
        """
        Test comments at top of file.
        """
        migration = type("Migration", (migrations.Migration,), {
            "operations": []
        })
        dt = datetime.datetime(2015, 7, 31, 4, 40, 0, 0, tzinfo=utc)
        with mock.patch('django.db.migrations.writer.now', lambda: dt):
            for include_header in (True, False):
                with self.subTest(include_header=include_header):
                    writer = MigrationWriter(migration, include_header)
                    output = writer.as_string()

                    self.assertEqual(
                        include_header,
                        output.startswith(
                            "# Generated by Django %s on 2015-07-31 04:40\n\n" % get_version()
                        )
                    )
                    if not include_header:
                        # Make sure the output starts with something that's not
                        # a comment or indentation or blank line
                        self.assertRegex(output.splitlines(keepends=True)[0], r"^[^#\s]+") 
開發者ID:nesdis,項目名稱:djongo,代碼行數:26,代碼來源:test_writer.py

示例7: import_django_settings

# 需要導入模塊: import django [as 別名]
# 或者: from django import get_version [as 別名]
def import_django_settings():
    try:
        from django.core.exceptions import ImproperlyConfigured

        try:
            from django.conf import settings as _django_settings

            # We can get a situation when Django module is installed in the system, but not initialized,
            # which means we are running not in a Django process.
            # In this case the following line throws ImproperlyConfigured exception
            if 'cloudinary' in _django_settings.INSTALLED_APPS:
                from django import get_version as _get_django_version
                global USER_PLATFORM
                USER_PLATFORM = "Django/{django_version}".format(django_version=_get_django_version())

            if 'CLOUDINARY' in dir(_django_settings):
                return _django_settings.CLOUDINARY
            else:
                return None

        except ImproperlyConfigured:
            return None

    except ImportError:
        return None 
開發者ID:Tautulli,項目名稱:Tautulli,代碼行數:27,代碼來源:__init__.py

示例8: test_django_version

# 需要導入模塊: import django [as 別名]
# 或者: from django import get_version [as 別名]
def test_django_version(manage):
    django_version = django.get_version().encode("ascii") + b"\n"
    assert manage("testcmd", "--version") == django_version
    assert manage("versioncmd", "--version") == b"20.0\n" 
開發者ID:GaretJax,項目名稱:django-click,代碼行數:6,代碼來源:test_adapter.py

示例9: __init__

# 需要導入模塊: import django [as 別名]
# 或者: from django import get_version [as 別名]
def __init__(self, **kwargs):
        self.kwargs = kwargs
        self.version = self.kwargs.pop("version", get_version())

        context_settings = kwargs.setdefault("context_settings", {})
        context_settings["help_option_names"] = ["-h", "--help"] 
開發者ID:GaretJax,項目名稱:django-click,代碼行數:8,代碼來源:adapter.py

示例10: get_version

# 需要導入模塊: import django [as 別名]
# 或者: from django import get_version [as 別名]
def get_version(self):
        """
        Return the Django version, which should be correct for all
        built-in Django commands. User-supplied commands should
        override this method.

        """
        return django.get_version() 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:10,代碼來源:base.py

示例11: process_response

# 需要導入模塊: import django [as 別名]
# 或者: from django import get_version [as 別名]
def process_response(self, request, response):
        # same-site = None introduced for Chrome 80 breaks for Chrome 51-66
        # Refer (https://www.chromium.org/updates/same-site/incompatible-clients)
        http_user_agent = request.META.get("HTTP_USER_AGENT") or " "
        user_agent_checker = UserAgentChecker(http_user_agent)

        if user_agent_checker.do_not_send_same_site_policy:
            return response

        if LooseVersion(django.get_version()) >= LooseVersion(DJANGO_SUPPORTED_VERSION):
            raise DeprecationWarning(
                "Your version of Django supports SameSite flag in the cookies mechanism. "
                "You should remove django-cookies-samesite from your project."
            )

        if not self.samesite_flag:
            return response

        # TODO: capitalize those values
        if self.samesite_flag not in {"Lax", "None", "Strict"}:
            raise ValueError('samesite must be "Lax", "None", or "Strict".')

        if self.samesite_force_all:
            for cookie in response.cookies:
                self.update_cookie(cookie, request, response)
        else:
            for cookie in self.protected_cookies:
                if cookie in response.cookies:
                    self.update_cookie(cookie, request, response)

        return response 
開發者ID:jotes,項目名稱:django-cookies-samesite,代碼行數:33,代碼來源:middleware.py

示例12: test_settings_default_values

# 需要導入模塊: import django [as 別名]
# 或者: from django import get_version [as 別名]
def test_settings_default_values(self):
        """Check if middleware reads default values as expected"""
        with self.settings():
            middleware = CookiesSameSite()
            self.assertEqual(middleware.samesite_force_all, None)
            self.assertEqual(middleware.protected_cookies, {'sessionid', 'csrftoken'})

            if LooseVersion(django.get_version()) >= LooseVersion('3.0'):
                self.assertEqual(middleware.samesite_flag, 'Lax')
            else:
                self.assertEqual(middleware.samesite_flag, '') 
開發者ID:jotes,項目名稱:django-cookies-samesite,代碼行數:13,代碼來源:test_middleware.py

示例13: django_version

# 需要導入模塊: import django [as 別名]
# 或者: from django import get_version [as 別名]
def django_version():
    if django.get_version().startswith('1.8'):
        return DjangoVersion.DJANGO_18
    elif django.get_version().startswith('1.9'):
        return DjangoVersion.DJANGO_19
    elif django.get_version().startswith('1.10'):
        return DjangoVersion.DJANGO_110
    elif django.get_version().startswith('1.11'):
        return DjangoVersion.DJANGO_111
    elif django.get_version().startswith('2.0'):
        return DjangoVersion.DJANGO_20
    elif django.get_version().startswith('2.1'):
        return DjangoVersion.DJANGO_21 
開發者ID:ctxis,項目名稱:django-admin-view-permission,代碼行數:15,代碼來源:utils.py

示例14: case_setup_django

# 需要導入模塊: import django [as 別名]
# 或者: from django import get_version [as 別名]
def case_setup_django(debugger_runner_simple):

    class WriterThread(AbstractWriterThreadCaseDjango):
        pass

    class CaseSetup(object):

        @contextmanager
        def test_file(self, **kwargs):
            import django
            version = [int(x) for x in django.get_version().split('.')][:2]
            if version == [1, 7]:
                django_folder = 'my_django_proj_17'
            elif version in ([2, 1], [2, 2], [3, 0]):
                django_folder = 'my_django_proj_21'
            else:
                raise AssertionError('Can only check django 1.7, 2.1, 2.2 and 3.0 right now. Found: %s' % (version,))

            WriterThread.DJANGO_FOLDER = django_folder
            for key, value in kwargs.items():
                assert hasattr(WriterThread, key)
                setattr(WriterThread, key, value)

            with debugger_runner_simple.check_case(WriterThread) as writer:
                yield writer

    return CaseSetup() 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:29,代碼來源:debugger_fixtures.py

示例15: _django_version

# 需要導入模塊: import django [as 別名]
# 或者: from django import get_version [as 別名]
def _django_version(self):
        try:
            import django
            return "django/%s" % django.get_version()
        except ImportError:
            return None 
開發者ID:percy,項目名稱:python-percy-client,代碼行數:8,代碼來源:user_agent.py


注:本文中的django.get_version方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。