Reorder files
This commit is contained in:
parent
8f3b1f817a
commit
d9a41f82bb
16 changed files with 59 additions and 13 deletions
41
notes/views.py
Normal file
41
notes/views.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
from django.http import HttpResponse
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
from django.shortcuts import render, redirect
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import transaction, connection
|
||||
|
||||
# from notes.models import Note
|
||||
|
||||
@login_required()
|
||||
def index(request):
|
||||
user = request.user
|
||||
|
||||
# notes = Note.objects.filter(owner=user)
|
||||
# notes_list = [ { 'time' : note.time, 'body' : note.body } for note in notes ]
|
||||
# notes_list.sort(key=lambda note: note['time'])
|
||||
|
||||
# return render(request, 'index.html', { 'notes' : notes_list})
|
||||
return render(request, 'index.html')
|
||||
|
||||
def login_view(request):
|
||||
if request.method == 'GET':
|
||||
return render(request, 'login.html')
|
||||
elif request.method == 'POST':
|
||||
username = request.POST.get('username')
|
||||
password = request.POST.get('password')
|
||||
|
||||
user = authenticate(username=username, password=password)
|
||||
|
||||
if user is not None:
|
||||
login(request, user)
|
||||
return redirect("index")
|
||||
else:
|
||||
return render(request, 'login.html', { 'login_failed' : True })
|
||||
return redirect("index")
|
||||
|
||||
def logout_view(request):
|
||||
if request.method == 'POST':
|
||||
logout(request)
|
||||
return redirect("index")
|
Reference in a new issue