NDOJ/judge/utils/tickets.py

22 lines
625 B
Python
Raw Permalink Normal View History

2020-01-21 06:35:58 +00:00
from django.contrib.contenttypes.models import ContentType
from django.db.models import Q
from judge.models import Problem
from judge.utils.problems import editable_problems
def own_ticket_filter(profile_id):
return Q(assignees__id=profile_id) | Q(user_id=profile_id)
def filter_visible_tickets(queryset, user, profile=None):
if profile is None:
profile = user.profile
2022-05-14 17:57:27 +00:00
return queryset.filter(
own_ticket_filter(profile.id)
| Q(
content_type=ContentType.objects.get_for_model(Problem),
object_id__in=editable_problems(user, profile),
)
).distinct()