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


Python helpers.redirect函数代码示例

本文整理汇总了Python中mozillians.common.helpers.redirect函数的典型用法代码示例。如果您正苦于以下问题:Python redirect函数的具体用法?Python redirect怎么用?Python redirect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: form_valid

    def form_valid(self, form):
        """Custom form validation to support email changing.

        If user is already authenticated and reaches this points, it's
        an email changing procedure. Validate that email is good and
        save it in the database.

        Otherwise continue with the default django-browserid verification.
        """
        if not self.request.user.is_authenticated():
            return super(BrowserIDVerify, self).form_valid(form)

        failure_url = urlparams(reverse('phonebook:profile_edit'), bid_login_failed=1)
        self.assertion = form.cleaned_data['assertion']
        self.audience = get_audience(self.request)
        result = verify(self.assertion, self.audience)
        if not result:
            messages.error(self.request, _('Authentication failed.'))
            return redirect(failure_url)

        email = result['email']

        if User.objects.filter(email=email).exists():
            messages.error(self.request, _('Email already exists in the database.'))
            return redirect('phonebook:logout')

        user = self.request.user
        user.email = email
        user.save()
        return redirect('phonebook:profile_view', user.username)
开发者ID:Ppchiu,项目名称:mozillians,代码行数:30,代码来源:views.py

示例2: change_primary_email

def change_primary_email(request, email_pk):
    """Change primary email address."""
    user = User.objects.get(pk=request.user.id)
    profile = user.userprofile
    alternate_emails = ExternalAccount.objects.filter(user=profile,
                                                      type=ExternalAccount.TYPE_EMAIL)

    # Only email owner can change primary email
    if not alternate_emails.filter(pk=email_pk).exists():
        raise Http404()

    alternate_email = alternate_emails.get(pk=email_pk)
    primary_email = user.email

    # Change primary email
    user.email = alternate_email.identifier

    # Turn primary email to alternate
    alternate_email.identifier = primary_email

    with transaction.atomic():
        user.save()
        alternate_email.save()

    return redirect('phonebook:profile_edit')
开发者ID:eckeman,项目名称:mozillians,代码行数:25,代码来源:views.py

示例3: invite

def invite(request):
    profile = request.user.userprofile
    invite_form = None
    vouch_form = None
    if profile.can_vouch:
        invite_form = forms.InviteForm(request.POST or None,
                                       instance=Invite(inviter=profile))
        vouch_form = forms.VouchForm(request.POST or None)

    if invite_form and vouch_form and invite_form.is_valid() and vouch_form.is_valid():
        invite_form.instance.reason = vouch_form.cleaned_data['description']
        invite = invite_form.save()
        invite.send(sender=profile, personal_message=invite_form.cleaned_data['message'])
        msg = _(u"%s has been invited to Mozillians. They'll receive an email "
                u"with instructions on how to join. You can "
                u"invite another Mozillian if you like.") % invite.recipient
        messages.success(request, msg)
        return redirect('phonebook:invite')

    return render(request, 'phonebook/invite.html',
                  {
                      'invite_form': invite_form,
                      'vouch_form': vouch_form,
                      'invites': profile.invites.all(),
                      'vouch_threshold': settings.CAN_VOUCH_THRESHOLD,
                  })
开发者ID:maheshkkumar,项目名称:mozillians,代码行数:26,代码来源:views.py

示例4: edit_profile

def edit_profile(request):
    """Edit user profile view."""
    # Don't user request.user
    user = User.objects.get(pk=request.user.id)
    profile = user.userprofile
    user_groups = stringify_groups(profile.groups.all().order_by('name'))
    user_skills = stringify_groups(profile.skills.all().order_by('name'))
    user_languages = stringify_groups(profile.languages.all().order_by('name'))

    user_form = forms.UserForm(request.POST or None, instance=user)
    AccountsFormset = inlineformset_factory(UserProfile, ExternalAccount, extra=1)
    accounts_formset = AccountsFormset(request.POST or None, instance=profile)
    new_profile = False
    form = forms.ProfileForm
    if not profile.is_complete:
        new_profile = True
        form = forms.RegisterForm

    profile_form = form(request.POST or None, request.FILES or None,
                        instance=profile, locale=request.locale,
                        initial=dict(groups=user_groups, skills=user_skills,
                                     languages=user_languages))

    email_form = forms.EmailForm(request.POST or None,
                                 initial={'email': request.user.email,
                                          'user_id': request.user.id})

    if (user_form.is_valid() and profile_form.is_valid() and accounts_formset.is_valid() and
        email_form.is_valid()):
        old_username = request.user.username
        user_form.save()
        profile_form.save()
        accounts_formset.save()

        # Notify the user that their old profile URL won't work.
        if new_profile:
            update_invites(request)
            messages.info(request, _(u'Your account has been created.'))
        elif user.username != old_username:
            messages.info(request,
                          _(u'You changed your username; please note your '
                            'profile URL has also changed.'))

        if email_form.email_changed():
            return render(request, 'phonebook/verify_email.html',
                          {'email': email_form.cleaned_data['email']})
        return redirect('phonebook:profile_view', user.username)

    data = dict(profile_form=profile_form,
                user_form=user_form,
                accounts_formset = accounts_formset,
                email_form = email_form,
                user_groups=user_groups,
                my_vouches=UserProfile.objects.filter(vouched_by=profile),
                profile=request.user.userprofile,
                apps=user.apiapp_set.filter(is_active=True))

    # If there are form errors, don't send a 200 OK.
    status = 400 if (profile_form.errors or user_form.errors) else 200
    return render(request, 'phonebook/edit_profile.html', data, status=status)
开发者ID:flodolo,项目名称:mozillians,代码行数:60,代码来源:views.py

示例5: view_profile

def view_profile(request, username):
    """View a profile by username."""
    data = {}
    privacy_mappings = {'anonymous': PUBLIC, 'mozillian': MOZILLIANS, 'employee': EMPLOYEES,
                        'privileged': PRIVILEGED, 'myself': None}
    privacy_level = None

    if (request.user.is_authenticated() and request.user.username == username):
        # own profile
        view_as = request.GET.get('view_as', 'myself')
        privacy_level = privacy_mappings.get(view_as, None)
        profile = UserProfile.objects.privacy_level(privacy_level).get(user__username=username)
        data['privacy_mode'] = view_as
    else:
        userprofile_query = UserProfile.objects.filter(user__username=username)
        public_profile_exists = userprofile_query.public().exists()
        profile_exists = userprofile_query.exists()
        profile_complete = userprofile_query.exclude(full_name='').exists()

        if not public_profile_exists:
            if not request.user.is_authenticated():
                # you have to be authenticated to continue
                messages.warning(request, LOGIN_MESSAGE)
                return (login_required(view_profile, login_url=reverse('phonebook:home'))
                        (request, username))

            if not request.user.userprofile.is_vouched:
                # you have to be vouched to continue
                messages.error(request, GET_VOUCHED_MESSAGE)
                return redirect('phonebook:home')

        if not profile_exists or not profile_complete:
            raise Http404

        profile = UserProfile.objects.get(user__username=username)
        profile.set_instance_privacy_level(PUBLIC)
        if request.user.is_authenticated():
            profile.set_instance_privacy_level(
                request.user.userprofile.privacy_level)

        if (not profile.is_vouched
            and request.user.is_authenticated()
            and request.user.userprofile.is_vouched):
                data['vouch_form'] = (
                    forms.VouchForm(initial={'vouchee': profile.pk}))

    data['shown_user'] = profile.user
    data['profile'] = profile
    data['groups'] = profile.get_annotated_groups()
    data['locale'] = request.locale

    # Only show pending groups if user is looking at their own profile,
    # or current user is a superuser
    if not (request.user.is_authenticated()
            and (request.user.username == username or request.user.is_superuser)):
        data['groups'] = [grp for grp in data['groups'] if not grp.pending]

    return render(request, 'phonebook/profile.html', data)
开发者ID:agbiyani,项目名称:mozillians,代码行数:58,代码来源:views.py

示例6: view_profile

def view_profile(request, username):
    """View a profile by username."""
    data = {}
    privacy_mappings = {
        "anonymous": PUBLIC,
        "mozillian": MOZILLIANS,
        "employee": EMPLOYEES,
        "privileged": PRIVILEGED,
        "myself": None,
    }
    privacy_level = None

    if request.user.is_authenticated() and request.user.username == username:
        # own profile
        view_as = request.GET.get("view_as", "myself")
        privacy_level = privacy_mappings.get(view_as, None)
        profile = UserProfile.objects.privacy_level(privacy_level).get(user__username=username)
        data["privacy_mode"] = view_as
    else:
        userprofile_query = UserProfile.objects.filter(user__username=username)
        public_profile_exists = userprofile_query.public().exists()
        profile_exists = userprofile_query.exists()
        profile_complete = userprofile_query.exclude(full_name="").exists()

        if not public_profile_exists:
            if not request.user.is_authenticated():
                # you have to be authenticated to continue
                messages.warning(request, LOGIN_MESSAGE)
                return login_required(view_profile, login_url=reverse("phonebook:home"))(request, username)

            if not request.user.userprofile.is_vouched:
                # you have to be vouched to continue
                messages.error(request, GET_VOUCHED_MESSAGE)
                return redirect("phonebook:home")

        if not profile_exists or not profile_complete:
            raise Http404

        profile = UserProfile.objects.get(user__username=username)
        profile.set_instance_privacy_level(PUBLIC)
        if request.user.is_authenticated():
            profile.set_instance_privacy_level(request.user.userprofile.privacy_level)

        if not profile.is_vouched and request.user.is_authenticated() and request.user.userprofile.is_vouched:
            data["vouch_form"] = forms.VouchForm(initial={"vouchee": profile.pk})

    data["shown_user"] = profile.user
    data["profile"] = profile
    data["groups"] = profile.get_annotated_groups()
    data["locale"] = request.locale

    # Only show pending groups if user is looking at their own profile,
    # or current user is a superuser
    if not (request.user.is_authenticated() and (request.user.username == username or request.user.is_superuser)):
        data["groups"] = [grp for grp in data["groups"] if not grp.pending]

    return render(request, "phonebook/profile.html", data)
开发者ID:J0WI,项目名称:mozillians,代码行数:57,代码来源:views.py

示例7: delete_invite

def delete_invite(request, invite_pk):
    profile = request.user.userprofile
    deleted_invite = get_object_or_404(Invite, pk=invite_pk, inviter=profile, redeemed=None)
    deleted_invite.delete()

    msg = (_(u"%s's invitation to Mozillians has been revoked. "
             u"You can invite %s again if you like.") %
            (deleted_invite.recipient, deleted_invite.recipient))
    messages.success(request, msg)
    return redirect('phonebook:invite')
开发者ID:maheshkkumar,项目名称:mozillians,代码行数:10,代码来源:views.py

示例8: delete_email

def delete_email(request, email_pk):
    """Delete alternate email address."""
    user = User.objects.get(pk=request.user.id)
    profile = user.userprofile

    # Only email owner can delete emails
    if not ExternalAccount.objects.filter(user=profile, pk=email_pk).exists():
        raise Http404()

    ExternalAccount.objects.get(pk=email_pk).delete()
    return redirect('phonebook:edit_emails')
开发者ID:JacksonIsaac,项目名称:mozillians,代码行数:11,代码来源:views.py

示例9: unvouch

def unvouch(request, username):
    """Automatically remove all vouches from username.

    This must be behind a waffle flag and activated only for testing
    purposes.

    """
    profile = get_object_or_404(UserProfile, user__username=username)
    profile.vouches_received.all().delete()
    messages.success(request, _('Successfully unvouched user.'))
    return redirect('phonebook:profile_view', profile.user.username)
开发者ID:maheshkkumar,项目名称:mozillians,代码行数:11,代码来源:views.py

示例10: process_request

    def process_request(self, request):
        user = request.user
        path = request.path

        if settings.DEBUG:
            self.allow_urls.append(settings.MEDIA_URL)

        if (user.is_authenticated() and not user.userprofile.is_complete and not
                filter(lambda url: re.match(url, path), self.allow_urls)):
            messages.warning(request, _('Please complete registration before proceeding.'))
            return redirect('phonebook:profile_edit')
开发者ID:eckeman,项目名称:mozillians,代码行数:11,代码来源:middleware.py

示例11: vouch

def vouch(request, username):
    """Automatically vouch username.

    This must be behind a waffle flag and activated only for testing
    purposes.

    """
    profile = get_object_or_404(UserProfile, user__username=username)
    now = timezone.now()
    description = 'Automatically vouched for testing purposes on {0}'.format(now)
    profile.vouch(None, description=description, autovouch=True)
    messages.success(request, _('Successfully vouched user.'))
    return redirect('phonebook:profile_view', profile.user.username)
开发者ID:maheshkkumar,项目名称:mozillians,代码行数:13,代码来源:views.py

示例12: vouch

def vouch(request):
    """Vouch a user."""
    form = forms.VouchForm(request.POST)

    if form.is_valid():
        p = UserProfile.objects.get(pk=form.cleaned_data.get("vouchee"))
        p.vouch(request.user.userprofile)

        # Notify the current user that they vouched successfully.
        msg = _(u"Thanks for vouching for a fellow Mozillian! " u"This user is now vouched!")
        messages.info(request, msg)
        return redirect("phonebook:profile_view", p.user.username)

    return HttpResponseBadRequest()
开发者ID:rahulrrixe,项目名称:mozillians,代码行数:14,代码来源:views.py

示例13: betasearch

def betasearch(request):
    """This view is for researching new search and data filtering
    options. It will eventually replace the 'search' view.

    This view is behind the 'betasearch' waffle flag.
    """
    limit = None
    people = []
    show_pagination = False
    form = forms.SearchForm(request.GET)
    groups = None
    functional_areas = None

    if form.is_valid():
        query = form.cleaned_data.get('q', u'')
        limit = form.cleaned_data['limit']
        include_non_vouched = form.cleaned_data['include_non_vouched']
        page = request.GET.get('page', 1)
        functional_areas = Group.get_functional_areas()
        public = not (request.user.is_authenticated()
                      and request.user.userprofile.is_vouched)

        profiles = UserProfile.search(query, public=public,
                                      include_non_vouched=include_non_vouched)
        if not public:
            groups = Group.search(query)

        paginator = Paginator(profiles, limit)

        try:
            people = paginator.page(page)
        except PageNotAnInteger:
            people = paginator.page(1)
        except EmptyPage:
            people = paginator.page(paginator.num_pages)

        if profiles.count() == 1 and not groups:
            return redirect('phonebook:profile_view', people[0].user.username)

        show_pagination = paginator.count > settings.ITEMS_PER_PAGE

    d = dict(people=people,
             search_form=form,
             limit=limit,
             show_pagination=show_pagination,
             groups=groups,
             functional_areas=functional_areas)

    return render(request, 'phonebook/betasearch.html', d)
开发者ID:maheshkkumar,项目名称:mozillians,代码行数:49,代码来源:views.py

示例14: invite

def invite(request):
    profile = request.user.userprofile
    invite_form = forms.InviteForm(request.POST or None,
                                   instance=Invite(inviter=profile))
    if invite_form.is_valid():
        invite = invite_form.save()
        invite.send(sender=profile, personal_message=invite_form.cleaned_data['message'])
        msg = _(u"%s has been invited to Mozillians. They'll receive an email "
                u"with instructions on how to join. You can "
                u"invite another Mozillian if you like.") % invite.recipient
        messages.success(request, msg)
        return redirect('phonebook:home')

    return render(request, 'phonebook/invite.html',
                  {'invite_form': invite_form, 'invites': profile.invites.all()})
开发者ID:agbiyani,项目名称:mozillians,代码行数:15,代码来源:views.py

示例15: invite

def invite(request):
    profile = request.user.userprofile
    invite_form = forms.InviteForm(request.POST or None,
                                   instance=Invite(inviter=profile))
    if request.method == 'POST' and invite_form.is_valid():
        invite = invite_form.save()
        invite.send(sender=profile)
        msg = _(u"%s has been invited to Mozillians. They'll receive an email "
                u"with instructions on how to join. You can "
                u"invite another Mozillian if you like." % invite.recipient)
        messages.success(request, msg)
        return redirect('phonebook:home')

    return render(request, 'phonebook/invite.html',
                  {'invite_form': invite_form})
开发者ID:Ppchiu,项目名称:mozillians,代码行数:15,代码来源:views.py


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