Example #1
0
def location_new(request):
    if request.method == 'POST':
        form = forms.LocationEditForm(request.POST, instance=Location())
        if form.is_valid():
            form.save()
            messages.success(request, 'Location created.')
            return redirect('manage:locations')
    else:
        form = forms.LocationEditForm()
    return render(request, 'manage/location_new.html', {'form': form})
Example #2
0
def location_edit(request, id):
    location = get_object_or_404(Location, id=id)

    if request.method == 'POST' and request.POST.get('delete'):
        LocationDefaultEnvironment.objects.get(id=request.POST.get('delete'),
                                               location=location).delete()
        messages.info(request, 'Configuration deleted.')
        return redirect('manage:location_edit', location.id)

    if request.method == 'POST' and not request.POST.get('default'):
        form = forms.LocationEditForm(request.POST, instance=location)
        if form.is_valid():
            form.save()
            messages.info(request, 'Location "%s" saved.' % location)
            return redirect('manage:locations')
    else:
        form = forms.LocationEditForm(instance=location)

    if request.method == 'POST' and request.POST.get('default'):

        default_environment_form = forms.LocationDefaultEnvironmentForm(
            request.POST)
        if default_environment_form.is_valid():
            fc = default_environment_form.cleaned_data

            if LocationDefaultEnvironment.objects.filter(
                    location=location, privacy=fc['privacy']):
                # there can only be one of them
                lde = LocationDefaultEnvironment.objects.get(
                    location=location, privacy=fc['privacy'])
                lde.template = fc['template']
            else:
                lde = LocationDefaultEnvironment.objects.create(
                    location=location,
                    privacy=fc['privacy'],
                    template=fc['template'])
            lde.template_environment = fc['template_environment']
            lde.save()
            messages.info(request, 'Default location environment saved.')
            return redirect('manage:location_edit', location.id)
    else:
        default_environment_form = forms.LocationDefaultEnvironmentForm()

    context = {
        'form': form,
        'location': location,
        'default_environment_form': default_environment_form
    }

    context['location_default_environments'] = (
        LocationDefaultEnvironment.objects.filter(location=location).order_by(
            'privacy', 'template'))

    return render(request, 'manage/location_edit.html', context)
Example #3
0
def location_edit(request, id):
    location = Location.objects.get(id=id)
    if request.method == 'POST':
        form = forms.LocationEditForm(request.POST, instance=location)
        if form.is_valid():
            form.save()
            messages.info(request, 'Location "%s" saved.' % location)
            return redirect('manage:locations')
    else:
        form = forms.LocationEditForm(instance=location)
    return render(request, 'manage/location_edit.html', {'form': form,
                                                         'location': location})