コード例 #1
0
def view(request, id=None, form=None):
    if id is None:
        return redirect(reverse("navigator:user", args=[request.user.id]))

    try:
        user = User.objects.get(id=id)
    except User.DoesNotExist:
        return HttpResponse("User not found", status=404)

    ref = request.META.get('HTTP_REFERER', '')
    success = ref.endswith(reverse("navigator:user", args=[user.id
                                                           ])) and not form
    form = form or forms.UserDetailsForm(request, instance=user)

    # Generate projects-table javascript
    projects = Datatable(ProjectResource).filter(projectrole__user=user)
    main_active = "Current User" if user == request.user else "Users"

    return render(
        request, "user_view.html", {
            'user': user,
            'form': form,
            'projects': projects,
            'success': success,
            'main_active': main_active
        })
コード例 #2
0
def edit(request, user):
    form = forms.UserDetailsForm(request,
                                 data=request.POST or None,
                                 instance=user)
    if form.is_valid():
        form.save()
        return redirect(reverse(view, args=[user.id]))
    return view(request, id=user.id, form=form)
コード例 #3
0
def edit(request, user):
    try:
        user = User.objects.get(id=user)
    except User.DoesNotExist:
        return HttpResponse('User not found', status=404)

    if not (request.user.is_superuser or request.user.id == user.id):
        raise PermissionDenied("You cannot edit this user's profile.")

    form = forms.UserDetailsForm(request,
                                 data=request.POST or None,
                                 instance=user)
    if form.is_valid():
        form.save()
        return redirect(reverse("navigator:user", args=[user.id]))
    return view(request, id=user.id, form=form)
コード例 #4
0
def view(request, user=None, form=None):
    if user is None:
        return redirect(reverse(view, args=[request.user.id]))

    ref = request.META.get('HTTP_REFERER', '')
    success = ref.endswith(reverse(view, args=[user.id])) and not form
    form = form or forms.UserDetailsForm(request, instance=user)

    # Generate projects-table javascript
    projects = Datatable(ProjectResource).filter(projectrole__user=user)
    menu = None if user == request.user else USER_MENU

    return render(
        request, "navigator/user/view.html", {
            'user': user,
            'form': form,
            'projects': projects,
            'success': success,
            'menu': menu
        })