Pavel "LEdoian" Turinsky
1 year ago
3 changed files with 34 additions and 0 deletions
@ -0,0 +1,34 @@ |
|||||
|
from django.core.management.base import BaseCommand |
||||
|
import logging |
||||
|
|
||||
|
from django.contrib.auth.models import User, Group |
||||
|
import seminar.models as m |
||||
|
from datetime import date |
||||
|
|
||||
|
logger = logging.getLogger(__name__) |
||||
|
|
||||
|
class Command(BaseCommand): |
||||
|
def handle(self, *args, **options): |
||||
|
org_group = Group.objects.get(name='org') |
||||
|
stari_orgove = set() |
||||
|
nesparovani = set() |
||||
|
for u in User.objects.all(): |
||||
|
if u.is_staff or u in org_group.user_set.all() or u.has_perm('auth.org'): |
||||
|
# Dohledáme orga |
||||
|
# Používáme .filter, protože se nemusí najít |
||||
|
orgove = m.Organizator.objects.filter(osoba__user=u) |
||||
|
if orgove.count() != 1: |
||||
|
nesparovani.add(u) |
||||
|
org = orgove.first() |
||||
|
# Pokud už není aktivní, tak ho vypíšeme |
||||
|
# Porovnáváme data, protože neřeší časové zóny (datetime.now není tz-aware) |
||||
|
if org.organizuje_do is not None and org.organizuje_do.date() < date.today(): |
||||
|
stari_orgove.add(org) |
||||
|
if len(nesparovani) > 0: |
||||
|
print('Účty s právy, ke kterým neznáme orga:') |
||||
|
for x in nesparovani: |
||||
|
print(f'\t{x}') |
||||
|
if len(stari_orgove) > 0: |
||||
|
print('Staří orgové, kterým zóstala práva a neměla:') |
||||
|
for x in stari_orgove: |
||||
|
print(f'\t{x}') |
Loading…
Reference in new issue