本文整理匯總了Python中django.VERSION屬性的典型用法代碼示例。如果您正苦於以下問題:Python django.VERSION屬性的具體用法?Python django.VERSION怎麽用?Python django.VERSION使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django
的用法示例。
在下文中一共展示了django.VERSION屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: sql_table_creation_suffix
# 需要導入模塊: import django [as 別名]
# 或者: from django import VERSION [as 別名]
def sql_table_creation_suffix(self):
suffix = []
if django.VERSION < (1, 7):
if self.connection.settings_dict['TEST_CHARSET']:
suffix.append('CHARACTER SET {0}'.format(
self.connection.settings_dict['TEST_CHARSET']))
if self.connection.settings_dict['TEST_COLLATION']:
suffix.append('COLLATE {0}'.format(
self.connection.settings_dict['TEST_COLLATION']))
else:
test_settings = self.connection.settings_dict['TEST']
if test_settings['CHARSET']:
suffix.append('CHARACTER SET %s' % test_settings['CHARSET'])
if test_settings['COLLATION']:
suffix.append('COLLATE %s' % test_settings['COLLATION'])
return ' '.join(suffix)
示例2: get_version
# 需要導入模塊: import django [as 別名]
# 或者: from django import VERSION [as 別名]
def get_version(version=None):
"Returns a PEP 386-compliant version number from VERSION."
version = get_complete_version(version)
# Now build the two parts of the version number:
# major = X.Y[.Z]
# sub = .devN - for pre-alpha releases
# | {a|b|c}N - for alpha, beta and rc releases
major = get_major_version(version)
sub = ''
if version[3] == 'alpha' and version[4] == 0:
git_changeset = get_git_changeset()
if git_changeset:
sub = '.dev%s' % git_changeset
elif version[3] != 'final':
mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'}
sub = mapping[version[3]] + str(version[4])
return str(major + sub)
示例3: get_git_changeset
# 需要導入模塊: import django [as 別名]
# 或者: from django import VERSION [as 別名]
def get_git_changeset():
"""Returns a numeric identifier of the latest git changeset.
The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.
This value isn't guaranteed to be unique, but collisions are very unlikely,
so it's sufficient for generating the development version numbers.
"""
repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
git_log = subprocess.Popen('git log --pretty=format:%ct --quiet -1 HEAD',
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=True, cwd=repo_dir, universal_newlines=True)
timestamp = git_log.communicate()[0]
try:
timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
except ValueError:
return None
return timestamp.strftime('%Y%m%d%H%M%S')
示例4: test_migration2
# 需要導入模塊: import django [as 別名]
# 或者: from django import VERSION [as 別名]
def test_migration2(self):
"""Same test as test_migration, but this one passes."""
MyModel = self.get_model_before('test_app.MyModel')
self.assertEqual(MyModel.__name__, 'MyModel')
self.run_migration()
ForeignModel = self.get_model_after('test_app.ForeignModel')
self.assertEqual(ForeignModel.__name__, 'ForeignModel')
# get_model_before/get_model_after seems to not get the same model as
# this crazy thing.
if django.VERSION >= (2, 0):
MyModel = ForeignModel.my.field.related_model
else:
MyModel = ForeignModel.my.field.rel.to
self.assertEqual(MyModel.__name__, 'MyModel')
my = MyModel(name='test_my', number=1, double_number=3.14)
my.save()
ForeignModel(name='test_foreign', my=my)
示例5: get_version
# 需要導入模塊: import django [as 別名]
# 或者: from django import VERSION [as 別名]
def get_version(version=None):
"""Return a PEP 440-compliant version number from VERSION."""
version = get_complete_version(version)
# Now build the two parts of the version number:
# main = X.Y[.Z]
# sub = .devN - for pre-alpha releases
# | {a|b|rc}N - for alpha, beta, and rc releases
main = get_main_version(version)
sub = ''
if version[3] == 'alpha' and version[4] == 0:
git_changeset = get_git_changeset()
if git_changeset:
sub = '.dev%s' % git_changeset
elif version[3] != 'final':
mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'rc'}
sub = mapping[version[3]] + str(version[4])
return main + sub
示例6: get_git_changeset
# 需要導入模塊: import django [as 別名]
# 或者: from django import VERSION [as 別名]
def get_git_changeset():
"""Return a numeric identifier of the latest git changeset.
The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.
This value isn't guaranteed to be unique, but collisions are very unlikely,
so it's sufficient for generating the development version numbers.
"""
repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
git_log = subprocess.Popen(
'git log --pretty=format:%ct --quiet -1 HEAD',
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=True, cwd=repo_dir, universal_newlines=True,
)
timestamp = git_log.communicate()[0]
try:
timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
except ValueError:
return None
return timestamp.strftime('%Y%m%d%H%M%S')
示例7: content
# 需要導入模塊: import django [as 別名]
# 或者: from django import VERSION [as 別名]
def content(self, value):
workbook = None
if not bool(value) or not len(value): # Short-circuit to protect against empty querysets/empty lists/None, etc
self._container = []
return
elif isinstance(value, list):
workbook = self._serialize_list(value)
elif isinstance(value, QuerySet):
workbook = self._serialize_queryset(value)
if django.VERSION < (1, 9):
if isinstance(value, ValuesQuerySet):
workbook = self._serialize_values_queryset(value)
if workbook is None:
raise ValueError('ExcelResponse accepts the following data types: list, dict, QuerySet, ValuesQuerySet')
if self.force_csv:
self['Content-Type'] = 'text/csv; charset=utf8'
self['Content-Disposition'] = 'attachment;filename="{}.csv"'.format(self.output_filename)
workbook.seek(0)
workbook = self.make_bytes(workbook.getvalue())
else:
self['Content-Type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
self['Content-Disposition'] = 'attachment; filename="{}.xlsx"'.format(self.output_filename)
workbook = save_virtual_workbook(workbook)
self._container = [self.make_bytes(workbook)]
示例8: test_rollback__with_sid
# 需要導入模塊: import django [as 別名]
# 或者: from django import VERSION [as 別名]
def test_rollback__with_sid(self):
"""
Test of rollback with transaction savepoint
"""
@compat.commit_on_success
def db_action():
m = UnimportantThing(pk=3, importance=3)
m.save()
return m
@compat.commit_on_success
def db_action_with_rollback(m):
m.importance = 5
sid = django.db.transaction.savepoint()
m.save()
compat.rollback(None, sid)
if django.VERSION < (1, 5): # Rollback doesn't work with SQLite
return
m = db_action()
db_action_with_rollback(m)
self.assertEqual(UnimportantThing.objects.get(pk=3).importance, 3)
示例9: test_rollback__without_sid
# 需要導入模塊: import django [as 別名]
# 或者: from django import VERSION [as 別名]
def test_rollback__without_sid(self):
"""
Test of rollback without transaction savepoint
"""
@compat.commit_on_success
def db_action():
m = UnimportantThing(pk=4, importance=4)
m.save()
return m
@compat.commit_on_success
def db_action_with_rollback(m):
m.importance = 5
m.save()
compat.rollback()
if django.VERSION < (1, 8): # Rollback doesn't work after .save() if an exception isn't thrown
return
m = db_action()
db_action_with_rollback(m)
self.assertEqual(UnimportantThing.objects.get(pk=4).importance, 4)
示例10: publisher_status
# 需要導入模塊: import django [as 別名]
# 或者: from django import VERSION [as 別名]
def publisher_status(self, obj):
if not self.has_publish_permission(self.request, obj):
return ''
template_name = 'publisher/change_list_publish_status.html'
publish_btn = None
if obj.is_dirty:
publish_btn = reverse(self.publish_reverse, args=(obj.pk, ))
t = loader.get_template(template_name)
c = Context({
'publish_btn': publish_btn,
})
if django.VERSION >= (1, 10):
return t.render(c.flatten())
else:
return t.render(c)
示例11: publisher_publish
# 需要導入模塊: import django [as 別名]
# 或者: from django import VERSION [as 別名]
def publisher_publish(self, obj):
template_name = 'publisher/change_list_publish.html'
is_published = False
if obj.publisher_linked and obj.is_draft:
is_published = True
t = loader.get_template(template_name)
c = Context({
'object': obj,
'is_published': is_published,
'has_publish_permission': self.has_publish_permission(self.request, obj),
'publish_url': reverse(self.publish_reverse, args=(obj.pk, )),
'unpublish_url': reverse(self.unpublish_reverse, args=(obj.pk, )),
})
if django.VERSION >= (1, 10):
return t.render(c.flatten())
else:
return t.render(c)
示例12: _get_field_type
# 需要導入模塊: import django [as 別名]
# 或者: from django import VERSION [as 別名]
def _get_field_type(field):
if isinstance(field, models.ForeignKey):
if django.VERSION >= (2, 0):
to = field.remote_field.model
if isinstance(to, str):
to = _resolve_model(field, to)
else:
to = field.rel.to
if isinstance(to, str):
to = _resolve_model(field, to)
return u":type %s: %s to :class:`~%s.%s`" % (
field.name,
type(field).__name__,
to.__module__,
to.__name__,
)
else:
return u":type %s: %s" % (field.name, type(field).__name__)
示例13: test_model_fields
# 需要導入模塊: import django [as 別名]
# 或者: from django import VERSION [as 別名]
def test_model_fields(self):
lines = []
simple_model_path = 'sphinxcontrib_django.tests.test_docstrings.SimpleModel'
if django.VERSION < (3, 0):
obj = DeferredAttribute(field_name='dummy_field', model=simple_model_path)
else:
model = import_string(simple_model_path)
obj = DeferredAttribute(field=model._meta.get_field('dummy_field'))
docstrings._improve_attribute_docs(obj, '{}.dummy_field'.format(simple_model_path), lines)
self.assertEqual(
lines,
[
"**Model field:** dummy field",
],
)
示例14: render_activity
# 需要導入模塊: import django [as 別名]
# 或者: from django import VERSION [as 別名]
def render_activity(context, activity, template_prefix='', missing_data_policy=LOG):
if hasattr(activity, 'enriched') and not activity.enriched:
handle_not_enriched_data(activity, missing_data_policy)
return ''
if template_prefix != '':
template_prefix = '%s_' % template_prefix
if 'activities' in activity:
template_name = "activity/aggregated/%s%s.html" % (template_prefix, activity['verb'])
else:
template_name = "activity/%s%s.html" % (template_prefix, activity['verb'])
tmpl = loader.get_template(template_name)
context['activity'] = activity
if django.VERSION < (1, 11):
context = Context(context)
elif isinstance(context, Context):
context = context.flatten()
return tmpl.render(context)
示例15: create_parser
# 需要導入模塊: import django [as 別名]
# 或者: from django import VERSION [as 別名]
def create_parser(self, progname, subcommand):
"""
Called when run through `call_command`.
"""
if DJANGO_VERSION >= (1, 10):
return ArgumentParserAdapter()
else: # NOCOV
return OptionParseAdapter()