Created
July 11, 2022 01:06
-
-
Save bennett39/254e152e6cfe5fd527881eeafdaa77b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render, redirect | |
from django.views import View | |
from .models import Calculation | |
from .tasks import fibonacci_task | |
class FibonacciView(View): | |
def get(self, request): | |
"""Show a form to start a calculation""" | |
return render(request, 'fib/start.html') | |
def post(self, request): | |
"""Process a form & start a Fibonacci calculation""" | |
n = request.POST['fib_number'] | |
calculation = Calculation.objects.create( | |
equation=Calculation.EQUATION_FIBONACCI, | |
input=int(n), | |
status=Calculation.STATUS_PENDING, | |
) | |
fibonacci_task.delay(calculation.id) | |
return redirect('fibonacci_list') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment