Commit 049de075 authored by nikkastra's avatar nikkastra

homepage done

parent 16f895ac
from django import forms from django import forms
class IndexCardForm(forms.Form): class FirstName(forms.Form):
name = forms.CharField(label="Hello! What is your name? ", max_length=100) 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 * ...@@ -5,7 +5,7 @@ from .views import *
urlpatterns = [ urlpatterns = [
path('', HomePageView.as_view(), name='index'), path('', HomePageView.as_view(), name='index'),
path('home', index_card_view, name = 'home'), path('home', home, name = 'home'),
path('profile', profile, name = 'profile'), path('profile', profile, name = 'profile'),
path('key', key, name = 'key'), path('key', key, name = 'key'),
path('this_week', thisweek, name = 'thisweek'), path('this_week', thisweek, name = 'thisweek'),
......
...@@ -7,8 +7,10 @@ from django.views.generic.detail import DetailView ...@@ -7,8 +7,10 @@ from django.views.generic.detail import DetailView
from .forms import * from .forms import *
from .models import * from .models import *
name_dict = {} name_dict = {}
class NameListView(ListView): class NameListView(ListView):
model = Name model = Name
...@@ -19,20 +21,25 @@ class NameDetailView(DetailView): ...@@ -19,20 +21,25 @@ class NameDetailView(DetailView):
class HomePageView(View): class HomePageView(View):
def get(self, request): def get(self, request):
form = IndexCardForm() form = FirstName()
return render(request, 'index.html', {'form': form}) return render(request, 'index.html', {'form': form})
def index_card_view(request): def home(request):
global name_dict if len(name_dict)==1:
if len(name_dict) == 1:
return render(request, 'index.html', name_dict) return render(request, 'index.html', name_dict)
elif request.method == 'POST': elif request.method == 'POST':
form = IndexCardForm(request.POST) form = FirstName(request.POST)
if form.is_valid(): if form.is_valid():
name_dict['name'] = form.cleaned_data['name'] name_dict['name'] = form.cleaned_data['name']
return render(request,'index.html', name_dict) 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: else:
form = IndexCardForm() form = FirstName()
return render(request, 'index.html', {'form': form}) 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