示例#1
0
def location_edit(request, location_id, response_format='html'):
    "Location edit page"
    location = get_object_or_404(Location, pk=location_id)
    if not request.user.profile.has_permission(location, mode="w"):
        return user_denied(
            request,
            message="You don't have write access to this Location",
            response_format=response_format)

    if request.POST:
        if 'cancel' not in request.POST:
            form = LocationForm(request.user.profile,
                                None,
                                request.POST,
                                instance=location)
            if form.is_valid():
                location = form.save(request)
                return HttpResponseRedirect(
                    reverse('identities_location_view', args=[location.id]))
        else:
            return HttpResponseRedirect(
                reverse('identities_location_view', args=[location.id]))
    else:
        form = LocationForm(request.user.profile, None, instance=location)

    context = _get_default_context(request)
    context.update({'location': location, 'form': form})

    return render_to_response('identities/location_edit',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#2
0
文件: views.py 项目: tovmeod/anaf
def location_edit(request, location_id, response_format='html'):
    "Location edit page"
    location = get_object_or_404(Location, pk=location_id)
    if not request.user.profile.has_permission(location, mode="w"):
        return user_denied(request, message="You don't have write access to this Location",
                           response_format=response_format)

    if request.POST:
        if 'cancel' not in request.POST:
            form = LocationForm(
                request.user.profile, None, request.POST, instance=location)
            if form.is_valid():
                location = form.save(request)
                return HttpResponseRedirect(reverse('identities_location_view', args=[location.id]))
        else:
            return HttpResponseRedirect(reverse('identities_location_view', args=[location.id]))
    else:
        form = LocationForm(
            request.user.profile, None, instance=location)

    context = _get_default_context(request)
    context.update({'location': location,
                    'form': form})

    return render_to_response('identities/location_edit', context,
                              context_instance=RequestContext(request), response_format=response_format)
示例#3
0
def location_add(request, response_format='html'):
    "New location form"

    if request.POST:
        if 'cancel' not in request.POST:
            location = Location()
            form = LocationForm(request.user.profile,
                                None,
                                request.POST,
                                instance=location)
            if form.is_valid():
                location = form.save()
                location.set_user_from_request(request)
                return HttpResponseRedirect(
                    reverse('identities_location_view', args=[location.id]))
        else:
            return HttpResponseRedirect(reverse('identities_index'))
    else:
        form = LocationForm(request.user.profile, None)

    context = _get_default_context(request)
    context.update({'form': form})

    return render_to_response('identities/location_add',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#4
0
文件: views.py 项目: tovmeod/anaf
def location_add(request, response_format='html'):
    "New location form"

    if request.POST:
        if 'cancel' not in request.POST:
            location = Location()
            form = LocationForm(
                request.user.profile, None, request.POST, instance=location)
            if form.is_valid():
                location = form.save()
                location.set_user_from_request(request)
                return HttpResponseRedirect(reverse('identities_location_view', args=[location.id]))
        else:
            return HttpResponseRedirect(reverse('identities_index'))
    else:
        form = LocationForm(request.user.profile, None)

    context = _get_default_context(request)
    context.update({'form': form})

    return render_to_response('identities/location_add', context,
                              context_instance=RequestContext(request), response_format=response_format)