Track access counts and show them on mouseover

This commit is contained in:
Oliver Falk
2018-11-12 13:30:50 +01:00
parent d0d77d85c8
commit a56b8af7a9
5 changed files with 56 additions and 4 deletions

View File

@@ -0,0 +1,23 @@
# Generated by Django 2.1.3 on 2018-11-07 15:50
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ivataraccount', '0010_auto_20180705_1201'),
]
operations = [
migrations.AddField(
model_name='photo',
name='access_count',
field=models.BigIntegerField(default=0, editable=False),
),
migrations.AlterField(
model_name='userpreference',
name='theme',
field=models.CharField(choices=[('default', 'Default theme'), ('clime', 'climes theme'), ('falko', 'falkos theme')], default='default', max_length=10),
),
]

View File

@@ -0,0 +1,23 @@
# Generated by Django 2.1.3 on 2018-11-07 17:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ivataraccount', '0011_auto_20181107_1550'),
]
operations = [
migrations.AddField(
model_name='confirmedemail',
name='access_count',
field=models.BigIntegerField(default=0, editable=False),
),
migrations.AddField(
model_name='confirmedopenid',
name='access_count',
field=models.BigIntegerField(default=0, editable=False),
),
]

View File

@@ -114,6 +114,7 @@ class Photo(BaseAccountModel):
ip_address = models.GenericIPAddressField(unpack_ipv4=True)
data = models.BinaryField()
format = models.CharField(max_length=3)
access_count = models.BigIntegerField(default=0, editable=False)
class Meta: # pylint: disable=too-few-public-methods
'''
@@ -304,6 +305,7 @@ class ConfirmedEmail(BaseAccountModel):
digest = models.CharField(max_length=32)
digest_sha256 = models.CharField(max_length=64)
objects = ConfirmedEmailManager()
access_count = models.BigIntegerField(default=0, editable=False)
class Meta: # pylint: disable=too-few-public-methods
'''
@@ -419,6 +421,7 @@ class ConfirmedOpenId(BaseAccountModel):
on_delete=models.deletion.SET_NULL,
)
digest = models.CharField(max_length=64)
access_count = models.BigIntegerField(default=0, editable=False)
class Meta: # pylint: disable=too-few-public-methods
'''

View File

@@ -55,7 +55,7 @@ outline: inherit;
</div>
<div class="panel-body" style="height:130px">
<center>
<img style="max-height:100px;max-width:100px" src="{% if email.photo %}{% url 'raw_image' email.photo.id %}{% else %}{% static '/img/nobody/80.png' %}{% endif %}">
<img title="{% trans 'Access count' %}: {{ email.access_count }}" style="max-height:100px;max-width:100px" src="{% if email.photo %}{% url 'raw_image' email.photo.id %}{% else %}{% static '/img/nobody/80.png' %}{% endif %}">
</center>
</div>
</div>
@@ -71,7 +71,7 @@ outline: inherit;
</div>
<div class="panel-body" style="height:130px">
<center>
<img style="max-height:100px;max-width:100px" src="{% if openid.photo %}{% url 'raw_image' openid.photo.id %}{% else %}{% static '/img/nobody/80.png' %}{% endif %}">
<img title="{% trans 'Access count' %}: {{ openid.access_count }}" style="max-height:100px;max-width:100px" src="{% if openid.photo %}{% url 'raw_image' openid.photo.id %}{% else %}{% static '/img/nobody/80.png' %}{% endif %}">
</center>
</div>
</div>
@@ -119,7 +119,7 @@ outline: inherit;
</div>
<div class="panel-body" style="height:130px">
<center>
<img style="max-height:100px;max-width:100px" src="{% url 'raw_image' photo.id %}">
<img title="{% trans 'Access count' %}: {{ photo.access_count }}" style="max-height:100px;max-width:100px" src="{% url 'raw_image' photo.id %}">
</center>
</div>
</div>

View File

@@ -136,7 +136,10 @@ class AvatarImageView(TemplateView):
data = BytesIO()
photodata.save(data, pil_format(imgformat), quality=JPEG_QUALITY)
data.seek(0)
obj.photo.access_count += 1
obj.photo.save()
obj.access_count += 1
obj.save()
return HttpResponse(
data,
content_type='image/%s' % imgformat)