use inclusion tag for country detail view (makes things much easier!

This commit is contained in:
koksnuss 2020-04-22 17:09:45 +02:00
parent 2f9c9539db
commit 2495b9ded3
3 changed files with 63 additions and 93 deletions

View File

@ -0,0 +1,24 @@
<table>
<thead>
<tr>
<td colspan="4"><a href="/coinc/{{ country.name_iso }}">{{ country.name }}</a><td>
<td colspan="2">x €</td>
<td colspan="9"></td>
</tr>
</thead>
<tbody> {% for year in country.years %}
<tr>
<td>{{ year }}</td>{% comment %}
{% for col in row.cols %}
<td>{{ col.x }}</td>
{% endfor %}
<td>{% col.special1_name %}</td>
<td>{% col.special1_x %}</td>
<td>{% col.special2_name %}</td>
<td>{% col.special2_x %}</td>
<td>{% col.special3_name %}</td>
<td>{% col.special3_x %}</td>
{% endcomment %}
</tr> {% endfor %}
</tbody>
</table>

View File

@ -17,41 +17,14 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
https://stackoverflow.com/questions/49548972/django-remove-all-empty-lines-from-template-output
-->
<html>
<head>
<meta charset="utf-8">
<title>Münzsammlung</title>
</head>
<body> {% if countrys %} {% for country in countrys %}
<table>
<thead>
<tr>
<td colspan="4"><a href="/coinc/{{ country }}">{{ countrys|name:country }}</a><td>
<td colspan="2">x €</td>
<td colspan="9"></td>
</tr>
</thead>
<tbody> {% for year in countrys|years:country %}
<tr>
<td>{{ year }}</td>{% comment %}
{% for col in row.cols %}
<td>{{ col.x }}</td>
{% endfor %}
<td>{% col.special1_name %}</td>
<td>{% col.special1_x %}</td>
<td>{% col.special2_name %}</td>
<td>{% col.special2_x %}</td>
<td>{% col.special3_name %}</td>
<td>{% col.special3_x %}</td>
{% endcomment %}
</tr> {% endfor %}
</tbody>
</table> {% endfor %} {% else %}
<p>Trage zuerst Länder im Adminbereich ein.</p> {% endif %}
<body>{% if countrys %} {% for country in countrys %}
{% show_country country %} {% endfor %} {% else %}
<p>Trage zuerst Länder im Adminbereich ein.</p>{% endif %}
</body>
</html>

View File

@ -15,29 +15,11 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# Views
# - /
# coinc Homepage: Übersicht wie in der Tabelle
# Template: index.? lädt country.? nach und ermöglicht Filtern danach
#
# - /<country> <country> kann 'de' oder 'deutschland' sein
# Landesansicht: Zeige nur ein Land wie in der Übersicht
# Template: country.?
# - Urlaubsansicht /<country>?urlaub
# Ansicht von einem Land, wobei nur die Münzen, die Fehlen hervorgehoben werden
#
# - /statistik
# Statistik: zeige Statistiken, z.B. Anwachsen der Münzen über die Zeit/Länder/etc.
# Template: statistik.?
#
# - /admin
# Adminbereich: Füge neue Länder hinzu
# Template: bereits vorhanden
from datetime import datetime
from django.http import HttpResponse
from django.template import loader
from django.template.defaultfilters import register
@ -46,27 +28,24 @@ from .models import Country
@register.filter(name='name')
def name(countrys, name_iso):
return countrys[name_iso]['name']
@register.filter(name='years')
def years(countrys, name_iso):
return countrys[name_iso]['years']
def index(request):
c = Country.objects.order_by('name')
countrys = Country.objects.order_by('name')
template = loader.get_template('coinc/index.html')
countrys = {}
import json
from datetime import datetime
year_now = datetime.now().year
context = {'countrys': countrys}
for country in c:
countrys[country.name_iso] = {
return HttpResponse(template.render(context, request))
def country(request, country):
return HttpResponse(f"Land: {country}")
@register.inclusion_tag('coinc/country.html')
def show_country(country):
year_now = datetime.now().year
c = {
'name_iso': country.name_iso,
'name': country.name,
'comment': country.comment,
'euro_member_since': country.euro_member_since,
@ -74,7 +53,7 @@ def index(request):
}
for year in range(country.euro_member_since, year_now + 1):
countrys[country.name_iso]['years'][year] = {
c['years'][year] = {
'1': 1,
'2': 2,
'5': 5,
@ -91,13 +70,7 @@ def index(request):
'200_3': 200
}
context = { 'countrys': countrys }
print(json.dumps(context, indent=4))
return HttpResponse(template.render(context, request))
def country(request, country):
return HttpResponse(f"Land: {country}")
return {'country': c}
def statistic(request):