Exemple #1
0
def tan(request):
    t = None  # initial value of result
    if request.method == 'POST':
        form = InputForm(request.POST)
        if form.is_valid():
            form = form.save(commit=False)
            radianos = form.radianos
            t = calculate_tan(radianos)
    else:
        form = InputForm()

    return render_to_response('tan.html',
            {'form': form,
             't': '%.5f' % t if isinstance(t, float) else ''
             }, context_instance=RequestContext(request))
Exemple #2
0
def tan(request):
    t = None  # initial value of result
    if request.method == 'POST':
        form = InputForm(request.POST)
        if form.is_valid():
            form = form.save(commit=False)
            radianos = form.radianos
            t = calculate_tan(radianos)
    else:
        form = InputForm()

    return render_to_response('tan.html', {
        'form': form,
        't': '%.5f' % t if isinstance(t, float) else ''
    },
                              context_instance=RequestContext(request))
Exemple #3
0
def create_edit_input(request, input_id=None):

    if request.method == 'POST':
        if input_id != None:
            thisinput = InputSubstance.objects.get(id=input_id)
            form = InputForm(request.POST, instance=thisinput)
            if form.is_valid():
                form.save()
                messages.success(request, "Input updated")
                admin = User.objects.get(username=ADMIN_USERNAME)
                addMessage = InternalMessage(
                    sender=admin,
                    title=request.user.first_name + ' made some changes to ' +
                    form.cleaned_data['name'] + '...',
                    body=request.user.first_name + ' made changes to ' +
                    form.cleaned_data['name'] +
                    '\n\nYou should probably take a look...')
                addMessage.save()
                addMessage.recipient.add(admin)
                addMessage.save()
                print 'New input message sent....'
            else:
                messages.add_message(request, settings.DISALLOWED_MESSAGE,
                                     "Hold on, somethings not right there...")
                return render(request, 'create_edit_input.html', {
                    'form': form,
                    'input': thisinput
                })
            return HttpResponseRedirect('/data/input/all')
        else:
            form = InputForm(request.POST)

            if form.is_valid():
                new_input = form.save()
                messages.success(request, "Input added")
                admin = User.objects.get(username=ADMIN_USERNAME)
                addMessage = InternalMessage(
                    sender=admin,
                    title=request.user.first_name + ' added an Input',
                    body=request.user.first_name + ' added an Input called ' +
                    form.cleaned_data['name'] +
                    '\n\nYou should look at it and add the emission factor and SimaPro ID...'
                )
                addMessage.save()
                addMessage.recipient.add(admin)
                addMessage.save()
                print 'New input message sent....'
            else:
                messages.add_message(request, settings.DISALLOWED_MESSAGE,
                                     "Hold on, somethings not right there...")
                return render(request, 'create_edit_input.html',
                              {'form': form})

            return HttpResponseRedirect('/data/input/all/')
    else:

        args = {}
        args.update(csrf(request))

        if input_id is None:
            form = InputForm()
        else:
            input_instance = InputSubstance.objects.get(id=input_id)
            args['input'] = input_instance
            form = InputForm(instance=input_instance)

        args['form'] = form
        try:
            args['dismissMessage'] = Content.objects.get(
                name='InputsOutputsMessage')
        except:
            pass

        return render(request, 'create_edit_input.html', args)