当前位置: 首页>>代码示例>>Python>>正文


Python django.VERSION属性代码示例

本文整理汇总了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) 
开发者ID:LuciferJack,项目名称:python-mysql-pool,代码行数:20,代码来源:creation.py

示例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) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:24,代码来源:version.py

示例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') 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:19,代码来源:version.py

示例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) 
开发者ID:plumdog,项目名称:django_migration_testcase,代码行数:24,代码来源:tests.py

示例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 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:24,代码来源:version.py

示例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') 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:21,代码来源:version.py

示例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)] 
开发者ID:tarkatronic,项目名称:django-excel-response,代码行数:27,代码来源:response.py

示例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) 
开发者ID:arteria,项目名称:django-compat,代码行数:25,代码来源:test_compat.py

示例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) 
开发者ID:arteria,项目名称:django-compat,代码行数:24,代码来源:test_compat.py

示例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) 
开发者ID:jp74,项目名称:django-model-publisher,代码行数:20,代码来源:admin.py

示例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) 
开发者ID:jp74,项目名称:django-model-publisher,代码行数:21,代码来源:admin.py

示例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__) 
开发者ID:edoburu,项目名称:sphinxcontrib-django,代码行数:21,代码来源:docstrings.py

示例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",
            ],
        ) 
开发者ID:edoburu,项目名称:sphinxcontrib-django,代码行数:18,代码来源:test_docstrings.py

示例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) 
开发者ID:GetStream,项目名称:stream-django,代码行数:24,代码来源:activity_tags.py

示例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() 
开发者ID:GaretJax,项目名称:django-click,代码行数:10,代码来源:adapter.py


注:本文中的django.VERSION属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。