예제 #1
0
def user_detail(request, pk):
    user = request.user
    if str(pk) != str(user.pk):
        user = get_object_or_404(User, pk=pk)

    if request.method == 'POST':
        if request.user == user:
            if 'changeset' in request.session and request.POST.get(
                    'deactivate_changeset') == '1':
                request.session.pop('changeset', None)
                messages.success(request,
                                 _('You deactivated your current changeset.'))
                return redirect(request.path)

            if request.changeset.pk is None and ChangeSet.can_direct_edit(
                    request):
                if request.POST.get('direct_editing') == '1':
                    request.session['direct_editing'] = True
                    messages.success(request,
                                     _('You activated direct editing.'))
                    return redirect(request.path)
                elif request.POST.get('direct_editing') == '0':
                    request.session.pop('direct_editing', None)
                    messages.success(request,
                                     _('You deactivated direct editing.'))
                    return redirect(request.path)

    ctx = {
        'user':
        user,
        'can_direct_edit':
        ChangeSet.can_direct_edit(request),
        'recent_changesets':
        ChangeSet.objects.filter(author=user).order_by('-last_update')[:15],
    }

    if request.user_permissions.review_changesets:
        ctx.update({
            'can_review':
            True,
            'reviewing_changesets':
            ChangeSet.objects.filter(assigned_to=user,
                                     state='review').order_by('-last_update'),
            'to_review_changesets':
            ChangeSet.objects.filter(
                state__in=('proposed',
                           'reproposed'), ).order_by('-last_update'),
            'all_recent_changesets':
            ChangeSet.objects.exclude(
                state='unproposed').order_by('-last_update')[:20],
        })

    return render(request, 'editor/user.html', ctx)
예제 #2
0
파일: users.py 프로젝트: nomoketo/c3nav-new
def user_detail(request, pk):
    user = request.user
    if str(pk) != str(user.pk):
        user = get_object_or_404(User, pk=pk)

    if request.method == 'POST':
        if request.user == user:
            if 'changeset' in request.session and request.POST.get('deactivate_changeset') == '1':
                request.session.pop('changeset', None)
                messages.success(request, _('You deactivated your current changeset.'))
                return redirect(request.path)

            if request.changeset.pk is None and ChangeSet.can_direct_edit(request):
                if request.POST.get('direct_editing') == '1':
                    request.session['direct_editing'] = True
                    messages.success(request, _('You activated direct editing.'))
                    return redirect(request.path)
                elif request.POST.get('direct_editing') == '0':
                    request.session.pop('direct_editing', None)
                    messages.success(request, _('You deactivated direct editing.'))
                    return redirect(request.path)

    ctx = {
        'user': user,
        'can_direct_edit': ChangeSet.can_direct_edit(request),
        'recent_changesets': ChangeSet.qs_for_request(request).filter(author=user).order_by('-last_update')[:15],
    }

    if request.user_permissions.review_changesets:
        ctx.update({
            'can_review': True,
            'reviewing_changesets': ChangeSet.objects.filter(
                assigned_to=user, state='review'
            ).order_by('-last_update'),
            'to_review_changesets': ChangeSet.objects.filter(
                state__in=('proposed', 'reproposed'),
            ).order_by('-last_update'),
            'all_recent_changesets': ChangeSet.objects.exclude(state='unproposed').order_by('-last_update')[:20],
        })

    return render(request, 'editor/user.html', ctx)
예제 #3
0
파일: api.py 프로젝트: nomoketo/c3nav-new
    def direct_editing(self, request, *args, **kwargs):
        # django-rest-framework doesn't automatically do this for logged out requests
        SessionAuthentication().enforce_csrf(request)

        if not ChangeSet.can_direct_edit(request):
            raise PermissionDenied(_('You don\'t have the permission to activate direct editing.'))

        changeset = ChangeSet.get_for_request(request)
        if changeset.pk is not None:
            raise PermissionDenied(_('You cannot activate direct editing if you have an active changeset.'))

        request.session['direct_editing'] = True

        return Response({
            'success': True,
        })
예제 #4
0
파일: api.py 프로젝트: johnjohndoe/c3nav
    def direct_editing(self, request, *args, **kwargs):
        # django-rest-framework doesn't automatically do this for logged out requests
        SessionAuthentication().enforce_csrf(request)

        if not ChangeSet.can_direct_edit(request):
            raise PermissionDenied(_('You don\'t have the permission to activate direct editing.'))

        changeset = ChangeSet.get_for_request(request)
        if changeset.pk is not None:
            raise PermissionDenied(_('You cannot activate direct editing if you have an active changeset.'))

        request.session['direct_editing'] = True

        return Response({
            'success': True,
        })