Add audience and thema data to catalogue. Also: nicer cover view.
[redakcja.git] / src / team / models.py
1 from django.conf import settings
2 from django.db import models
3 from django.utils.timezone import now
4
5
6 class Profile(models.Model):
7     user = models.OneToOneField(settings.AUTH_USER_MODEL, models.CASCADE)
8     presence = models.BooleanField()
9
10
11 class Presence(models.Model):
12     user = models.ForeignKey(settings.AUTH_USER_MODEL, models.CASCADE)
13     chunk = models.ForeignKey('documents.Chunk', models.SET_NULL, blank=True, null=True)
14     timestamp = models.DateTimeField(auto_now_add=True, db_index=True)
15     active = models.BooleanField()
16
17     @classmethod
18     def report(cls, user, chunk, active):
19         if user.is_anonymous or not hasattr(user, 'profile') or not user.profile.presence:
20             return
21         cls.objects.create(
22             user=user,
23             chunk=chunk,
24             timestamp=now(),
25             active=active
26         )