• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python urlresolvers.reverse函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了reverse函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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])
开发者ID:yahkrivetko,项目名称:mozillians,代码行数:25,代码来源:models.py


示例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]))
开发者ID:param927,项目名称:mozillians,代码行数:29,代码来源:views.py


示例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)
开发者ID:yahkrivetko,项目名称:mozillians,代码行数:32,代码来源:views.py


示例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)
开发者ID:param927,项目名称:mozillians,代码行数:27,代码来源:views.py


示例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'))
开发者ID:fxa90id,项目名称:mozillians,代码行数:7,代码来源:views.py


示例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'))
开发者ID:param927,项目名称:mozillians,代码行数:17,代码来源:views.py


示例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)
开发者ID:eckeman,项目名称:mozillians,代码行数:42,代码来源:views.py


示例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]))
开发者ID:param927,项目名称:mozillians,代码行数:11,代码来源:views.py


示例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])
开发者ID:Acidburn0zzz,项目名称:mozillians,代码行数:14,代码来源:models.py


示例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)
开发者ID:param927,项目名称:mozillians,代码行数:24,代码来源:views.py


示例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)
开发者ID:yahkrivetko,项目名称:mozillians,代码行数:48,代码来源:views.py


示例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()
开发者ID:param927,项目名称:mozillians,代码行数:16,代码来源:views.py


示例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)
开发者ID:fxa90id,项目名称:mozillians,代码行数:17,代码来源:views.py


示例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()
开发者ID:fxa90id,项目名称:mozillians,代码行数:17,代码来源:views.py


示例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]))
开发者ID:fxa90id,项目名称:mozillians,代码行数:18,代码来源:views.py


示例16: index_groups

def index_groups(request):
    """Lists all public groups (in use) on Mozillians.

    Doesn't list functional areas, invisible groups, and groups with
    no vouched members
    """

    group_form = forms.CreateGroupForm(request.POST or None)
    if group_form.is_valid():
        group = group_form.save()
        group.curators.add(request.user.userprofile)
        return redirect(reverse('groups:group_edit', args=[group.url]))

    query = Group.get_non_functional_areas()
    template = 'groups/index_groups.html'
    context = {
        'group_form': group_form
    }
    return _list_groups(request, template, query, context)
开发者ID:ppapadeas,项目名称:mozillians,代码行数:19,代码来源:views.py


示例17: 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:ariestiyansyah,项目名称:mozillians,代码行数:22,代码来源:middleware.py


示例18: force_group_invalidation

def force_group_invalidation(request, url, alias_model, template=''):
    """View to help test different scenarios.

    Forces an immediate invalidation in the case that a group is
    set to expire its memberships.
    """
    group_alias = get_object_or_404(alias_model, url=url)
    group = group_alias.alias
    is_curator = group.curators.filter(id=request.user.userprofile.pk).exists()
    if group.invalidation_days and is_curator:

        curator_ids = group.curators.all().values_list('id', flat=True)
        memberships = group.groupmembership_set.exclude(userprofile__id__in=curator_ids)

        for member in memberships:
            status = None
            if group.accepting_new_members != Group.OPEN:
                status = GroupMembership.PENDING
            group.remove_member(member.userprofile, status=status)
    else:
        raise http.Http404

    return redirect(reverse('groups:show_group', args=[group.url]))
开发者ID:fxa90id,项目名称:mozillians,代码行数:23,代码来源:views.py


示例19: get_absolute_url

 def get_absolute_url(self):
     cls_name = self.__class__.__name__
     url_pattern = 'groups:show_{0}'.format(cls_name.lower())
     return absolutify(reverse(url_pattern, args=[self.url]))
开发者ID:johngian,项目名称:mozillians,代码行数:4,代码来源:models.py


示例20: group_edit

def group_edit(request, url=None):
    """Add or edit a group. (if there is a url we are editing)"""

    profile = request.user.userprofile
    is_manager = request.user.userprofile.is_manager
    invites = None
    forms_valid = True
    group_forms = {}
    form_key = None
    show_delete_group_button = False

    if not url:
        return redirect(reverse('groups:index_groups'))

    # 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()
    is_manager = request.user.userprofile.is_manager
    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]))

    invites = group.invites.all()
    show_delete_group_button = is_curator and group.members.all().count() == 1

    # Prepare the forms for rendering
    group_forms['basic_form'] = forms.GroupBasicForm
    group_forms['invalidation_form'] = forms.GroupInvalidationForm
    group_forms['curator_form'] = forms.GroupCuratorsForm
    group_forms['terms_form'] = forms.GroupTermsForm
    group_forms['invite_form'] = forms.GroupInviteForm
    group_forms['admin_form'] = forms.GroupAdminForm
    group_forms['criteria_form'] = forms.GroupCriteriaForm

    def _init_group_forms(request, group_forms):
        form_args = {
            'data': None,
            'instance': group,
            'request': request
        }
        key = None

        if request.POST:
            form_args['data'] = request.POST
            key, form = next(((k, v(**form_args)) for k, v in group_forms.items()
                              if k in request.POST), (None, None))
            if key and form:
                group_forms[key] = form

        # Initialize the rest of the forms with non-POST data
        form_args['data'] = None
        for k in group_forms.keys():
            if k != key:
                group_forms[k] = group_forms[k](**form_args)
        return key

    form_key = _init_group_forms(request, group_forms)

    form = group_forms[form_key] if form_key else None
    if form and form.is_bound and form.is_valid():
        form.save()
        next_section = request.GET.get('next')
        next_url = urlparams(reverse('groups:group_edit', args=[group.url]), next_section)
        return HttpResponseRedirect(next_url)

    context = {
        'group': group if url else None,
        'invites': invites if group else None,
        'forms_valid': forms_valid,
        'user_is_curator': is_curator,
        'user_is_manager': is_manager,
        'show_delete_group_button': show_delete_group_button
    }
    context.update(group_forms)
    return render(request, 'groups/edit_group.html', context)
开发者ID:param927,项目名称:mozillians,代码行数:76,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tests.CountryFactory类代码示例发布时间:2022-05-27
下一篇:
Python helpers.urlparams函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap