util.py 497 Bytes
#-*- coding:utf-8 -*-

from django.db import connection
from django.db.models import Q
from django.contrib.auth.models import User


def set_history(user):
  cursor = connection.cursor()
  cursor.execute("SELECT set_config('var.user_id', %s, true)", [str(user.id)])

def bot_history():
  set_history(User.objects.get(username=u'Kuźniobot'))

def users_with_perm(perm):
  return User.objects.filter(
    Q(groups__permissions=perm) | Q(user_permissions=perm) |
    Q(is_superuser=True)).distinct()