|
|
|
from django.contrib import admin
|
|
|
|
from django.contrib.auth.models import Group
|
|
|
|
from django_reverse_admin import ReverseModelAdmin
|
|
|
|
import seminar.models as m
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(m.Osoba)
|
|
|
|
class OsobaAdmin(admin.ModelAdmin):
|
|
|
|
actions = ['synchronizuj_maily', 'udelej_orgem']
|
|
|
|
search_fields = ['jmeno', 'prijmeni', 'prezdivka']
|
|
|
|
|
|
|
|
def synchronizuj_maily(self, request, queryset):
|
|
|
|
for o in queryset:
|
|
|
|
if o.user is not None:
|
|
|
|
u = o.user
|
|
|
|
u.email = o.email
|
|
|
|
u.save()
|
|
|
|
self.message_user(request, "E-maily synchronizovány.")
|
|
|
|
synchronizuj_maily.short_description = "Synchronizuj vybraným osobám e-maily do uživatelů"
|
|
|
|
|
|
|
|
def udelej_orgem(self,request,queryset):
|
|
|
|
org_group = Group.objects.get(name='org')
|
|
|
|
for o in queryset:
|
|
|
|
if m.Organizator.objects.filter(osoba=o).exists(): continue
|
|
|
|
user = o.user
|
|
|
|
user.groups.add(org_group)
|
|
|
|
user.is_staff = True
|
|
|
|
user.save()
|
|
|
|
org = m.Organizator.objects.create(osoba=o, organizuje_od=datetime.now())
|
|
|
|
org.save()
|
|
|
|
udelej_orgem.short_description = "Udělej z vybraných osob organizátory"
|
|
|
|
|
|
|
|
class OsobaInline(admin.TabularInline):
|
|
|
|
model = m.Osoba
|
|
|
|
|
|
|
|
@admin.register(m.Organizator)
|
|
|
|
class OrganizatorAdmin(ReverseModelAdmin):
|
|
|
|
search_fields = ['osoba__jmeno', 'osoba__prijmeni', 'osoba__prezdivka']
|
|
|
|
inline_type = 'stacked'
|
|
|
|
inline_reverse = ['osoba']
|
|
|
|
|
|
|
|
@admin.register(m.Resitel)
|
|
|
|
class ResitelAdmin(ReverseModelAdmin):
|
|
|
|
search_fields = ['osoba__jmeno', 'osoba__prijmeni', 'osoba__prezdivka']
|
|
|
|
ordering = ('osoba__prijmeni', 'osoba__jmeno')
|
|
|
|
inline_type = 'stacked'
|
|
|
|
inline_reverse = ['osoba']
|
|
|
|
|
|
|
|
admin.site.register(m.Skola)
|
|
|
|
admin.site.register(m.Prijemce)
|