Commit a222348da766d93d98186160c037a00a003a3043
1 parent
0f0d54faac
Exists in
master
let a user see his own cards
Showing 1 changed file with 7 additions and 4 deletions Side-by-side Diff
flashcards/models.py
View file @
a222348
1 | 1 | from math import log1p |
2 | 2 | from math import exp |
3 | -import datetime | |
4 | 3 | |
5 | 4 | from django.contrib.auth.models import AbstractUser, UserManager |
6 | 5 | from django.contrib.auth.tokens import default_token_generator |
7 | 6 | |
... | ... | @@ -15,9 +14,13 @@ |
15 | 14 | from fields import MaskField |
16 | 15 | from cached_property import cached_property |
17 | 16 | |
17 | +from datetime import datetime | |
18 | 18 | |
19 | 19 | |
20 | 20 | |
21 | + | |
22 | + | |
23 | + | |
21 | 24 | # Hack to fix AbstractUser before subclassing it |
22 | 25 | |
23 | 26 | AbstractUser._meta.get_field('email')._unique = True |
... | ... | @@ -255,7 +258,7 @@ |
255 | 258 | @cached_property |
256 | 259 | def score(self): |
257 | 260 | def seconds_since_epoch(dt): |
258 | - epoch = make_aware(datetime.datetime.utcfromtimestamp(0)) | |
261 | + epoch = make_aware(datetime.utcfromtimestamp(0)) | |
259 | 262 | delta = dt - epoch |
260 | 263 | return delta.total_seconds() |
261 | 264 | |
... | ... | @@ -274,8 +277,8 @@ |
274 | 277 | :param user: |
275 | 278 | :return: A queryset with all cards that should be visible to a user. |
276 | 279 | """ |
277 | - return cls.objects.filter(author__confirmed_email=True).filter(is_hidden=False).exclude( | |
278 | - flashcardhide__user=user) | |
280 | + return cls.objects.filter(Q(author__confirmed_email=True) | Q(author=user) | |
281 | + ).exclude(Q(is_hidden=True) | Q(flashcardhide__user=user)) | |
279 | 282 | |
280 | 283 | |
281 | 284 | class UserFlashcardQuiz(Model): |