Merge branch 'ju' into 'master'
Ju Closes #11 See merge request klub-dev-ens/annuaire!5
This commit is contained in:
commit
67a553382a
12 changed files with 93 additions and 31 deletions
|
@ -36,6 +36,7 @@ INSTALLED_APPS = [
|
|||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'django_cas_ng',
|
||||
'fiches'
|
||||
]
|
||||
|
||||
|
@ -67,6 +68,11 @@ TEMPLATES = [
|
|||
},
|
||||
]
|
||||
|
||||
AUTHENTICATION_BACKENDS = (
|
||||
'django.contrib.auth.backends.ModelBackend',
|
||||
'django_cas_ng.backends.CASBackend',
|
||||
)
|
||||
|
||||
WSGI_APPLICATION = 'annuaire.wsgi.application'
|
||||
|
||||
|
||||
|
@ -123,3 +129,9 @@ STATIC_URL = '/static/'
|
|||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||
|
||||
MEDIA_URL = '/media/'
|
||||
|
||||
CAS_SERVER_URL = 'https://cas.eleves.ens.fr/'
|
||||
|
||||
CAS_VERSION = "2"
|
||||
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
||||
|
|
|
@ -18,12 +18,15 @@ from django.contrib import admin
|
|||
from django.urls import path, include
|
||||
from django.conf.urls.static import static
|
||||
from fiches.views import home, birthday
|
||||
import django_cas_ng.views as cas_views
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('fiche/', include('fiches.urls')),
|
||||
path('', home, name='home'),
|
||||
path('birthday', birthday, name='birthday')
|
||||
path('birthday', birthday, name='birthday'),
|
||||
path('login', cas_views.LoginView.as_view(), name='cas_ng_login'),
|
||||
path('logout', cas_views.LogoutView.as_view(), name='cas_ng_logout'),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
|
|
|
@ -2,4 +2,4 @@ from django.apps import AppConfig
|
|||
|
||||
|
||||
class FichesConfig(AppConfig):
|
||||
name = 'fiches'
|
||||
name = "fiches"
|
||||
|
|
|
@ -15,22 +15,22 @@ class ProfileForm(forms.ModelForm):
|
|||
"thurne",
|
||||
"text_field",
|
||||
"printing",
|
||||
"keep_me"
|
||||
"keep_me",
|
||||
]
|
||||
|
||||
|
||||
class SearchForm(forms.Form):
|
||||
name = forms.CharField(label='Nom/Surnom', max_length=1023, required=False)
|
||||
year = forms.IntegerField(label='Promotion', required=False)
|
||||
name = forms.CharField(label="Nom/Surnom", max_length=1023, required=False)
|
||||
year = forms.IntegerField(label="Promotion", required=False)
|
||||
department = forms.ModelMultipleChoiceField(
|
||||
queryset=Department.objects.all(), required=False
|
||||
)
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
if (
|
||||
not cleaned_data['name']
|
||||
and not cleaned_data['year']
|
||||
and not cleaned_data['department']
|
||||
not cleaned_data["name"]
|
||||
and not cleaned_data["year"]
|
||||
and not cleaned_data["department"]
|
||||
):
|
||||
raise forms.ValidationError(('Tous les champs sont vides'), code='invalid')
|
||||
raise forms.ValidationError(("Tous les champs sont vides"), code="invalid")
|
||||
|
|
20
fiches/migrations/0004_auto_20200212_2130.py
Normal file
20
fiches/migrations/0004_auto_20200212_2130.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 2.2.9 on 2020-02-12 21:30
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('fiches', '0003_auto_20200108_2306'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='profile',
|
||||
name='user',
|
||||
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='profile', to=settings.AUTH_USER_MODEL, verbose_name='utilisateur'),
|
||||
),
|
||||
]
|
|
@ -33,6 +33,9 @@ class Profile(models.Model):
|
|||
def __str__(self):
|
||||
return self.full_name
|
||||
|
||||
def birthday():
|
||||
return self.birth_date.strftime("%d%m")
|
||||
|
||||
|
||||
class Department(models.Model):
|
||||
name = models.CharField(max_length=255, verbose_name=_("nom du département"))
|
||||
|
|
|
@ -29,6 +29,11 @@
|
|||
<a href='{% url "fiche_modif" %}'> Modifier sa fiche d'annuaire </a>
|
||||
<a href='{% url "fiche" request.user.profile.id %}'> Consulter sa fiche d'annuaire </a>
|
||||
<a href='{% url "birthday" %}'> Anniversaires à venir </a>
|
||||
{% if user.is_authenticated %}
|
||||
<a href='{% url "cas_ng_logout" %}'> Se déconnecter</a>
|
||||
{% else %}
|
||||
<a href='{% url "cas_ng_login" %}'> Se connecter</a>
|
||||
{% endif %}
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
|
|
|
@ -12,4 +12,5 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
6
fiches/templates/fiches/mail/mail_modif.txt
Normal file
6
fiches/templates/fiches/mail/mail_modif.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
Bonjour {{profile.full_name}},
|
||||
|
||||
Ta fiche annuaire a été modifiée !
|
||||
|
||||
Cordialement,
|
||||
le Klub Dev
|
|
@ -2,6 +2,6 @@ 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("<int:id>", views.fiche, name="fiche"),
|
||||
path("edit", views.fiche_modif, name="fiche_modif"),
|
||||
]
|
||||
|
|
|
@ -7,54 +7,65 @@ from django.urls import reverse
|
|||
from django.db.models import Q
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
from django.core.mail import send_mail
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
|
||||
@login_required
|
||||
def fiche(request, id):
|
||||
profile = get_object_or_404(Profile, id=id)
|
||||
return render(request, 'fiches/fiche.html', {"profile": profile})
|
||||
return render(request, "fiches/fiche.html", {"profile": profile})
|
||||
|
||||
|
||||
@login_required
|
||||
def fiche_modif(request):
|
||||
profile = request.user.profile
|
||||
if request.method == 'POST':
|
||||
if request.method == "POST":
|
||||
form = ProfileForm(request.POST, instance=profile)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect(reverse('fiche', args=(profile.id,)))
|
||||
send_mail(
|
||||
"Fiche annuaire modifée",
|
||||
render_to_string("fiches/mail/mail_modif.txt", {"profile": profile}),
|
||||
"klub-dev@ens.psl.eu",
|
||||
["{}@clipper.ens.psl.eu".format(request.user.username)],
|
||||
fail_silently=False,
|
||||
)
|
||||
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 home(request):
|
||||
if request.method == 'POST':
|
||||
if request.method == "POST":
|
||||
form = SearchForm(request.POST)
|
||||
if form.is_valid():
|
||||
result = Profile.objects.filter(
|
||||
Q(full_name__icontains=form.cleaned_data['name'])
|
||||
| Q(nickname__icontains=form.cleaned_data['name'])
|
||||
)
|
||||
return render(
|
||||
request, 'fiches/home.html', {"form": form, "result": result}
|
||||
Q(full_name__icontains=form.cleaned_data["name"])
|
||||
| Q(nickname__icontains=form.cleaned_data["name"])
|
||||
)
|
||||
return render(request, "fiches/home.html", {"form": form, "result": result})
|
||||
|
||||
else:
|
||||
form = SearchForm()
|
||||
return render(request, 'fiches/home.html', {"form": form})
|
||||
return render(request, "fiches/home.html", {"form": form})
|
||||
|
||||
|
||||
@login_required
|
||||
def birthday(request):
|
||||
today = timezone.now()
|
||||
result = list(Profile.objects.filter(
|
||||
birth_date__day=today.day, birth_date__month=today.month
|
||||
))
|
||||
result = list(
|
||||
Profile.objects.filter(birth_date__day=today.day, birth_date__month=today.month)
|
||||
)
|
||||
for i in range(1, 7):
|
||||
today = today + timedelta(days=1)
|
||||
result += list(Profile.objects.filter(
|
||||
birth_date__day=today.day, birth_date__month=today.month)
|
||||
result += list(
|
||||
Profile.objects.filter(
|
||||
birth_date__day=today.day, birth_date__month=today.month
|
||||
)
|
||||
)
|
||||
return render(request, 'fiches/birthday.html', {"result": result})
|
||||
return render(request, "fiches/birthday.html", {"result": result})
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
django==2.2.*
|
||||
Pillow
|
||||
Pillow
|
||||
django_cas_ng
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue