Commit 049de075 authored by nikkastra's avatar nikkastra

homepage done

parent 16f895ac
from django import forms
class IndexCardForm(forms.Form):
class FirstName(forms.Form):
name = forms.CharField(label="Hello! What is your name? ", max_length=100)
\ No newline at end of file
......@@ -5,7 +5,7 @@ from .views import *
urlpatterns = [
path('', HomePageView.as_view(), name='index'),
path('home', index_card_view, name = 'home'),
path('home', home, name = 'home'),
path('profile', profile, name = 'profile'),
path('key', key, name = 'key'),
path('this_week', thisweek, name = 'thisweek'),
......
......@@ -7,8 +7,10 @@ from django.views.generic.detail import DetailView
from .forms import *
from .models import *
name_dict = {}
class NameListView(ListView):
model = Name
......@@ -19,20 +21,25 @@ class NameDetailView(DetailView):
class HomePageView(View):
def get(self, request):
form = IndexCardForm()
form = FirstName()
return render(request, 'index.html', {'form': form})
def index_card_view(request):
global name_dict
if len(name_dict) == 1:
def home(request):
if len(name_dict)==1:
return render(request, 'index.html', name_dict)
elif request.method == 'POST':
form = IndexCardForm(request.POST)
form = FirstName(request.POST)
if form.is_valid():
name_dict['name'] = form.cleaned_data['name']
try:
if Name.objects.get(name=name_dict['name']) in Name.objects.all():
return render(request,'index.html', name_dict)
except:
person_info = Name(name=name_dict['name'], nickname='no nickname', bio='no bio')
person_info.save()
return render(request, 'index.html', name_dict)
else:
form = IndexCardForm()
form = FirstName()
return render(request, 'index.html', {'form': form})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment