示例#1
0
def edit_group_member(request, mid):
    member = get_object_or_404(Dojo_Group_Member, pk=mid)
    memberform = Edit_Group_MemberForm(instance=member)

    if request.method == 'POST':
        memberform = Edit_Group_MemberForm(request.POST, instance=member)
        if memberform.is_valid():
            if not member.role.is_owner:
                owners = Dojo_Group_Member.objects.filter(
                    group=member.group,
                    role__is_owner=True).exclude(id=member.id).count()
                if owners < 1:
                    messages.add_message(
                        request,
                        messages.WARNING,
                        'There must be at least one owner for group {}.'.
                        format(member.group.name),
                        extra_tags='alert-warning')
                    if is_title_in_breadcrumbs('View User'):
                        return HttpResponseRedirect(
                            reverse('view_user', args=(member.user.id, )))
                    else:
                        return HttpResponseRedirect(
                            reverse('view_group', args=(member.group.id, )))
            if member.role.is_owner and not user_has_permission(
                    request.user, member.group, Permissions.Group_Add_Owner):
                messages.add_message(
                    request,
                    messages.WARNING,
                    'You are not permitted to make users owners.',
                    extra_tags='alert-warning')
            else:
                memberform.save()
                messages.add_message(request,
                                     messages.SUCCESS,
                                     'Group member updated successfully',
                                     extra_tags='alert-success')
                if is_title_in_breadcrumbs('View User'):
                    return HttpResponseRedirect(
                        reverse('view_user', args=(member.user.id, )))
                else:
                    return HttpResponseRedirect(
                        reverse('view_group', args=(member.group.id, )))

    add_breadcrumb(title="Edit a Group Member",
                   top_level=False,
                   request=request)
    return render(request, 'dojo/edit_group_member.html', {
        'memberid': mid,
        'form': memberform
    })
示例#2
0
def delete_product_type_group(request, groupid):
    group = get_object_or_404(Product_Type_Group, pk=groupid)
    groupform = Delete_Product_Type_GroupForm(instance=group)

    if request.method == 'POST':
        groupform = Delete_Product_Type_GroupForm(request.POST, instance=group)
        group = groupform.instance
        group.delete()
        messages.add_message(request,
                             messages.SUCCESS,
                             'Product type group deleted successfully.',
                             extra_tags='alert-success')
        if is_title_in_breadcrumbs('View Group'):
            return HttpResponseRedirect(
                reverse('view_group', args=(group.group.id, )))
        else:
            # TODO: If user was in the group that was deleted and no longer has access, redirect them to the product
            #  types page
            return HttpResponseRedirect(
                reverse('view_product_type', args=(group.product_type.id, )))

    add_breadcrumb("Delete Product Type Group",
                   top_level=False,
                   request=request)
    return render(request, 'dojo/delete_product_type_group.html', {
        'groupid': groupid,
        'form': groupform
    })
示例#3
0
def edit_product_type_group(request, groupid):
    group = get_object_or_404(Product_Type_Group, pk=groupid)
    groupform = Edit_Product_Type_Group_Form(instance=group)

    if request.method == 'POST':
        groupform = Edit_Product_Type_Group_Form(request.POST, instance=group)
        if groupform.is_valid():
            if group.role.is_owner and not user_has_permission(request.user, group.product_type, Permissions.Product_Type_Group_Add_Owner):
                messages.add_message(request,
                                     messages.WARNING,
                                     'You are not permitted to make groups owners.',
                                     extra_tags='alert-warning')
            else:
                groupform.save()
                messages.add_message(request,
                                     messages.SUCCESS,
                                     'Product type group updated successfully.',
                                     extra_tags='alert-success')
                if is_title_in_breadcrumbs('View Group'):
                    return HttpResponseRedirect(reverse('view_group', args=(group.group.id,)))
                else:
                    return HttpResponseRedirect(reverse('view_product_type', args=(group.product_type.id,)))

    add_breadcrumb(title="Edit Product Type Group", top_level=False, request=request)
    return render(request, 'dojo/edit_product_type_group.html', {
        'groupid': groupid,
        'form': groupform
    })
示例#4
0
def delete_product_type_member(request, memberid):
    member = get_object_or_404(Product_Type_Member, pk=memberid)
    memberform = Delete_Product_Type_MemberForm(instance=member)
    if request.method == 'POST':
        memberform = Delete_Product_Type_MemberForm(request.POST, instance=member)
        member = memberform.instance
        if member.role.is_owner:
            owners = Product_Type_Member.objects.filter(product_type=member.product_type, role__is_owner=True).count()
            if owners <= 1:
                messages.add_message(request,
                                    messages.SUCCESS,
                                    'There must be at least one owner.',
                                    extra_tags='alert-warning')
                return HttpResponseRedirect(reverse('view_product_type', args=(member.product_type.id, )))

        user = member.user
        member.delete()
        messages.add_message(request,
                            messages.SUCCESS,
                            'Product type member deleted successfully.',
                            extra_tags='alert-success')
        if is_title_in_breadcrumbs('View User'):
            return HttpResponseRedirect(reverse('view_user', args=(member.user.id, )))
        else:
            if user == request.user:
                return HttpResponseRedirect(reverse('product_type'))
            else:
                return HttpResponseRedirect(reverse('view_product_type', args=(member.product_type.id, )))
    add_breadcrumb(title="Delete Product Type Member", top_level=False, request=request)
    return render(request, 'dojo/delete_product_type_member.html', {
        'memberid': memberid,
        'form': memberform,
    })
示例#5
0
def delete_group_member(request, mid):
    member = get_object_or_404(Dojo_Group_Member, pk=mid)
    memberform = Delete_Group_MemberForm(instance=member)

    if request.method == 'POST':
        memberform = Delete_Group_MemberForm(request.POST, instance=member)
        member = memberform.instance
        if member.role.is_owner:
            owners = Dojo_Group_Member.objects.filter(
                group=member.group, role__is_owner=True).count()
            if owners <= 1:
                messages.add_message(
                    request,
                    messages.WARNING,
                    'There must be at least one owner for group {}.'.format(
                        member.group.name),
                    extra_tags='alert-warning')
                if is_title_in_breadcrumbs('View User'):
                    return HttpResponseRedirect(
                        reverse('view_user', args=(member.user.id, )))
                else:
                    return HttpResponseRedirect(
                        reverse('view_group', args=(member.group.id, )))

        user = member.user
        member.delete()
        messages.add_message(request,
                             messages.SUCCESS,
                             'Group member deleted successfully.',
                             extra_tags='alert-success')
        if is_title_in_breadcrumbs('View User'):
            return HttpResponseRedirect(
                reverse('view_user', args=(member.user.id, )))
        else:
            if user == request.user:
                return HttpResponseRedirect(reverse('groups'))
            else:
                return HttpResponseRedirect(
                    reverse('view_group', args=(member.group.id, )))

    add_breadcrumb("Delete a group member", top_level=False, request=request)
    return render(request, 'dojo/delete_group_member.html', {
        'memberid': mid,
        'form': memberform
    })