|
|
|
from django.contrib import admin
|
|
|
|
from reversion.admin import VersionAdmin
|
|
|
|
from korektury.models import KorekturovanePDF
|
|
|
|
|
|
|
|
from django.core.mail import send_mail
|
|
|
|
from django.urls import reverse
|
|
|
|
|
|
|
|
# Register your models here.
|
|
|
|
class KorekturovanePDFAdmin(VersionAdmin):
|
|
|
|
|
|
|
|
readonly_fields = ['cas', 'stran']
|
|
|
|
|
|
|
|
def get_readonly_fields(self, request, obj=None):
|
|
|
|
if obj:
|
|
|
|
return self.readonly_fields + ['pdf']
|
|
|
|
return self.readonly_fields
|
|
|
|
|
|
|
|
fieldsets = [
|
|
|
|
(None,
|
|
|
|
{'fields':
|
|
|
|
['pdf', 'cas', 'org', 'stran', 'nazev', 'komentar', 'poslat_mail']}),
|
|
|
|
# (u'PDF', {'fields': ['pdf']}),
|
|
|
|
]
|
|
|
|
list_display = ['nazev', 'cas', 'stran', 'org']
|
|
|
|
list_filter = []
|
|
|
|
search_fields = []
|
|
|
|
|
|
|
|
def save_model(self, request, obj, form, change):
|
|
|
|
super().save_model(request, obj, form, change)
|
|
|
|
if not change and obj.poslat_mail: # Je nový a má se poslat mail
|
|
|
|
odkaz = request.build_absolute_uri(reverse('korektury', kwargs={'pdf': obj.id}))
|
|
|
|
odesilatel = 'korekturovatko-nove-pdf@mam.mff.cuni.cz'
|
|
|
|
prijemce = 'org@mam.mff.cuni.cz'
|
|
|
|
predmet = f'Nové korektury: {obj.nazev}'
|
|
|
|
text = f'''\
|
|
|
|
V korekturovátku se objevil nový soubor: {obj.nazev}
|
|
|
|
{odkaz}
|
|
|
|
|
|
|
|
Popis souboru:
|
|
|
|
{obj.komentar}
|
|
|
|
|
|
|
|
---
|
|
|
|
S pozdravem a korekturám zdar!
|
|
|
|
Korekturovátko
|
|
|
|
'''
|
|
|
|
send_mail(predmet,text,odesilatel,[prijemce])
|
|
|
|
|
|
|
|
admin.site.register(KorekturovanePDF, KorekturovanePDFAdmin)
|