本文整理汇总了Python中mozillians.common.templatetags.helpers.redirect函数的典型用法代码示例。如果您正苦于以下问题:Python redirect函数的具体用法?Python redirect怎么用?Python redirect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了redirect函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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:Acidburn0zzz,项目名称:mozillians,代码行数:11,代码来源:middleware.py
示例2: delete_identity
def delete_identity(request, identity_pk):
"""Delete alternate email address."""
user = User.objects.get(pk=request.user.id)
profile = user.userprofile
# Only email owner can delete emails
idp_query = IdpProfile.objects.filter(profile=profile, pk=identity_pk)
if not idp_query.exists():
raise Http404()
idp_query = idp_query.filter(primary=False, primary_contact_identity=False)
if idp_query.exists():
idp_type = idp_query[0].get_type_display()
idp_query.delete()
send_userprofile_to_cis.delay(profile.pk)
msg = _(u'Identity {0} successfully deleted.'.format(idp_type))
messages.success(request, msg)
return redirect('phonebook:profile_edit')
# We are trying to delete the primary identity, politely ignore the request
msg = _(u'Sorry the requested Identity cannot be deleted.')
messages.error(request, msg)
return redirect('phonebook:profile_edit')
开发者ID:johngian,项目名称:mozillians,代码行数:23,代码来源:views.py
示例3: apikeys
def apikeys(request):
profile = request.user.userprofile
apikey_request_form = forms.APIKeyRequestForm(
request.POST or None,
instance=APIv2App(enabled=True, owner=profile)
)
if apikey_request_form.is_valid():
apikey_request_form.save()
msg = _(u'API Key generated successfully.')
messages.success(request, msg)
return redirect('phonebook:apikeys')
data = {
'appsv2': profile.apps.filter(enabled=True),
'apikey_request_form': apikey_request_form,
}
return render(request, 'phonebook/apikeys.html', data)
开发者ID:johngian,项目名称:mozillians,代码行数:18,代码来源:views.py
示例4: change_primary_contact_identity
def change_primary_contact_identity(request, identity_pk):
"""Change primary email address."""
user = User.objects.get(pk=request.user.id)
profile = user.userprofile
alternate_identities = IdpProfile.objects.filter(profile=profile)
# Only email owner can change primary email
if not alternate_identities.filter(pk=identity_pk).exists():
raise Http404()
if alternate_identities.filter(primary_contact_identity=True).exists():
alternate_identities.filter(pk=identity_pk).update(primary_contact_identity=True)
alternate_identities.exclude(pk=identity_pk).update(primary_contact_identity=False)
msg = _(u'Primary Contact Identity successfully updated.')
messages.success(request, msg)
return redirect('phonebook:profile_edit')
开发者ID:johngian,项目名称:mozillians,代码行数:18,代码来源:views.py
示例5: search
def search(request):
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 = UserProfileMappingType.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/search.html', d)
开发者ID:federicoculloca,项目名称:mozillians,代码行数:44,代码来源:views.py
示例6: process_view
def process_view(self, request, view_func, view_args, view_kwargs):
for view_url in self.exceptions:
if re.match(view_url, request.path):
return None
allow_public = getattr(view_func, '_allow_public', None)
if allow_public:
return None
if not request.user.is_authenticated():
messages.warning(request, LOGIN_MESSAGE)
return (login_required(view_func, login_url=reverse('phonebook:home'))
(request, *view_args, **view_kwargs))
if request.user.userprofile.is_vouched:
return None
allow_unvouched = getattr(view_func, '_allow_unvouched', None)
if allow_unvouched:
return None
messages.error(request, GET_VOUCHED_MESSAGE)
return redirect('phonebook:home')
开发者ID:johngian,项目名称:mozillians,代码行数:23,代码来源:middleware.py
示例7: __call__
def __call__(self, request):
user = request.user
path = request.path
allow_urls = [
r'^/[\w-]+{0}'.format(reverse('phonebook:logout')),
r'^/[\w-]+{0}'.format(reverse('phonebook:login')),
r'^/[\w-]+{0}'.format(reverse('phonebook:profile_edit')),
r'^/[\w-]+{0}'.format(reverse('groups:skills-autocomplete')),
r'^/[\w-]+{0}'.format(reverse('users:country-autocomplete')),
r'^/[\w-]+{0}'.format(reverse('users:region-autocomplete')),
r'^/[\w-]+{0}'.format(reverse('users:city-autocomplete')),
r'^/[\w-]+{0}'.format(reverse('users:timezone-autocomplete')),
]
if settings.DEBUG:
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), allow_urls)):
messages.warning(request, _('Please complete registration before proceeding.'))
return redirect('phonebook:profile_edit')
return self.get_response(request)
开发者ID:akatsoulas,项目名称:mozillians,代码行数:23,代码来源:middleware.py
示例8: get
def get(self, request):
"""Callback handler for OIDC authorization code flow.
This is based on the mozilla-django-oidc library.
This callback is used to verify the identity added by the user.
Users are already logged in and we do not care about authentication.
The JWT token is used to prove the identity of the user.
"""
profile = request.user.userprofile
# This is a difference nonce than the one used to login!
nonce = request.session.get('oidc_verify_nonce')
if nonce:
# Make sure that nonce is not used twice
del request.session['oidc_verify_nonce']
# Check for all possible errors and display a message to the user.
errors = [
'code' not in request.GET,
'state' not in request.GET,
'oidc_verify_state' not in request.session,
request.GET['state'] != request.session['oidc_verify_state']
]
if any(errors):
msg = 'Something went wrong, account verification failed.'
messages.error(request, msg)
return redirect('phonebook:profile_edit')
token_payload = {
'client_id': self.OIDC_RP_VERIFICATION_CLIENT_ID,
'client_secret': self.OIDC_RP_VERIFICATION_CLIENT_SECRET,
'grant_type': 'authorization_code',
'code': request.GET['code'],
'redirect_uri': absolutify(
self.request,
nonprefixed_url('phonebook:verify_identity_callback')
),
}
response = requests.post(self.OIDC_OP_TOKEN_ENDPOINT,
data=token_payload,
verify=import_from_settings('OIDC_VERIFY_SSL', True))
response.raise_for_status()
token_response = response.json()
id_token = token_response.get('id_token')
# Verify JWT
jws = JWS.from_compact(force_bytes(id_token))
jwk = JWK.load(smart_bytes(self.OIDC_RP_VERIFICATION_CLIENT_SECRET))
verified_token = None
if jws.verify(jwk):
verified_token = jws.payload
# Create the new Identity Profile.
if verified_token:
user_info = json.loads(verified_token)
email = user_info['email']
if not user_info.get('email_verified'):
msg = 'Account verification failed: Email is not verified.'
messages.error(request, msg)
return redirect('phonebook:profile_edit')
user_q = {
'auth0_user_id': user_info['sub'],
'email': email
}
# If we are linking GitHub we need to save
# the username too.
if 'github|' in user_info['sub']:
user_q['username'] = user_info['nickname']
# Check that the identity doesn't exist in another Identity profile
# or in another mozillians profile
error_msg = ''
if IdpProfile.objects.filter(**user_q).exists():
error_msg = 'Account verification failed: Identity already exists.'
elif User.objects.filter(email__iexact=email).exclude(pk=profile.user.pk).exists():
error_msg = 'The email in this identity is used by another user.'
if error_msg:
messages.error(request, error_msg)
next_url = self.request.session.get('oidc_login_next', None)
return HttpResponseRedirect(next_url or reverse('phonebook:profile_edit'))
# Save the new identity to the IdpProfile
user_q['profile'] = profile
idp, created = IdpProfile.objects.get_or_create(**user_q)
current_idp = get_object_or_none(IdpProfile, profile=profile, primary=True)
# The new identity is stronger than the one currently used. Let's swap
append_msg = ''
# We need to check for equality too in the case a user updates the primary email in
# the same identity (matching auth0_user_id). If there is an addition of the same type
# we are not swapping login identities
if ((current_idp and current_idp.type < idp.type) or
(current_idp and current_idp.auth0_user_id == idp.auth0_user_id) or
(not current_idp and created and idp.type >= IdpProfile.PROVIDER_GITHUB)):
IdpProfile.objects.filter(profile=profile).exclude(pk=idp.pk).update(primary=False)
idp.primary = True
idp.save()
#.........这里部分代码省略.........
开发者ID:johngian,项目名称:mozillians,代码行数:101,代码来源:views.py
示例9: delete_idp_profiles
def delete_idp_profiles(request):
"""QA helper: Delete IDP profiles for request.user"""
request.user.userprofile.idp_profiles.all().delete()
messages.warning(request, 'Identities deleted.')
return redirect('phonebook:profile_edit')
开发者ID:johngian,项目名称:mozillians,代码行数:5,代码来源:views.py
注:本文中的mozillians.common.templatetags.helpers.redirect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论