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',
|
||||
|
|
|
@ -24,4 +24,4 @@ urlpatterns = [
|
|||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
|
|
@ -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,21 +1,23 @@
|
|||
from django import forms
|
||||
from fiches.models import Profile
|
||||
|
||||
|
||||
class ProfileForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Profile
|
||||
fields = [
|
||||
"full_name",
|
||||
"nickname",
|
||||
"picture",
|
||||
"department",
|
||||
"promotion",
|
||||
"birth_date",
|
||||
"thurne",
|
||||
"text_field",
|
||||
"printing",
|
||||
"keep_me"
|
||||
]
|
||||
class Meta:
|
||||
model = Profile
|
||||
fields = [
|
||||
"full_name",
|
||||
"nickname",
|
||||
"picture",
|
||||
"department",
|
||||
"promotion",
|
||||
"birth_date",
|
||||
"thurne",
|
||||
"text_field",
|
||||
"printing",
|
||||
"keep_me"
|
||||
]
|
||||
|
||||
|
||||
class SearchForm(forms.Form):
|
||||
name = forms.CharField(label='search name', max_length=1023)
|
||||
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,66 +1,66 @@
|
|||
{% extends "fiches/base.html" %}
|
||||
{% block content %}
|
||||
<div>
|
||||
<div style="width:200px;height:200px;overflow:hidden;" >
|
||||
<img src="{{ profile.picture.url }}" width="200px" height="auto"/>
|
||||
</div>
|
||||
<div>
|
||||
<h3>{{ profile.full_name }}
|
||||
({{ profile.promotion }})
|
||||
{% if profile.nickname %}
|
||||
<em>alias:</em>{{ profile.nickname }})</h3>
|
||||
{% endif %}
|
||||
<p>
|
||||
{% if profile.department.exists %}
|
||||
<em>Département{{ profile.department.count|pluralize}} :</em>
|
||||
{% endif %}
|
||||
{% for dep in profile.department.all %}
|
||||
{{ dep }}
|
||||
{% if not forloop.last %}
|
||||
,
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if profile.birth_date %}
|
||||
</p>
|
||||
<p>
|
||||
{% if profile.phone_set.exists %}
|
||||
<em>Téléphone{{ profile.phone_set.count|pluralize}} :</em>
|
||||
{% endif %}
|
||||
{% for ph in profile.phone_set.all %}
|
||||
{{ ph }}
|
||||
{% if not forloop.last %}
|
||||
,<br/>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</p>
|
||||
<p>
|
||||
{% if profile.social_set.exists %}
|
||||
<em>{{ profile.social_set.count|pluralize:"Réseau social,Réseaux sociaux"}} :</em>
|
||||
{% endif %}
|
||||
{% for ph in profile.social_set.all %}
|
||||
{{ ph }}
|
||||
{% if not forloop.last %}
|
||||
,<br/>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</p>
|
||||
<p>
|
||||
<em>Date de naissance :</em> {{ profile.birth_date }}
|
||||
</p>
|
||||
{% endif %}
|
||||
<div>
|
||||
<div style="width:200px;height:200px;overflow:hidden;" >
|
||||
<img src="{{ profile.picture.url }}" width="200px" height="auto"/>
|
||||
</div>
|
||||
<div>
|
||||
<h3>{{ profile.full_name }}
|
||||
({{ profile.promotion }})
|
||||
{% if profile.nickname %}
|
||||
<em>alias:</em>{{ profile.nickname }})</h3>
|
||||
{% endif %}
|
||||
<p>
|
||||
{% if profile.department.exists %}
|
||||
<em>Département{{ profile.department.count|pluralize}} :</em>
|
||||
{% endif %}
|
||||
{% for dep in profile.department.all %}
|
||||
{{ dep }}
|
||||
{% if not forloop.last %}
|
||||
,
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if profile.birth_date %}
|
||||
</p>
|
||||
<p>
|
||||
{% if profile.phone_set.exists %}
|
||||
<em>Téléphone{{ profile.phone_set.count|pluralize}} :</em>
|
||||
{% endif %}
|
||||
{% for ph in profile.phone_set.all %}
|
||||
{{ ph }}
|
||||
{% if not forloop.last %}
|
||||
,<br/>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</p>
|
||||
<p>
|
||||
{% if profile.social_set.exists %}
|
||||
<em>{{ profile.social_set.count|pluralize:"Réseau social,Réseaux sociaux"}} :</em>
|
||||
{% endif %}
|
||||
{% for ph in profile.social_set.all %}
|
||||
{{ ph }}
|
||||
{% if not forloop.last %}
|
||||
,<br/>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</p>
|
||||
<p>
|
||||
<em>Date de naissance :</em> {{ profile.birth_date }}
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if profile.thurne %}
|
||||
<p>
|
||||
<em>Thurne :</em> {{ profile.thurne }}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
{% if profile.text_field %}
|
||||
<p>
|
||||
<b>Champ libre :</b> {{ profile.text_field }}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if profile.thurne %}
|
||||
<p>
|
||||
<em>Thurne :</em> {{ profile.thurne }}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
{% if profile.text_field %}
|
||||
<p>
|
||||
<b>Champ libre :</b> {{ profile.text_field }}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -1,11 +1,11 @@
|
|||
{% extends "fiches/base.html" %}
|
||||
{% block content %}
|
||||
<h2>Modifier ma page d'annuaire</h2>
|
||||
<form method="post" action="">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Enregistrer">
|
||||
</form>
|
||||
<h2>Modifier ma page d'annuaire</h2>
|
||||
<form method="post" action="">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Enregistrer">
|
||||
</form>
|
||||
|
||||
|
||||
{% endblock %}
|
|
@ -1,21 +1,21 @@
|
|||
{% extends "fiches/base.html" %}
|
||||
{% block content %}
|
||||
|
||||
<h2> Chercher quelqu'un.e dans l'annuaire </h2>
|
||||
<form method='post' action="">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Recherche">
|
||||
</form>
|
||||
<h2> Chercher quelqu'un.e dans l'annuaire </h2>
|
||||
<form method='post' action="">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Recherche">
|
||||
</form>
|
||||
|
||||
<div>
|
||||
<ul>
|
||||
{% for profile in result %}
|
||||
<li><a href="{% url 'fiche' profile.id %}">{{profile.full_name}} {{profile.departement}}
|
||||
</a> </li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div>
|
||||
<ul>
|
||||
{% for profile in result %}
|
||||
<li><a href="{% url 'fiche' profile.id %}">{{profile.full_name}} {{profile.departement}}
|
||||
</a> </li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
|
@ -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,38 +1,40 @@
|
|||
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
|
||||
def fiche_modif(request):
|
||||
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,)))
|
||||
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)
|
||||
|
||||
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})
|
||||
else:
|
||||
form = SearchForm()
|
||||
return render(request,'fiches/search.html',{"form":form})
|
||||
if request.method == 'POST':
|
||||
form = SearchForm(request.POST)
|
||||
if form.is_valid():
|
||||
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})
|
||||
|
|
Loading…
Reference in a new issue