##// END OF EJS Templates
Version bump
Version bump

File last commit:

r2056:dcf7666c default
r2074:f781e25f 4.9.1 default
Show More
user.py
57 lines | 1.6 KiB | text/x-python | PythonLexer
neko259
Split up user models
r386 from django.db import models
neko259
Add notifications for threads created in favorite tags
r2054 from django.db.models import Q
neko259
Split post module into post and manager
r1234 import boards
neko259
Added notification API
r994
neko259
Split up user models
r386 __author__ = 'neko259'
BAN_REASON_AUTO = 'Auto'
BAN_REASON_MAX_LENGTH = 200
neko259
Store user settings apart from session in the database
r2041 SESSION_KEY_MAX_LENGTH = 100
neko259
Split up user models
r386
class Ban(models.Model):
class Meta:
app_label = 'boards'
ip = models.GenericIPAddressField()
reason = models.CharField(default=BAN_REASON_AUTO,
max_length=BAN_REASON_MAX_LENGTH)
can_read = models.BooleanField(default=True)
neko259
Made ban object show IP in 'str' method instead of 'unicode' which was user...
r798 def __str__(self):
neko259
Split up user models
r386 return self.ip
neko259
User notifications (BB-59)
r990
neko259
Added notification API
r994 class NotificationManager(models.Manager):
neko259
Do not load fav tags when need to only check notifications
r2056 def get_notification_posts(self, usernames: list, last: int = None, user_settings=None):
neko259
Subscribe to a multiple of users for notifications
r1429 lower_names = [username.lower() for username in usernames]
posts = boards.models.post.Post.objects.filter(
neko259
Show only threads created in the favorite tag, not all its posts
r2055 Q(notification__name__in=lower_names) |
neko259
Do not load fav tags when need to only check notifications
r2056 (Q(thread__tags__settings_as_fav=user_settings) & Q(opening=True))).distinct()
neko259
Added notification API
r994 if last is not None:
posts = posts.filter(id__gt=last)
posts = posts.order_by('-id')
return posts
neko259
User notifications (BB-59)
r990 class Notification(models.Model):
class Meta:
app_label = 'boards'
neko259
Added notification API
r994 objects = NotificationManager()
neko259
Adapt to django-2.0
r1986 post = models.ForeignKey('Post', on_delete=models.CASCADE)
neko259
User notifications (BB-59)
r990 name = models.TextField()
neko259
Store user settings apart from session in the database
r2041
class UserSettings(models.Model):
class Meta:
app_label = 'boards'
session_key = models.CharField(max_length=SESSION_KEY_MAX_LENGTH, unique=True)
fav_tags = models.ManyToManyField('Tag', related_name='settings_as_fav')
hidden_tags = models.ManyToManyField('Tag', related_name='settings_as_hidden')