Admin | u Osoby lze zvolit osoby a ucinit je orgy (nefunguje uplne)
This commit is contained in:
parent
f82ac3f5b1
commit
f6e781490b
2 changed files with 18 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from django.contrib.auth.models import Permission
|
||||||
|
|
||||||
from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin, PolymorphicChildModelFilter
|
from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin, PolymorphicChildModelFilter
|
||||||
from reversion.admin import VersionAdmin
|
from reversion.admin import VersionAdmin
|
||||||
|
@ -18,7 +19,7 @@ admin.site.register(m.Soustredeni)
|
||||||
|
|
||||||
@admin.register(m.Osoba)
|
@admin.register(m.Osoba)
|
||||||
class OsobaAdmin(admin.ModelAdmin):
|
class OsobaAdmin(admin.ModelAdmin):
|
||||||
actions = ['synchronizuj_maily']
|
actions = ['synchronizuj_maily', 'udelej_orgem']
|
||||||
|
|
||||||
def synchronizuj_maily(self, request, queryset):
|
def synchronizuj_maily(self, request, queryset):
|
||||||
for o in queryset:
|
for o in queryset:
|
||||||
|
@ -29,6 +30,20 @@ class OsobaAdmin(admin.ModelAdmin):
|
||||||
self.message_user(request, "E-maily synchronizovány.")
|
self.message_user(request, "E-maily synchronizovány.")
|
||||||
synchronizuj_maily.short_description = "Synchronizuj vybraným osobám e-maily do uživatelů"
|
synchronizuj_maily.short_description = "Synchronizuj vybraným osobám e-maily do uživatelů"
|
||||||
|
|
||||||
|
def udelej_orgem(self,request,queryset):
|
||||||
|
org_perm = Permission.objects.filter(codename__exact='org').first()
|
||||||
|
print(queryset)
|
||||||
|
for o in queryset:
|
||||||
|
user = o.user
|
||||||
|
user.user_permissions.add(org_perm)
|
||||||
|
user.is_staff = True
|
||||||
|
user.save()
|
||||||
|
org = m.Organizator.objects.create(osoba=o)
|
||||||
|
org.save()
|
||||||
|
udelej_orgem.short_description = "Udělej vybraných osob organizátory"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(m.Problem)
|
@admin.register(m.Problem)
|
||||||
class ProblemAdmin(PolymorphicParentModelAdmin):
|
class ProblemAdmin(PolymorphicParentModelAdmin):
|
||||||
base_model = m.Problem
|
base_model = m.Problem
|
||||||
|
|
|
@ -200,6 +200,8 @@ def gen_organizatori(rnd, osoby, last_rocnik):
|
||||||
os.user = user
|
os.user = user
|
||||||
os.save()
|
os.save()
|
||||||
os.user.user_permissions.add(org_perm)
|
os.user.user_permissions.add(org_perm)
|
||||||
|
os.user.is_staff = True
|
||||||
|
os.user.save()
|
||||||
organizatori.append(Organizator.objects.create(osoba=os,
|
organizatori.append(Organizator.objects.create(osoba=os,
|
||||||
organizuje_od=od, organizuje_do=do, strucny_popis_organizatora = popis_orga))
|
organizuje_od=od, organizuje_do=do, strucny_popis_organizatora = popis_orga))
|
||||||
return organizatori
|
return organizatori
|
||||||
|
|
Loading…
Reference in a new issue