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


Python User.get_or_create_inactive方法代码示例

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


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

示例1: lookup_users_by_phone

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create_inactive [as 别名]
def lookup_users_by_phone(phone_number):
    """Attempt to match the given phone number in an arbitrary format to one or more members"""
    phone_number = re.sub('\s', '', phone_number)
    if phone_number == '':
        return []

    # Perform raw query in order to use MSSQL's 'REPLACE' function to remove whitespace
    # Note that we're excluding Actors with end_code 'dublett' manually here
    actors = Actor.objects.raw(
        "select * from Actor where REPLACE(MobPh, ' ', '') = %s AND EndCd != %s;",
        [phone_number, ACTOR_ENDCODE_DUBLETT]
    )

    # Filter on personal members; we're never handling other membership types
    actors = [actor for actor in actors if actor.is_personal_member()]

    # Perform raw query in order to use MSSQL's 'REPLACE' function to remove whitespace
    # Note that we're excluding inactive Enrollments manually (like Enrollment.get_active() would have) here
    query = 'select * from %s where (("Paymethod" = %s or "Paymethod" = %s ) and ' \
            '"SubmittedDt" is null and REPLACE(Mob, \' \', \'\') = %s );' % (
                Enrollment._meta.db_table, '%s', '%s', '%s',
            )
    params = [PAYMENT_METHOD_CODES['card'], PAYMENT_METHOD_CODES['invoice'], phone_number]
    pending_actors = Enrollment.objects.raw(query, params)

    # Convert the matching actors to users
    users = [User.get_or_create_inactive(memberid=actor.memberid) for actor in actors]
    users += [User.get_or_create_inactive(memberid=actor.memberid) for actor in pending_actors]
    return users
开发者ID:Turistforeningen,项目名称:sherpa,代码行数:31,代码来源:util.py

示例2: verify_memberid

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create_inactive [as 别名]
def verify_memberid(ip_address, memberid, country_code, zipcode):
    """
    Returns a User object matching the given memberid, country code, and if
    Norwegian; also zipcode. Includes pending users by default. Raises a range
    of exceptions if the provided data is invalid or does not match any user:
    - MemberidLookupsExceeded: If the client IP address has performed more
      lookups than we allowed
    - CountryDoesNotExist: If the given country code is invalid
    - ActorIsNotPersonalMember: If the data matches an Actor in Focus who
      isn't a personal member
    - NoMatchingMemberid: If the data doesn't match any member
    """
    # Check that the memberid is correct (and retrieve the Actor-entry)
    if memberid_lookups_exceeded(ip_address):
        raise MemberidLookupsExceeded

    if not FocusCountry.objects.filter(code=country_code).exists():
        raise CountryDoesNotExist

    # Not filtering on Actor.get_personal_members() in order to raise explicit
    # exception for non-personal-membership matches; see below
    actor = Actor.objects.filter(
        memberid=memberid,
        address__country_code=country_code
    )

    # Require correct zipcode for domestic members
    if country_code == 'NO':
        actor = actor.filter(address__zipcode=zipcode)

    if actor.exists():
        actor = actor.get()

        # Check that it's a proper member object (note that we didn't filter
        # the query on Actor.get_personal_members())
        if not actor.is_personal_member():
            raise ActorIsNotPersonalMember

        return User.get_or_create_inactive(memberid=actor.memberid)

    # No matching actors, check for pending users
    enrollment = Enrollment.get_active().filter(memberid=memberid)

    # Require correct zipcode for domestic members
    if country_code == 'NO':
        enrollment = enrollment.filter(zipcode=zipcode)

    if enrollment.exists():
        return User.get_or_create_inactive(memberid=memberid)

    # No matches
    raise NoMatchingMemberid
开发者ID:Turistforeningen,项目名称:sherpa,代码行数:54,代码来源:util.py

示例3: confirm_membership_by_token

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create_inactive [as 别名]
def confirm_membership_by_token(request):
    """
    Confirm the membership with only the given token as authentication. Note that the URL to this view is hardcoded in
    Focus which sends out emails/SMS with the URL and correct token.
    """
    try:
        token = request.GET['code']
        actor = Actor.objects.get(family_youth_member_accepted_token=token)
        youth_user = User.get_or_create_inactive(memberid=actor.memberid)
        context = {
            'token': token,
            'youth_user': youth_user,
        }
    except (KeyError, Actor.DoesNotExist):
        raise Http404

    if request.method == 'GET':
        return render(request, 'common/user/membership_confirmation.html', context)
    elif request.method == 'POST':
        try:
            User.confirm_membership_by_token(token)
            librato.increment('sherpa.medlemmer.familiemedlemskap.bekreft_ungdomsmedlem')
            return redirect('%s?code=%s' % (reverse('user:confirm_membership_by_token'), token))
        except:
            context['confirmation_error'] = True
            return render(request, 'common/user/membership_confirmation.html', context)
开发者ID:,项目名称:,代码行数:28,代码来源:

示例4: members

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create_inactive [as 别名]
def members(request, version, format):
    if request.method == 'GET':
        require_focus(request)

        try:
            if 'sherpa_id' in request.GET and 'medlemsnummer' in request.GET:
                user = User.get_users(include_pending=True).get(id=request.GET['sherpa_id'], memberid=request.GET['medlemsnummer'])
            elif 'sherpa_id' in request.GET:
                user = User.get_users(include_pending=True).get(id=request.GET['sherpa_id'])
            elif 'medlemsnummer' in request.GET:
                try:
                    user = User.get_or_create_inactive(memberid=request.GET['medlemsnummer'], include_pending=True)
                except (Enrollment.DoesNotExist, ValueError):
                    # No such member
                    raise User.DoesNotExist
            else:
                raise BadRequest(
                    u"You must supply either an 'sherpa_id' or 'medlemsnummer' parameter for member lookup",
                    code=error_codes.MISSING_REQUIRED_PARAMETER,
                    http_code=400
                )
            return HttpResponse(json.dumps(get_member_data(user)))
        except (User.DoesNotExist, ValueError):
            raise BadRequest(
                u"A member matching that 'sherpa_id', 'medlemsnummer', or both if both were provided, does not exist.",
                code=error_codes.RESOURCE_NOT_FOUND,
                http_code=404
            )
    else:
        raise BadRequest(
            u"Unsupported HTTP verb",
            code=error_codes.UNSUPPORTED_HTTP_VERB,
            http_code=400
        )
开发者ID:simensma,项目名称:sherpa,代码行数:36,代码来源:api.py

示例5: validate_existing

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create_inactive [as 别名]
    def validate_existing(self):
        try:
            user = ExistingUser.get_or_create_inactive(memberid=self.existing_memberid)
        except (ExistingUser.DoesNotExist, ValueError):
            return False

        if not user.payment.status['is_paid']:
            return False

        if user.get_dnt_age() < settings.MEMBERSHIP['AGES']['YOUTH']:
            return False

        if user.is_related_member():
            return False

        if user.has_membership_type('family_primary'):
            return False

        if user.address.country.code != self.country:
            return False

        if self.country == 'NO' and user.address.zipcode.zipcode != self.zipcode:
            return False

        return True
开发者ID:Turistforeningen,项目名称:sherpa,代码行数:27,代码来源:models.py

示例6: get_children

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create_inactive [as 别名]
    def get_children(self):
        from user.models import User

        children = cache.get('actor.%s.children' % self.actor.memberid)
        if children is None:
            actor_children = Actor.get_personal_members().filter(parent=self.actor.memberid).exclude(id=self.actor.id)
            children = [
                User.get_or_create_inactive(memberid=actor_child.memberid)
                for actor_child in actor_children
            ]
            cache.set('actor.%s.children' % self.actor.memberid, children, settings.FOCUS_MEMBER_CACHE_PERIOD)
        return children
开发者ID:Turistforeningen,项目名称:sherpa,代码行数:14,代码来源:member.py

示例7: get_parent

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create_inactive [as 别名]
    def get_parent(self):
        """Returns the parent pending member of this pending member, or None if it has no parent"""
        from user.models import User

        parent_memberid = self.enrollment.get_parent_memberid()
        if parent_memberid is None:
            return None

        try:
            return User.get_or_create_inactive(memberid=parent_memberid)
        except User.DoesNotExist:
            # Entirely possible that this member is connected to a parent which isn't active. Ignore it
            return None
开发者ID:Turistforeningen,项目名称:sherpa,代码行数:15,代码来源:pending_member.py

示例8: membership_fee

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create_inactive [as 别名]
def membership_fee(request, memberid):
    librato.increment('sherpa.api.tailored.medlemskontingent.request')
    try:
        user = User.get_or_create_inactive(memberid)
        response = json.dumps({
            'id': user.id,
            'hasPaid': user.payment.status['is_paid'],
        })
        librato.increment('sherpa.api.tailored.medlemskontingent.response.200')
        return HttpResponse(response, content_type="application/json")
    except (User.DoesNotExist, ValueError):
        librato.increment('sherpa.api.tailored.medlemskontingent.response.404')
        raise Http404
开发者ID:Turistforeningen,项目名称:sherpa,代码行数:15,代码来源:resources_tailored.py

示例9: lookup_users_by_phone

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create_inactive [as 别名]
def lookup_users_by_phone(phone_number):
    """Attempt to match the given phone number in an arbitrary format to one or more members"""
    phone_number = re.sub('\s', '', phone_number)
    if phone_number == '':
        return []

    # Note that we're excluding Actors with end_code 'dublett' manually here
    actors = Actor.objects.raw(
        "select * from Actor where REPLACE(MobPh, ' ', '') = %s AND EndCd != %s;",
        [phone_number, ACTOR_ENDCODE_DUBLETT]
    )

    # Convert the matching actors to users. Filter on personal members; we're never handling other membership types
    return [User.get_or_create_inactive(memberid=actor.memberid) for actor in actors if actor.is_personal_member()]
开发者ID:simensma,项目名称:sherpa,代码行数:16,代码来源:util.py

示例10: get_children

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create_inactive [as 别名]
    def get_children(self):
        from user.models import User

        # Only look for children among other pending users. There could theoretically be children that are proper
        # members, but in most such cases the current pending member would also have been accepted, so don't handle it.
        enrollment_children = Enrollment.get_active().filter(
            parent=self.enrollment.memberid,
        ).exclude(
            pk=self.enrollment.pk,
        )
        return [
            User.get_or_create_inactive(memberid=enrollment_child.memberid)
            for enrollment_child in enrollment_children
        ]
开发者ID:Turistforeningen,项目名称:sherpa,代码行数:16,代码来源:pending_member.py

示例11: contact_person_search

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create_inactive [as 别名]
def contact_person_search(request, forening_id):
    current_forening = Forening.objects.get(id=forening_id)
    if current_forening not in request.user.all_foreninger():
        raise PermissionDenied

    MAX_HITS = 100

    if len(request.POST['q']) < settings.ADMIN_USER_SEARCH_CHAR_LENGTH:
        raise PermissionDenied

    local_nonmember_users = User.get_users().filter(memberid__isnull=True)
    for word in request.POST['q'].split():
        local_nonmember_users = local_nonmember_users.filter(
            Q(first_name__icontains=word) |
            Q(last_name__icontains=word)
        )
    local_nonmember_users = local_nonmember_users.order_by('first_name')

    actors = Actor.get_personal_members()
    for word in request.POST['q'].split():
        actors = actors.filter(
            Q(first_name__icontains=word) |
            Q(last_name__icontains=word) |
            Q(memberid__icontains=word)
        )
    actors = actors.order_by('first_name')

    # Get (or create) the user objects for the first MAX_HITS actor-hits
    users = [
        User.get_or_create_inactive(a.memberid)
        for a in actors[:MAX_HITS]]

    # Merge with non-members
    users = sorted(
        list(users) + list(local_nonmember_users),
        key=lambda u: u.get_full_name())

    context = {
        'current_forening': current_forening,
        'users': users[:MAX_HITS],
    }
    return HttpResponse(json.dumps({
        'results': render_to_string(
            'central/admin/foreninger/contact_person_search_results.html',
            context,
            request=request,
        ),
        'max_hits_exceeded': len(users) > MAX_HITS or len(actors) > MAX_HITS
    }))
开发者ID:Turistforeningen,项目名称:sherpa,代码行数:51,代码来源:views.py

示例12: get_parent

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create_inactive [as 别名]
 def get_parent(self):
     from user.models import User
     parent = cache.get('focus.enrollment.%s.parent' % self.enrollment.memberid)
     if parent is None:
         parent_memberid = self.get_parent_memberid()
         if parent_memberid is not None:
             try:
                 parent = User.get_or_create_inactive(memberid=parent_memberid, include_pending=True)
             except Enrollment.DoesNotExist:
                 # Entirely possible that this member is connected to a parent which isn't active. Ignore it
                 parent = None
         else:
             parent = None
         cache.set('focus.enrollment.%s.parent' % self.enrollment.memberid, parent, settings.FOCUS_MEMBER_CACHE_PERIOD)
     return parent
开发者ID:simensma,项目名称:sherpa,代码行数:17,代码来源:abstractions.py

示例13: get_parent

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create_inactive [as 别名]
    def get_parent(self):
        """Returns the parent of this member, or None if it has no parent"""
        from user.models import User

        if not self.is_related_member():
            return None

        # Most household members should have a parent, but some don't. Some of these are lifelong household members
        # (this membership type is now deprecated) who have lost their spouce, and memberservice has decided to keep
        # them as household members, with no parent.
        # They must be separated from main lifelong members because they're *not* entitled to receive Fjell og Vidde
        # or årboken.
        parent_memberid = self.actor.get_parent_memberid()
        if parent_memberid is None:
            return None

        return User.get_or_create_inactive(memberid=parent_memberid)
开发者ID:Turistforeningen,项目名称:sherpa,代码行数:19,代码来源:member.py

示例14: forening

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create_inactive [as 别名]
def forening(request, version, format):
    if request.method == 'GET':
        require_focus(request)
        librato.increment('sherpa.api.tailored.forening.request')

        if 'bruker_sherpa_id' in request.GET or 'bruker_medlemsnummer' in request.GET:
            try:
                # Lookup by specified members' access
                if 'bruker_sherpa_id' in request.GET and 'bruker_medlemsnummer' in request.GET:
                    user = User.get_users(include_pending=True).get(id=request.GET['bruker_sherpa_id'], memberid=request.GET['bruker_medlemsnummer'])
                elif 'bruker_sherpa_id' in request.GET:
                    user = User.get_users(include_pending=True).get(id=request.GET['bruker_sherpa_id'])
                elif 'bruker_medlemsnummer' in request.GET:
                    try:
                        user = User.get_or_create_inactive(memberid=request.GET['bruker_medlemsnummer'])
                    except (User.DoesNotExist, ValueError):
                        # No such member
                        raise User.DoesNotExist

                foreninger = [get_forening_data(f) for f in user.all_foreninger()]
                librato.increment('sherpa.api.tailored.forening.response.200')
                return HttpResponse(json.dumps(foreninger))

            except (User.DoesNotExist, ValueError):
                librato.increment('sherpa.api.tailored.forening.response.404')
                raise BadRequest(
                    "A member matching that 'sherpa_id', 'bruker_medlemsnummer', or both if both were provided, does not exist.",
                    code=error_codes.RESOURCE_NOT_FOUND,
                    http_code=404
                )
        else:
            librato.increment('sherpa.api.tailored.forening.response.400')
            raise BadRequest(
                "You must supply either a 'bruker_sherpa_id' or 'bruker_medlemsnummer' parameter for forening lookup by member. Only this form of forening-lookup is implemented in this version.",
                code=error_codes.MISSING_REQUIRED_PARAMETER,
                http_code=400
            )
    else:
        librato.increment('sherpa.api.tailored.forening.response.400')
        raise BadRequest(
            "Unsupported HTTP verb",
            code=error_codes.UNSUPPORTED_HTTP_VERB,
            http_code=400
        )
开发者ID:Turistforeningen,项目名称:sherpa,代码行数:46,代码来源:resources_tailored.py

示例15: existing

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create_inactive [as 别名]
def existing(request):
    if not request.is_ajax():
        return redirect('enrollment:household')

    # Note: This logic is duplicated in validate_existing()
    data = json.loads(request.POST['data'])
    if data['country'] == 'NO' and len(data['zipcode']) != 4:
        return HttpResponse(json.dumps({'error': 'bad_zipcode'}))
    try:
        user = User.get_or_create_inactive(memberid=data['id'])
    except User.DoesNotExist:
        return HttpResponse(json.dumps({'error': 'does_not_exist'}))
    except ValueError:
        return HttpResponse(json.dumps({'error': 'invalid_id'}))

    country_matches = user.address.country.code == data['country']

    # Match both country and zipcode for norwegian members, only country for foreign members
    if data['country'] == 'NO':
        valid = country_matches and user.address.zipcode.zipcode == data['zipcode']
    else:
        valid = country_matches
    if not valid:
        return HttpResponse(json.dumps({'error': 'invalid_address'}))

    if not user.payment.status['is_paid']:
        return HttpResponse(json.dumps({'error': 'has_not_paid'}))

    if user.get_dnt_age() < settings.MEMBERSHIP['AGES']['YOUTH']:
        return HttpResponse(json.dumps({'error': 'too_young', 'age': user.get_dnt_age()}))

    if user.is_related_member():
        return HttpResponse(json.dumps({'error': 'is_related_member'}))

    if user.has_membership_type('family_primary'):
        return HttpResponse(json.dumps({'error': 'is_family_member'}))

    return HttpResponse(json.dumps({
        'name': user.get_full_name(),
        'address': user.address.format_for_oneline(),
    }))
开发者ID:Turistforeningen,项目名称:sherpa,代码行数:43,代码来源:views.py


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