當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。