Ejemplo n.º 1
0
def edit_installationType(request, installationTypeid = None):
    logger = logging.getLogger('webapp')
    logger.info('run edit_installationType run')

    if(installationTypeid):
        t = InstallationType.objects.get(id=int(installationTypeid))

        if request.method == 'POST':
            #update record with submitted values

            logger.info('run submit_edit run')
            form = InstallationTypeForm(request.POST, instance=t)

            if form.is_valid():
                logger.info('updating installationtype')
                logger.info(form.cleaned_data)
                t.name = form.cleaned_data['name']

                t.save()

                return HttpResponseRedirect('/installationtypes/')

            return render(request, 'installation/installationtype_detail.html', {'form': form, 'action':'/installationtype/' + installationTypeid + '/', 'http_method':'POST'})
        else:
            #load record to allow edition

            form = InstallationTypeForm(instance=t)
            return render(request, 'installation/installationtype_detail.html', {'form': form, 'action':'/installationtype/' + installationTypeid + '/', 'http_method':'POST'})
    else:
        return HttpResponseRedirect('/installationtypes/')
Ejemplo n.º 2
0
def handle_installationType(request):
    logger = logging.getLogger('webapp')
    logger.info('run handle_installationType run')

    if request.method == 'POST':

        form = InstallationTypeForm(request.POST)

        if form.is_valid():
            t = InstallationType()
            t.name = form.cleaned_data['name']

            t.save()

            return HttpResponseRedirect('/installationtypes/')

    else:
        form = InstallationTypeForm()
    return render(request, 'installation/installationtype_detail.html', {'form': form, 'action':'/installationtype/', 'http_method':'POST'})