flake8
This commit is contained in:
parent
35720d3d96
commit
8a2afe3893
5 changed files with 26 additions and 18 deletions
|
@ -22,9 +22,15 @@ class ProfileForm(forms.ModelForm):
|
|||
class SearchForm(forms.Form):
|
||||
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)
|
||||
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']):
|
||||
raise forms.ValidationError(('Tous les champs sont vides'), code='invalid')
|
||||
if (
|
||||
not cleaned_data['name']
|
||||
and not cleaned_data['year']
|
||||
and not cleaned_data['department']
|
||||
):
|
||||
raise forms.ValidationError(('Tous les champs sont vides'), code='invalid')
|
||||
|
|
|
@ -32,7 +32,7 @@ class Profile(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return self.full_name
|
||||
|
||||
|
||||
|
||||
class Department(models.Model):
|
||||
name = models.CharField(max_length=255, verbose_name=_("nom du département"))
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
<h2> Anniversaires </h2>
|
||||
|
||||
|
||||
<div>
|
||||
<ul>
|
||||
{% for profile in result %}
|
||||
|
@ -13,5 +12,4 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
|
@ -8,7 +8,6 @@
|
|||
<input type="submit" value="Recherche">
|
||||
</form>
|
||||
|
||||
|
||||
<div>
|
||||
<ul>
|
||||
{% for profile in result %}
|
||||
|
@ -18,5 +17,4 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
|
@ -25,30 +25,36 @@ def fiche_modif(request):
|
|||
return redirect(reverse('fiche', args=(profile.id,)))
|
||||
else:
|
||||
form = ProfileForm(instance=profile)
|
||||
|
||||
return render(request, 'fiches/fiches_modif.html', {"form": form})
|
||||
|
||||
|
||||
|
||||
@login_required
|
||||
def home(request):
|
||||
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})
|
||||
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}
|
||||
)
|
||||
|
||||
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))
|
||||
for i in range(1,7):
|
||||
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))
|
||||
return render(request,'fiches/birthday.html',{"result":result})
|
||||
|
||||
result += list(Profile.objects.filter(
|
||||
birth_date__day=today.day, birth_date__month=today.month)
|
||||
)
|
||||
return render(request, 'fiches/birthday.html', {"result": result})
|
||||
|
|
Loading…
Add table
Reference in a new issue