##// END OF EJS Templates
Compute divided range only once, do not expose it outsided of paginator
Compute divided range only once, do not expose it outsided of paginator

File last commit:

r2056:dcf7666c default
r2063:5d000252 default
Show More
user.py
57 lines | 1.6 KiB | text/x-python | PythonLexer
from django.db import models
from django.db.models import Q
import boards
__author__ = 'neko259'
BAN_REASON_AUTO = 'Auto'
BAN_REASON_MAX_LENGTH = 200
SESSION_KEY_MAX_LENGTH = 100
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)
def __str__(self):
return self.ip
class NotificationManager(models.Manager):
def get_notification_posts(self, usernames: list, last: int = None, user_settings=None):
lower_names = [username.lower() for username in usernames]
posts = boards.models.post.Post.objects.filter(
Q(notification__name__in=lower_names) |
(Q(thread__tags__settings_as_fav=user_settings) & Q(opening=True))).distinct()
if last is not None:
posts = posts.filter(id__gt=last)
posts = posts.order_by('-id')
return posts
class Notification(models.Model):
class Meta:
app_label = 'boards'
objects = NotificationManager()
post = models.ForeignKey('Post', on_delete=models.CASCADE)
name = models.TextField()
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')