from django.shortcuts import render
|
|
# from django.http import HttpResponse
|
|
from .form import CreateUserForm
|
|
|
|
|
|
# Create your views here.
|
|
#
|
|
# def form(request):
|
|
# if request.method == 'POST':
|
|
# fullname = request.POST['fullname']
|
|
# mathematics = int(request.POST['mathematics'])
|
|
# latvian_lng = int(request.POST['latvian_lng'])
|
|
# foreign_lng = int(request.POST['foreign_lng'])
|
|
# if mathematics < 40 or latvian_lng < 40 or foreign_lng < 40:
|
|
# return HttpResponse(f'{fullname} can not apply to university')
|
|
# else:
|
|
# return HttpResponse(f'Hello, {fullname}! You can apply to our university. Your grades: Mathematics: {mathematics}, Latviesu vld: {latvian_lng}, Svesvaloda: {foreign_lng}')
|
|
#
|
|
# return render(
|
|
# request,
|
|
# template_name='form.html',
|
|
# )
|
|
#
|
|
# def add_visit(request):
|
|
#
|
|
# if request.method == 'POST':
|
|
#
|
|
# context = {
|
|
# 'visitor': request.POST['visitor'],
|
|
# 'date_time': request.POST['date_time'],
|
|
# 'reason': request.POST['reason'],
|
|
# }
|
|
#
|
|
# return render(
|
|
# request,
|
|
# template_name='visit.html',
|
|
# context=context,
|
|
# )
|
|
#
|
|
# return render(
|
|
# request,
|
|
# template_name='visit_form.html',
|
|
# )
|
|
#
|
|
# def add_user(request):
|
|
#
|
|
# if request.method == 'POST':
|
|
#
|
|
# context = {
|
|
# 'username': request.POST['username'],
|
|
# 'email': request.POST['email'],
|
|
# }
|
|
#
|
|
# return render(
|
|
# request,
|
|
# template_name='add_user.html',
|
|
# context=context,
|
|
# )
|
|
#
|
|
# return render(
|
|
# request,
|
|
# template_name='add_user_form.html',
|
|
# )
|
|
|
|
def adduser(request):
|
|
|
|
form = CreateUserForm(request.POST or None)
|
|
|
|
if request.method == 'POST':
|
|
|
|
if form.is_valid():
|
|
|
|
user = User(
|
|
username=form.cleaned_data['username'],
|
|
email=form.cleaned_data['email'],
|
|
)
|
|
|
|
users.append(user)
|
|
|
|
context = {
|
|
'user': user,
|
|
}
|
|
|
|
return render(
|
|
request,
|
|
template_name='user.html',
|
|
context=context,
|
|
)
|
|
|
|
context = {
|
|
'form': form,
|
|
}
|
|
|
|
return render(
|
|
request,
|
|
template_name='adduser.html',
|
|
context=context,
|
|
)
|