Cosmetic whitespace changes
This commit is contained in:
parent
674d41172e
commit
cac6bd390b
11 changed files with 149 additions and 137 deletions
|
@ -86,7 +86,8 @@ DATABASES = {
|
|||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
'NAME':
|
||||
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
|
|
|
@ -7,7 +7,6 @@ from fiches.models import Mail
|
|||
from fiches.models import Address
|
||||
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(Profile)
|
||||
admin.site.register(Department)
|
||||
admin.site.register(Phone)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from django import forms
|
||||
from fiches.models import Profile
|
||||
|
||||
|
||||
class ProfileForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Profile
|
||||
|
@ -17,5 +18,6 @@ class ProfileForm(forms.ModelForm):
|
|||
"keep_me"
|
||||
]
|
||||
|
||||
|
||||
class SearchForm(forms.Form):
|
||||
name = forms.CharField(label='search name', max_length=1023)
|
|
@ -6,7 +6,10 @@ from django.contrib.auth.models import User
|
|||
|
||||
class Profile(models.Model):
|
||||
user = models.OneToOneField(
|
||||
User, on_delete=models.CASCADE, verbose_name=_("utilisateur"), related_name='profile'
|
||||
User,
|
||||
on_delete=models.CASCADE,
|
||||
verbose_name=_("utilisateur"),
|
||||
related_name="profile",
|
||||
)
|
||||
full_name = models.CharField(max_length=1023, verbose_name=_("nom"))
|
||||
nickname = models.CharField(blank=True, max_length=1023, verbose_name=_("surnom"))
|
||||
|
@ -26,12 +29,14 @@ class Profile(models.Model):
|
|||
keep_me = models.BooleanField(
|
||||
default=False, verbose_name=_("conserver la fiche annuaire ?")
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.full_name
|
||||
|
||||
|
||||
class Department(models.Model):
|
||||
name = models.CharField(max_length=255, verbose_name=_("nom du département"))
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
@ -42,6 +47,7 @@ class Phone(models.Model):
|
|||
)
|
||||
name = models.CharField(max_length=255, verbose_name=_("type"))
|
||||
number = models.CharField(max_length=1023, verbose_name=_("numéro"))
|
||||
|
||||
def __str__(self):
|
||||
return "{} : {}".format(self.name, self.number)
|
||||
|
||||
|
@ -52,23 +58,28 @@ class Social(models.Model):
|
|||
)
|
||||
name = models.CharField(max_length=255, verbose_name=_("type"))
|
||||
content = models.CharField(max_length=1023, verbose_name=_("contenu"))
|
||||
|
||||
def __str__(self):
|
||||
return "{} : {}".format(self.name, self.content)
|
||||
|
||||
|
||||
class Mail(models.Model):
|
||||
profile = models.ForeignKey(
|
||||
Profile, on_delete=models.CASCADE, verbose_name=_("profil")
|
||||
)
|
||||
name = models.CharField(max_length=255, verbose_name=_("type"))
|
||||
mail = models.CharField(max_length=1023, verbose_name=_("adresse mail"))
|
||||
|
||||
def __str__(self):
|
||||
return "{} : {}".format(self.name, self.mail)
|
||||
|
||||
|
||||
class Address(models.Model):
|
||||
profile = models.ForeignKey(
|
||||
Profile, on_delete=models.CASCADE, verbose_name=_("profil")
|
||||
)
|
||||
name = models.CharField(max_length=255, verbose_name=_("type"))
|
||||
content = models.CharField(max_length=1023, verbose_name=_("adresse"))
|
||||
|
||||
def __str__(self):
|
||||
return "{} : {}".format(self.name, self.content)
|
|
@ -1,3 +0,0 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -2,7 +2,7 @@ from django.urls import path
|
|||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('<int:id>',views.fiche, name='fiche'),
|
||||
path('edit',views.fiche_modif, name='fiche_modif'),
|
||||
path('search',views.search, name='search')
|
||||
]
|
||||
path('<int:id>', views.fiche, name='fiche'),
|
||||
path('edit', views.fiche_modif, name='fiche_modif'),
|
||||
path('search', views.search, name='search'),
|
||||
]
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
from django.shortcuts import render
|
||||
from django.shortcuts import get_object_or_404,redirect
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from fiches.models import Profile
|
||||
from fiches.forms import ProfileForm, SearchForm
|
||||
from django.urls import reverse
|
||||
|
||||
# Create your views here.
|
||||
|
||||
@login_required
|
||||
def fiche(request,id):
|
||||
profile=get_object_or_404(Profile,id=id)
|
||||
return render(request,'fiches/fiche.html',{"profile":profile})
|
||||
def fiche(request, id):
|
||||
profile = get_object_or_404(Profile, id=id)
|
||||
return render(request, 'fiches/fiche.html', {"profile": profile})
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -19,20 +19,22 @@ def fiche_modif(request):
|
|||
form = ProfileForm(request.POST, instance=profile)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect(reverse('fiche',args=(profile.id,)))
|
||||
|
||||
return redirect(reverse('fiche', args=(profile.id,)))
|
||||
else:
|
||||
form = ProfileForm(instance=profile)
|
||||
|
||||
return render(request,'fiches/fiches_modif.html',{"form":form})
|
||||
return render(request, 'fiches/fiches_modif.html', {"form": form})
|
||||
|
||||
|
||||
@login_required
|
||||
def search(request):
|
||||
if request.method == 'POST':
|
||||
form = SearchForm(request.POST)
|
||||
if form.is_valid():
|
||||
result = Profile.objects.filter(full_name__icontains=form.cleaned_data['name'])
|
||||
return render(request,'fiches/search.html',{"form":form,"result":result})
|
||||
name = form.cleaned_data["name"]
|
||||
result = Profile.objects.filter(full_name__icontains=name)
|
||||
context = {"form": form, "result": result}
|
||||
return render(request, 'fiches/search.html', context)
|
||||
else:
|
||||
form = SearchForm()
|
||||
return render(request,'fiches/search.html',{"form":form})
|
||||
return render(request, 'fiches/search.html', {"form": form})
|
||||
|
|
Loading…
Reference in a new issue