2019-02-11 22:52:48 +01:00
|
|
|
from django.shortcuts import render
|
2020-01-27 19:58:25 +01:00
|
|
|
from django.shortcuts import get_object_or_404, redirect
|
2020-01-15 20:58:10 +01:00
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from fiches.models import Profile
|
2020-01-15 21:27:37 +01:00
|
|
|
from fiches.forms import ProfileForm, SearchForm
|
2020-01-15 20:58:10 +01:00
|
|
|
from django.urls import reverse
|
2019-02-11 22:52:48 +01:00
|
|
|
|
2020-01-27 19:58:25 +01:00
|
|
|
|
2020-01-15 20:58:10 +01:00
|
|
|
@login_required
|
2020-01-27 19:58:25 +01:00
|
|
|
def fiche(request, id):
|
|
|
|
profile = get_object_or_404(Profile, id=id)
|
|
|
|
return render(request, 'fiches/fiche.html', {"profile": profile})
|
2019-04-08 21:47:50 +02:00
|
|
|
|
|
|
|
|
2020-01-15 20:58:10 +01:00
|
|
|
@login_required
|
|
|
|
def fiche_modif(request):
|
2020-01-27 19:58:25 +01:00
|
|
|
profile = request.user.profile
|
|
|
|
if request.method == 'POST':
|
|
|
|
form = ProfileForm(request.POST, instance=profile)
|
|
|
|
if form.is_valid():
|
|
|
|
form.save()
|
|
|
|
return redirect(reverse('fiche', args=(profile.id,)))
|
|
|
|
else:
|
|
|
|
form = ProfileForm(instance=profile)
|
|
|
|
|
|
|
|
return render(request, 'fiches/fiches_modif.html', {"form": form})
|
2020-01-15 20:58:10 +01:00
|
|
|
|
2020-01-15 21:27:37 +01:00
|
|
|
|
2020-02-08 11:02:39 +01:00
|
|
|
|
2020-01-15 21:27:37 +01:00
|
|
|
@login_required
|
2020-02-08 11:02:39 +01:00
|
|
|
def home(request):
|
2020-01-27 19:58:25 +01:00
|
|
|
if request.method == 'POST':
|
|
|
|
form = SearchForm(request.POST)
|
|
|
|
if form.is_valid():
|
2020-02-08 11:02:39 +01:00
|
|
|
result = Profile.objects.filter(full_name__icontains=form.cleaned_data['name'])
|
|
|
|
return render(request,'fiches/home.html',{"form":form, "result":result})
|
|
|
|
|
2020-01-27 19:58:25 +01:00
|
|
|
else:
|
|
|
|
form = SearchForm()
|
2020-02-08 11:02:39 +01:00
|
|
|
return render(request,'fiches/home.html',{"form":form})
|