diff --git a/annuaire/settings.py b/annuaire/settings.py index 32af7e0..657cae3 100644 --- a/annuaire/settings.py +++ b/annuaire/settings.py @@ -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', @@ -121,4 +122,4 @@ STATIC_URL = '/static/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') -MEDIA_URL = '/media/' \ No newline at end of file +MEDIA_URL = '/media/' diff --git a/annuaire/urls.py b/annuaire/urls.py index 0c8e865..5697b50 100644 --- a/annuaire/urls.py +++ b/annuaire/urls.py @@ -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) diff --git a/fiches/admin.py b/fiches/admin.py index 9da72e0..b059338 100644 --- a/fiches/admin.py +++ b/fiches/admin.py @@ -7,10 +7,9 @@ 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) admin.site.register(Social) admin.site.register(Mail) -admin.site.register(Address) \ No newline at end of file +admin.site.register(Address) diff --git a/fiches/forms.py b/fiches/forms.py index 2ebe60b..8a487a3 100644 --- a/fiches/forms.py +++ b/fiches/forms.py @@ -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) \ No newline at end of file + name = forms.CharField(label='search name', max_length=1023) diff --git a/fiches/models.py b/fiches/models.py index 4bd9c44..7793fdb 100644 --- a/fiches/models.py +++ b/fiches/models.py @@ -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) \ No newline at end of file + return "{} : {}".format(self.name, self.content) diff --git a/fiches/templates/fiches/fiche.html b/fiches/templates/fiches/fiche.html index a21c0be..7458f52 100644 --- a/fiches/templates/fiches/fiche.html +++ b/fiches/templates/fiches/fiche.html @@ -1,66 +1,66 @@ {% extends "fiches/base.html" %} {% block content %} -
-
- -
-
-

{{ profile.full_name }} - ({{ profile.promotion }}) - {% if profile.nickname %} - alias:{{ profile.nickname }})

- {% endif %} -

- {% if profile.department.exists %} - Département{{ profile.department.count|pluralize}} : - {% endif %} - {% for dep in profile.department.all %} - {{ dep }} - {% if not forloop.last %} - , - {% endif %} - {% endfor %} - {% if profile.birth_date %} -

-

- {% if profile.phone_set.exists %} - Téléphone{{ profile.phone_set.count|pluralize}} : - {% endif %} - {% for ph in profile.phone_set.all %} - {{ ph }} - {% if not forloop.last %} - ,
- {% endif %} - {% endfor %} -

-

- {% if profile.social_set.exists %} - {{ profile.social_set.count|pluralize:"Réseau social,Réseaux sociaux"}} : - {% endif %} - {% for ph in profile.social_set.all %} - {{ ph }} - {% if not forloop.last %} - ,
- {% endif %} - {% endfor %} -

-

- Date de naissance : {{ profile.birth_date }} -

- {% endif %} +
+
+ +
+
+

{{ profile.full_name }} + ({{ profile.promotion }}) + {% if profile.nickname %} + alias:{{ profile.nickname }})

+ {% endif %} +

+ {% if profile.department.exists %} + Département{{ profile.department.count|pluralize}} : + {% endif %} + {% for dep in profile.department.all %} + {{ dep }} + {% if not forloop.last %} + , + {% endif %} + {% endfor %} + {% if profile.birth_date %} +

+

+ {% if profile.phone_set.exists %} + Téléphone{{ profile.phone_set.count|pluralize}} : + {% endif %} + {% for ph in profile.phone_set.all %} + {{ ph }} + {% if not forloop.last %} + ,
+ {% endif %} + {% endfor %} +

+

+ {% if profile.social_set.exists %} + {{ profile.social_set.count|pluralize:"Réseau social,Réseaux sociaux"}} : + {% endif %} + {% for ph in profile.social_set.all %} + {{ ph }} + {% if not forloop.last %} + ,
+ {% endif %} + {% endfor %} +

+

+ Date de naissance : {{ profile.birth_date }} +

+ {% endif %} - {% if profile.thurne %} -

- Thurne : {{ profile.thurne }} -

- {% endif %} -
-
-
- {% if profile.text_field %} -

- Champ libre : {{ profile.text_field }} -

- {% endif %} -
-{% endblock %} \ No newline at end of file + {% if profile.thurne %} +

+ Thurne : {{ profile.thurne }} +

+ {% endif %} +
+
+
+ {% if profile.text_field %} +

+ Champ libre : {{ profile.text_field }} +

+ {% endif %} +
+{% endblock %} diff --git a/fiches/templates/fiches/fiches_modif.html b/fiches/templates/fiches/fiches_modif.html index 87bfed1..f98dd19 100644 --- a/fiches/templates/fiches/fiches_modif.html +++ b/fiches/templates/fiches/fiches_modif.html @@ -1,11 +1,11 @@ {% extends "fiches/base.html" %} {% block content %} -

Modifier ma page d'annuaire

-
- {% csrf_token %} - {{ form.as_p }} - -
+

Modifier ma page d'annuaire

+
+ {% csrf_token %} + {{ form.as_p }} + +
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/fiches/templates/fiches/search.html b/fiches/templates/fiches/search.html index 9d77921..15eb066 100644 --- a/fiches/templates/fiches/search.html +++ b/fiches/templates/fiches/search.html @@ -1,21 +1,21 @@ {% extends "fiches/base.html" %} {% block content %} -

Chercher quelqu'un.e dans l'annuaire

-
- {% csrf_token %} - {{ form.as_p }} - -
+

Chercher quelqu'un.e dans l'annuaire

+
+ {% csrf_token %} + {{ form.as_p }} + +
-
- -
+
+ +
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/fiches/tests.py b/fiches/tests.py index 7ce503c..e69de29 100644 --- a/fiches/tests.py +++ b/fiches/tests.py @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/fiches/urls.py b/fiches/urls.py index 6ee1a8c..688a581 100644 --- a/fiches/urls.py +++ b/fiches/urls.py @@ -2,7 +2,7 @@ from django.urls import path from . import views urlpatterns = [ - path('',views.fiche, name='fiche'), - path('edit',views.fiche_modif, name='fiche_modif'), - path('search',views.search, name='search') - ] \ No newline at end of file + path('', views.fiche, name='fiche'), + path('edit', views.fiche_modif, name='fiche_modif'), + path('search', views.search, name='search'), +] diff --git a/fiches/views.py b/fiches/views.py index 3d51c57..a1207a9 100644 --- a/fiches/views.py +++ b/fiches/views.py @@ -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) + + return render(request, 'fiches/fiches_modif.html', {"form": form}) - else: - form = ProfileForm(instance=profile) - - 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})