blender-studio/users/managers.py
Anna Sirota e7669f6e8c Move Profile fields into a custom User model [D9913]
- Moves all columns of `Profile` model to the custom `users.User` model;
- Moves `Notification` model to `users` app without touching its table's content;
- Unifies `Profile`/`User` admin;
- Moves/renames a lot of modules and templates;
- Makes email lookup in unsubscribe handler case-insensitive (bugfix).

- Having all custom profile data on `User` makes it easy to use it:
   Every template/module that needs to do something with profile data has to reference it with `[request].user.profile.field`, potentially introducing extra joins, requiring extra checks and so on;
- Having all custom profile data on `User` makes implementing deletion more straightforward, if not simpler:
   The only way to reliably override the way `User` records are deleted is to override methods of the model/queryset, which is not possible while it's governed by Django's `auth` app. Having User and Profile separate also introduces a layer of hacks in the admin, which we could do without.
2020-12-22 10:28:57 +01:00

19 lines
545 B
Python

"""Implement custom activity streams."""
from actstream.managers import ActionManager, stream
class CustomStreamManager(ActionManager):
"""Defines custom activity streams, such as personal notifications."""
verb_commented = 'commented'
verb_liked = 'liked'
verb_replied = 'replied to'
@stream
def notifications(self, user, **kwargs):
"""Retrieve all personal notifications."""
return self.filter(
notifications__user=user,
**kwargs,
).prefetch_related('notifications')