本文整理汇总了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.'
))
示例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'
)
示例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))
示例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(),
}
)
)
示例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(),
}
)
)
示例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]+")
示例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
示例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"
示例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"]
示例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()
示例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
示例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, '')
示例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
示例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()
示例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