I get this error: “RecursionError at / maximum recursion depth exceeded”
This is my view:
@login_required
def show_weekdays(request):
shifts = Shift.objects.all().order_by('start_date')
weeks = []
current_week = None
previous_week_number = None
for shift in shifts:
week_number = shift.start_date.isocalendar()[1]
weekday = shift.start_date.weekday()
if previous_week_number is not None and week_number != previous_week_number:
weeks.append(current_week)
if week_number != previous_week_number:
current_week = {'week_number': week_number, 'days': []}
current_day = next((day for day in current_week['days'] if day['weekday'] == weekday), None)
if current_day is None:
current_day = {'weekday': weekday, 'start_date': shift.start_date, 'shifts': []}
current_week['days'].append(current_day)
current_day['shifts'].append(shift)
previous_week_number = week_number
if current_week:
weeks.append(current_week)
user_group = None
if request.user.is_authenticated:
if request.user.is_superuser:
user_group = 'admin'
elif request.user.groups.filter(name='Customer').exists():
user_group = 'customer'
else:
user_group = 'user'
context = {'weeks': weeks, 'user_group': user_group}
if request.user.is_authenticated:
if user_group == 'admin' or request.user.is_superuser:
return render(request, 'shift-layout-admin.html', context)
elif user_group == 'customer':
return render(request, 'shift-layout-customer.html', context)
else:
return render(request, 'shift-layout-user.html', context)
else:
return render(request, 'base.html', context)
This is shift-layout-admin.html:
{% extends "base.html" %}
{% block shift-layout-admin %}
{% load static %}
<p>Admin</p>
<div class="m20"><!--START PAGE-->
{% for week in weeks %}
<div class="weeknr">
<h1>Week {{ week.week_number }}</h1>
<div class="grid-container shifts">
{% for day in week.days %}
<div class="weekday day{{ day.weekday }}">
<div class="dayheader day{{ day.weekday }}">{{ day.start_date|date:'l j M Y' }}</div>
<!--START SHIFT-->
{% for shift in day.shifts %}
{% include shift.status.template_admin %}
{% endfor %}
<!--END SHIFT-->
</div>
{% endfor %}
</div>
</div>
{% endfor %}
</div><!--END PAGE-->
{% endblock %}
The debug indicates that the error is caused on this line:
<h1>Week {{ week.week_number }}</h1>
The included shift looks like this:
<!--START SHIFT-->
<div id="record-{{ shift.id }}" class="card {{ shift.status.color_admin|safe }}" onclick="{{ shift.status.onclick_admin|safe }}('{{ shift.id }}')">
<div class="inverse container-card">
<div class="date-card"><b>{{ shift.start_date|date:'D j M Y' }}</b></div>
<div class="time-card">{{ shift.start_time }} - {{ shift.end_time }}</div>
</div>
<div><b>{{ shift.function }}</b> | {{ shift.shift_title }}</div>
<div><i>{{ shift.user.first_name}} {{ shift.user.last_name }}, <b>{{ shift.user.Function_short }}</b></i></div>
<div class="flex-container sb">
<div>{{ shift.site.Short_value }} - {{ shift.site }}</div>
</div>
<div class="shiftid">{{ shift.id }}</div>
</div>
<!--END SHIFT-->
I don’t know why but I got the impression it got something to do with the background color that is defined in the css. I use rather complex styling here EG:
.blue-shift{background-color: #4B92DB;}
.blue-x-shift{background: repeating-linear-gradient( 45deg, #4B92DB, #4B92DB 10px, #a4c8ed 10px, #a4c8ed 20px );}
.orange-shift{background-color:#FF9966;}
.orange-x-shift{background: repeating-linear-gradient( 45deg, #FF9966, #FF9966 10px, #ffbf9f 10px, #ffbf9f 20px );}
.green-shift{background-color:#00A693;}
.gray-x-shift{background: repeating-linear-gradient( 45deg, #b8b8b8, #b8b8b8 10px, #d9d9d9 10px, #d9d9d9 20px );}
When I use only simple colors everything works fine.
But the error is pointing to a view/template rendering relation