#13 add etag header with last_modified function to country view
This commit is contained in:
parent
62743d3a9b
commit
aa20dc8534
@ -20,7 +20,7 @@
|
||||
|
||||
from datetime import datetime, date
|
||||
|
||||
from django.db.models import BooleanField, CASCADE, CharField, DateField, ForeignKey, Model, PositiveIntegerField, PositiveSmallIntegerField, TextField
|
||||
from django.db.models import BooleanField, CASCADE, CharField, DateField, DateTimeField, ForeignKey, Model, PositiveIntegerField, PositiveSmallIntegerField, TextField
|
||||
|
||||
|
||||
year_now = int(datetime.now().year)
|
||||
@ -85,6 +85,10 @@ class Coin(Model):
|
||||
|
||||
found_on = DateField('Eingetragen am', default=date.today)
|
||||
|
||||
date_added = DateTimeField('Hinzugefügt', auto_now_add=True)
|
||||
|
||||
date_modified = DateTimeField('Geändert', auto_now=True)
|
||||
|
||||
circulation = PositiveIntegerField('Auflage', default=0)
|
||||
|
||||
buy_only = BooleanField('Kursmünze', default=False)
|
||||
|
@ -24,6 +24,7 @@ from django.conf import settings
|
||||
from django.http import HttpResponse, Http404
|
||||
from django.template import loader
|
||||
from django.template.defaultfilters import register
|
||||
from django.views.decorators.http import condition
|
||||
|
||||
from .models import Country, Stamp, Coin, User
|
||||
|
||||
@ -46,8 +47,16 @@ def coin_sum_of_(country):
|
||||
coin_count['total'] += 200 * coin_count[value]
|
||||
else:
|
||||
coin_count['total'] += value * coin_count[value]
|
||||
coin_count['total'] /= 100
|
||||
return coin_count['total']
|
||||
|
||||
return coin_count['total'] / 100
|
||||
|
||||
|
||||
def latest_coin_added_to_(request, name_iso):
|
||||
''' return the datetime of the last coin added to a country
|
||||
>>> latest_coin_added_to_(germany)
|
||||
datetime.datetime
|
||||
'''
|
||||
return Coin.objects.filter(country=name_iso).latest('date_modified').date_modified
|
||||
|
||||
|
||||
def index(request):
|
||||
@ -66,6 +75,7 @@ def index(request):
|
||||
return HttpResponse(template.render(context, request))
|
||||
|
||||
|
||||
@condition(last_modified_func=latest_coin_added_to_)
|
||||
def detail_country(request, name_iso):
|
||||
''' wrapper_view for a *single* country '''
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user