本文整理汇总了Python中mozillians.common.urlresolvers.reverse函数的典型用法代码示例。如果您正苦于以下问题:Python reverse函数的具体用法?Python reverse怎么用?Python reverse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了reverse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _email_now_vouched
def _email_now_vouched(self, vouched_by, description=''):
"""Email this user, letting them know they are now vouched."""
name = None
voucher_profile_link = None
vouchee_profile_link = utils.absolutify(self.get_absolute_url())
if vouched_by:
name = vouched_by.full_name
voucher_profile_link = utils.absolutify(vouched_by.get_absolute_url())
number_of_vouches = self.vouches_received.all().count()
template = get_template('phonebook/emails/vouch_confirmation_email.txt')
message = template.render({
'voucher_name': name,
'voucher_profile_url': voucher_profile_link,
'vouchee_profile_url': vouchee_profile_link,
'vouch_description': description,
'functional_areas_url': utils.absolutify(reverse('groups:index_functional_areas')),
'groups_url': utils.absolutify(reverse('groups:index_groups')),
'first_vouch': number_of_vouches == 1,
'can_vouch_threshold': number_of_vouches == settings.CAN_VOUCH_THRESHOLD,
})
subject = _(u'You have been vouched on Mozillians.org')
filtered_message = message.replace('"', '"').replace(''', "'")
send_mail(subject, filtered_message, settings.FROM_NOREPLY,
[self.email])
示例2: join_group
def join_group(request, url):
"""User request to join group."""
group = get_object_or_404(Group, url=url)
profile_to_add = request.user.userprofile
# TODO: this duplicates some of the logic in Group.user_can_join(), but we
# want to give the user a message that's specific to the reason they can't join.
# Can we make this DRYer?
if group.has_member(profile_to_add):
messages.error(request, _('You are already in this group.'))
elif group.has_pending_member(profile_to_add):
messages.error(request, _('Your request to join this group is still pending.'))
elif group.accepting_new_members == 'no':
messages.error(request, _('This group is not accepting requests to join.'))
else:
if group.accepting_new_members == 'yes':
status = GroupMembership.MEMBER
messages.info(request, _('You have been added to this group.'))
if group.terms:
status = GroupMembership.PENDING_TERMS
elif group.accepting_new_members == 'by_request':
status = GroupMembership.PENDING
messages.info(request, _('Your membership request has been sent '
'to the group curator(s).'))
group.add_member(profile_to_add, status=status)
return redirect(reverse('groups:show_group', args=[group.url]))
示例3: confirm_member
def confirm_member(request, url, user_pk):
"""
Add a member to a group who has requested membership.
"""
group = get_object_or_404(Group, url=url)
profile = get_object_or_404(UserProfile, pk=user_pk)
is_curator = (request.user.userprofile in group.curators.all())
is_manager = request.user.userprofile.is_manager
group_url = reverse('groups:show_group', args=[group.url])
# Workaround for using both request.GET and request.POST data
next_url = getattr(request, request.method).get('next_url', group_url)
if not (is_curator or is_manager):
raise http.Http404()
try:
membership = GroupMembership.objects.get(group=group, userprofile=profile)
except GroupMembership.DoesNotExist:
messages.error(request, _('This user has not requested membership in this group.'))
else:
if membership.status == GroupMembership.MEMBER and not membership.needs_renewal:
messages.error(request, _('This user is already a member of this group.'))
else:
status = GroupMembership.MEMBER
if group.terms:
status = GroupMembership.PENDING_TERMS
group.add_member(profile, status=status, inviter=request.user.userprofile)
if membership.needs_renewal:
messages.info(request, _('The membership of the user has been renewed.'))
else:
messages.info(request, _('This user has been added as a member of this group.'))
return redirect(next_url)
示例4: confirm_member
def confirm_member(request, url, user_pk):
"""
Add a member to a group who has requested membership.
"""
group = get_object_or_404(Group, url=url)
profile = get_object_or_404(UserProfile, pk=user_pk)
is_curator = (request.user.userprofile in group.curators.all())
is_manager = request.user.userprofile.is_manager
group_url = reverse('groups:show_group', args=[group.url])
next_url = request.REQUEST.get('next_url', group_url)
if not (is_curator or is_manager):
raise Http404()
try:
membership = GroupMembership.objects.get(group=group, userprofile=profile)
except GroupMembership.DoesNotExist:
messages.error(request, _('This user has not requested membership in this group.'))
else:
if membership.status == GroupMembership.MEMBER:
messages.error(request, _('This user is already a member of this group.'))
else:
status = GroupMembership.MEMBER
if group.terms:
status = GroupMembership.PENDING_TERMS
group.add_member(profile, status=status)
messages.info(request, _('This user has been added as a member of this group.'))
return redirect(next_url)
示例5: membership_renewal_notification
def membership_renewal_notification(request):
"""View to help test membership renewal notification
Manually spawn a task to send membership renewal notifications to the users.
"""
notify_membership_renewal.apply_async()
return redirect(reverse('groups:index_groups'))
示例6: group_delete
def group_delete(request, url):
profile = request.user.userprofile
# Get the group to delete
group = get_object_or_404(Group, url=url)
# Only a group curator is allowed to delete a group
is_curator = profile in group.curators.all()
if not is_curator and not profile.is_manager:
messages.error(request, _('You must be a curator to delete a group'))
return redirect(reverse('groups:show_group', args=[group.url]))
# Cannot delete if anyone else is in it
if group.members.all().count() != 1:
messages.error(request, _('You cannot delete a group if anyone else is in it.'))
return redirect(reverse('groups:show_group', args=[group.url]))
# Go to it
group.delete()
messages.info(request, _('Group %s has been deleted') % group.name)
return redirect(reverse('groups:index_groups'))
示例7: group_add_edit
def group_add_edit(request, url=None):
"""
Add or edit a group. (If a url is passed in, we're editing.)
"""
profile = request.user.userprofile
is_manager = request.user.userprofile.is_manager
if url:
# Get the group to edit
group = get_object_or_404(Group, url=url)
# Only a group curator or an admin is allowed to edit a group
is_curator = profile in group.curators.all()
if not (is_curator or is_manager):
messages.error(request, _('You must be a curator or an admin to edit a group'))
return redirect(reverse('groups:show_group', args=[group.url]))
else:
group = Group()
form_class = SuperuserGroupForm if is_manager else GroupForm
# Add the creator of a group as curator
curators_ids = [profile.id]
# If we are editing add the existing curators. If the group has no curator in edit
# mode, append an empty list
if url:
curators_ids = group.curators.all().values_list('id', flat=True)
form = form_class(request.POST or None, instance=group,
initial={'curators': curators_ids})
if form.is_valid():
group = form.save()
return redirect(reverse('groups:show_group', args=[group.url]))
context = {
'form': form,
'creating': url is None,
'group': group if url else None
}
return render(request, 'groups/add_edit.html', context)
示例8: toggle_skill_subscription
def toggle_skill_subscription(request, url):
"""Toggle the current user's membership of a group."""
skill = get_object_or_404(Skill, url=url)
profile = request.user.userprofile
if profile.skills.filter(id=skill.id).exists():
profile.skills.remove(skill)
else:
profile.skills.add(skill)
return redirect(reverse('groups:show_skill', args=[skill.url]))
示例9: send_thanks
def send_thanks(self):
"""Sends email to person who friend accepted invitation."""
template = get_template('phonebook/emails/invite_accepted.txt')
subject = _('%s created a Mozillians profile') % self.redeemer.full_name
profile_url = reverse('phonebook:profile_view',
kwargs={'username': self.redeemer.user.username})
message = template.render({
'inviter': self.inviter.full_name,
'friend': self.redeemer.full_name,
'profile': absolutify(profile_url)})
filtered_message = message.replace('"', '"').replace(''', "'")
send_mail(subject, filtered_message, settings.FROM_NOREPLY,
[self.inviter.email])
示例10: review_terms
def review_terms(request, url):
"""Review group terms page."""
group = get_object_or_404(Group, url=url)
if not group.terms:
return redirect(reverse('groups:show_group', args=[group.url]))
membership = get_object_or_404(GroupMembership, group=group,
userprofile=request.user.userprofile,
status=GroupMembership.PENDING_TERMS)
membership_form = forms.TermsReviewForm(request.POST or None)
if membership_form.is_valid():
if membership_form.cleaned_data['terms_accepted'] == 'True':
group.add_member(request.user.userprofile, GroupMembership.MEMBER)
else:
membership.delete()
return redirect(reverse('groups:show_group', args=[group.url]))
ctx = {
'group': group,
'membership_form': membership_form
}
return render(request, 'groups/terms.html', ctx)
示例11: remove_member
def remove_member(request, url, user_pk, status=None):
group = get_object_or_404(Group, url=url)
profile_to_remove = get_object_or_404(UserProfile, pk=user_pk)
this_userprofile = request.user.userprofile
is_curator = (this_userprofile in group.curators.all())
is_manager = request.user.userprofile.is_manager
group_url = reverse('groups:show_group', args=[group.url])
# Workaround for using both request.GET and request.POST data
next_url = getattr(request, request.method).get('next_url', group_url)
# TODO: this duplicates some of the logic in Group.user_can_leave(), but we
# want to give the user a message that's specific to the reason they can't leave.
# Can we make this DRYer?
# You can remove yourself, if group allows it. Curator and superuser can remove anyone.
if not (is_curator or is_manager):
if not group.members_can_leave:
messages.error(request, _('This group does not allow members to remove themselves.'))
return redirect(next_url)
if profile_to_remove != this_userprofile:
raise http.Http404()
# Curators cannot be removed, only by themselves and if there is another curator.
curators = group.curators.all()
if (profile_to_remove in curators and curators.count() <= 1 and
profile_to_remove != this_userprofile):
messages.error(request, _('The group needs at least one curator.'))
return redirect(next_url)
if request.method == 'POST':
group.remove_member(profile_to_remove, status=status,
send_email=(profile_to_remove != this_userprofile))
if profile_to_remove in curators:
group.curators.remove(profile_to_remove)
if this_userprofile == profile_to_remove:
messages.info(request, _('You have been removed from this group.'))
else:
messages.info(request, _('The group member has been removed.'))
return redirect(next_url)
# Display confirmation page
context = {
'group': group,
'profile': profile_to_remove,
'next_url': next_url
}
return render(request, 'groups/confirm_remove_member.html', context)
示例12: delete_invite
def delete_invite(request, invite_pk):
"""Delete an invite to join a group."""
invite = get_object_or_404(Invite, pk=invite_pk)
group = invite.group
if (group.curators.filter(id=request.user.userprofile.id).exists() or
request.user.userprofile.is_manager):
redeemer = invite.redeemer
invite.delete()
# TODO:Revoke any celery tasks if needed and shoot revokation emails.
msg = _(u'The invitation to {0} has been successfully revoked. ').format(redeemer)
messages.success(request, msg)
return redirect(reverse('groups:group_edit', args=[group.url]))
raise Http404()
示例13: send_invitation_email
def send_invitation_email(request, invite_pk):
"""Send group invitation email."""
invite = get_object_or_404(Invite, pk=invite_pk)
is_curator = invite.group.curators.filter(pk=request.user.userprofile.pk).exists()
is_manager = request.user.userprofile.is_manager
if not (is_curator or is_manager):
raise http.Http404
notify_redeemer_invitation.delay(invite.pk, invite.group.invite_email_text)
msg = _(u'Invitation to {0} has been sent successfully.'.format(invite.redeemer))
messages.success(request, msg)
next_section = request.GET.get('next')
next_url = urlparams(reverse('groups:group_edit', args=[invite.group.url]), next_section)
return http.HttpResponseRedirect(next_url)
示例14: delete_invite
def delete_invite(request, invite_pk):
"""Delete an invite to join a group."""
invite = get_object_or_404(Invite, pk=invite_pk)
group = invite.group
if (group.curators.filter(id=request.user.userprofile.id).exists() or
request.user.userprofile.is_manager):
redeemer = invite.redeemer
invite.delete()
notify_redeemer_invitation_invalid.delay(redeemer.pk, group.pk)
msg = _(u'The invitation to {0} has been successfully revoked.').format(redeemer)
messages.success(request, msg)
next_section = request.GET.get('next')
next_url = urlparams(reverse('groups:group_edit', args=[group.url]), next_section)
return http.HttpResponseRedirect(next_url)
raise http.Http404()
示例15: accept_reject_invitation
def accept_reject_invitation(request, invite_pk, action):
"""Accept or reject group invitation."""
redeemer = request.user.userprofile
invite = get_object_or_404(Invite, pk=invite_pk, redeemer=redeemer)
if action == 'accept':
if invite.group.terms:
invite.group.add_member(redeemer, GroupMembership.PENDING_TERMS)
else:
invite.group.add_member(redeemer, GroupMembership.MEMBER)
invite.accepted = True
invite.save()
notify_curators_invitation_accepted.delay(invite.pk)
else:
notify_curators_invitation_rejected.delay(redeemer.pk, invite.inviter.pk, invite.group.pk)
invite.delete()
return redirect(reverse('groups:show_group', args=[invite.group.url]))