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


Python functions.Lower方法代码示例

本文整理汇总了Python中django.db.models.functions.Lower方法的典型用法代码示例。如果您正苦于以下问题:Python functions.Lower方法的具体用法?Python functions.Lower怎么用?Python functions.Lower使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.models.functions的用法示例。


在下文中一共展示了functions.Lower方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: team_listing

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Lower [as 别名]
def team_listing(request):
    """Return a listing of teams visible to the user."""
    team_list = Team.objects.user_visible(request.user).order_by(Lower('name'))
    desc = _('List of teams on {name} and summary information').format(name=get_current_site(request).name)  # nopep8

    user_teams = set()
    user_invites = set()
    user_pending = set()
    user_owns = set()

    if request.user.is_authenticated:
        user_invites = set(TeamRequest.objects.filter(invitee=request.user, inviter__isnull=False).values_list('team', flat=True))
        user_pending = set(TeamRequest.objects.filter(invitee=request.user, inviter__isnull=True).values_list('team', flat=True))
        user_teams = set(request.user.team_set.values_list('id', flat=True))
        user_owns = set(Team.objects.filter(owner=request.user).values_list('id', flat=True))

    return render(request, 'teams/teams.html', {
        'teams': make_paginator(request, team_list),
        'meta_description': desc,
        'user_teams': user_teams,
        'user_invites': user_invites,
        'user_pending': user_pending,
        'user_owns': user_owns,
    }) 
开发者ID:twschiller,项目名称:open-synthesis,代码行数:26,代码来源:teams.py

示例2: clean_domain_name

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Lower [as 别名]
def clean_domain_name(field_name):
    """
    Returns a Django query expression that replaces all underscores with a
    hyphen, removes leading and trailing hyphens, and converts the field to
    lower case.
    """
    remove_underscores = Func(
        F(field_name),
        Value('_'),
        Value('-'),
        function='replace'
    )
    trim_hyphens = Func(
        remove_underscores,
        Value('-'),
        function='btrim',
    )
    remove_trailing_hyphens = Func(
        trim_hyphens,
        Value(r'[-]+\.'),
        Value('.'),
        Value('g'),
        function='regexp_replace'
    )
    return Lower(remove_trailing_hyphens) 
开发者ID:open-craft,项目名称:opencraft,代码行数:27,代码来源:0007_fix_invalid_domain_names.py

示例3: alphabetize

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Lower [as 别名]
def alphabetize(order, fields):
    """Returns the correct sort order

    :param order: The list of ordering
    :type order: list
    :param fields: The list of fields to alphabetize
    :type fields: list
    """

    ordering = []
    for o in order:
        if o in fields:
            # Check for descending first (prepended with a -)
            if o[0] == '-':
                ordering.append(Lower(o[1:]).desc())
            else:
                ordering.append(Lower(o))
        else:
            ordering.append(o)

    return ordering 
开发者ID:ngageoint,项目名称:scale,代码行数:23,代码来源:database.py

示例4: get_queryset

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Lower [as 别名]
def get_queryset(self):
        event = Event.objects.get(slug=self.kwargs.get('slug'))
        queryset = Ticket.objects.filter(type__event=event).order_by(Lower('last_name'), Lower('first_name'))

        search = self.request.GET.get('search')
        if search:
            queryset = queryset.filter(
                Q(first_name__icontains=search) |
                Q(last_name__icontains=search) |
                Q(email__icontains=search)
            )

        registered_only = self.request.GET.get('registered_only')
        if registered_only:
            queryset = queryset.filter(status=Ticket.REGISTERED)

        return queryset 
开发者ID:pyconsk,项目名称:django-konfera,代码行数:19,代码来源:views.py

示例5: get_ordering

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Lower [as 别名]
def get_ordering(self, request, queryset):
        ordering = super().get_ordering(request, queryset)
        for i in range(len(ordering)):
            desc = False
            fieldname = ordering[i]
            if fieldname.startswith("-"):
                fieldname = fieldname[1:]
                desc = True

            try:
                field = queryset.model()._meta.get_field(
                    "id" if fieldname == "pk" else fieldname
                )
            except FieldDoesNotExist:
                continue

            f_type = field.db_type(connection)
            if f_type != "text":
                continue

            if desc:
                ordering[i] = Lower(fieldname).desc()
            else:
                ordering[i] = Lower(fieldname)
        return ordering 
开发者ID:propublica,项目名称:django-collaborative,代码行数:27,代码来源:admin.py

示例6: test_basic

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Lower [as 别名]
def test_basic(self):
        Author.objects.create(name='John Smith', alias='smithj')
        Author.objects.create(name='Rhonda')
        authors = Author.objects.annotate(name_part=Substr('name', 5, 3))
        self.assertQuerysetEqual(
            authors.order_by('name'), [' Sm', 'da'],
            lambda a: a.name_part
        )
        authors = Author.objects.annotate(name_part=Substr('name', 2))
        self.assertQuerysetEqual(
            authors.order_by('name'), ['ohn Smith', 'honda'],
            lambda a: a.name_part
        )
        # If alias is null, set to first 5 lower characters of the name.
        Author.objects.filter(alias__isnull=True).update(
            alias=Lower(Substr('name', 1, 5)),
        )
        self.assertQuerysetEqual(
            authors.order_by('name'), ['smithj', 'rhond'],
            lambda a: a.alias
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:23,代码来源:test_substr.py

示例7: test_basic

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Lower [as 别名]
def test_basic(self):
        Author.objects.create(name='John Smith', alias='smithj')
        Author.objects.create(name='Rhonda')
        authors = Author.objects.annotate(lower_name=Lower('name'))
        self.assertQuerysetEqual(
            authors.order_by('name'), ['john smith', 'rhonda'],
            lambda a: a.lower_name
        )
        Author.objects.update(name=Lower('name'))
        self.assertQuerysetEqual(
            authors.order_by('name'), [
                ('john smith', 'john smith'),
                ('rhonda', 'rhonda'),
            ],
            lambda a: (a.lower_name, a.name)
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:18,代码来源:test_lower.py

示例8: team_members

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Lower [as 别名]
def team_members(request, team_id):
    """Return a listing of members for the given team."""
    team = get_object_or_404(Team, pk=team_id)

    is_member, pending_invitation = member_status(request.user, team)

    if not is_member and not team.public and not pending_invitation:
        raise PermissionDenied()

    return render(request, 'teams/members.html', {
        'team': team,
        'members': make_paginator(request, team.members.order_by(Lower('username'))),
        'is_owner': team.owner == request.user,
    }) 
开发者ID:twschiller,项目名称:open-synthesis,代码行数:16,代码来源:teams.py

示例9: __init__

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Lower [as 别名]
def __init__(self, *args, user=None, **kwargs):
        super().__init__(*args, **kwargs)

        # NOTE: a user who doesn't have access to a team can see the team name here if it's already a collaborator
        # on the board. In the future, might want to hide those team names here
        team_ids = set(Team.objects.user_visible(user=user).values_list('id', flat=True)) | set(kwargs['instance'].teams.values_list('id', flat=True))
        self.fields['teams'].queryset = Team.objects.filter(id__in=team_ids).order_by(Lower('name'))
        self.fields['collaborators'].queryset = User.objects.all().order_by(Lower('username'))
        self.fields['collaborators'].label = _('User Collaborators')
        self.fields['teams'].label = _('Team Collaborators') 
开发者ID:twschiller,项目名称:open-synthesis,代码行数:12,代码来源:forms.py

示例10: clean_email

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Lower [as 别名]
def clean_email(self):
        """
        Ensure that the email address provided is unique (in a case-insensitive manner).
        """
        email_value = self.cleaned_data['email']
        if not email_value:
            raise ValidationError(_("Enter a valid email address."))
        invalid_email = '{}{}'.format(settings.INVALID_PREFIX, email_value)
        emails_lookup = Q(email_lc=email_value.lower()) | Q(email_lc=invalid_email.lower())
        if email_value and email_value.lower() != self.previous_email.lower() \
                and User.objects.annotate(email_lc=Lower('email')).filter(emails_lookup).exists():
            raise ValidationError(_("User address already in use."))
        return email_value 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:15,代码来源:mixins.py

示例11: init_from_get_params

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Lower [as 别名]
def init_from_get_params(self, get_params: QueryDict) -> bool:
        tags = {tag.lower() for tag in get_params.getlist(self.GET_TAG_SEARCH)}
        self.tags = Tag.objects.annotate(name_lower=Lower('name')).filter(name_lower__in=tags)
        return bool(self.tags) 
开发者ID:Palanaeum,项目名称:palanaeum,代码行数:6,代码来源:search.py

示例12: test_list

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Lower [as 别名]
def test_list(self):
        """ Verify the endpoint returns a list of all courses. """
        url = reverse('api:v1:course-list')

        with self.assertNumQueries(25):
            response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertListEqual(
            response.data['results'],
            self.serialize_course(Course.objects.all().order_by(Lower('key')), many=True)
        ) 
开发者ID:edx,项目名称:course-discovery,代码行数:13,代码来源:test_courses.py

示例13: test_list

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Lower [as 别名]
def test_list(self):
        """ Verify the endpoint returns a list of all course runs. """
        url = reverse('api:v1:course_run-list')

        with self.assertNumQueries(13):
            response = self.client.get(url)

        assert response.status_code == 200
        self.assertListEqual(
            response.data['results'],
            self.serialize_course_run(CourseRun.objects.all().order_by(Lower('key')), many=True)
        ) 
开发者ID:edx,项目名称:course-discovery,代码行数:14,代码来源:test_course_runs.py

示例14: get_queryset

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Lower [as 别名]
def get_queryset(self):
        return super(SiteManager, self).get_queryset().order_by(Lower("hostname")) 
开发者ID:wagtail,项目名称:wagtail,代码行数:4,代码来源:models.py

示例15: make_usernames_lower

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Lower [as 别名]
def make_usernames_lower(apps, schema_editor):
    from django.db.models.functions import Lower
    from django.db.models import Count
    from ...core.conf import settings
    User = apps.get_model(settings.AUTH_USER_MODEL)

    if settings.ST_CASE_INSENSITIVE_USERNAMES:
        try:
            with transaction.atomic():
                User.objects.all().update(
                    username=Lower('username'))
        except IntegrityError:
            # Show all duplicated usernames
            users_lower = (
                User.objects
                .annotate(username_lower=Lower('username'))
                .values('username_lower')
                .annotate(cnt=Count(Lower('username')))
                .values('username_lower', 'cnt')
                .filter(cnt__gt=1)
                .order_by('username_lower', 'cnt'))
            users = [
                u.username
                for u in (
                    User.objects
                    .annotate(username_lower=Lower('username'))
                    .filter(username_lower__in=[
                        u['username_lower'] for u in users_lower]))]
            raise IntegrityError(
                'There are two or more users with '
                'similar name but different casing, for example: '
                'someUser and SomeUser, either remove one of them '
                'or set the `ST_CASE_INSENSITIVE_USERNAMES` setting '
                'to False. Then run the upgrade/migration again. '
                'Any change was reverted. Duplicate users are {}'.format(users)) 
开发者ID:nitely,项目名称:Spirit,代码行数:37,代码来源:0011_auto_20181124_2320.py


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