diff --git a/mamweb/settings_common.py b/mamweb/settings_common.py index 19616ac1..55817b6d 100644 --- a/mamweb/settings_common.py +++ b/mamweb/settings_common.py @@ -342,6 +342,7 @@ SEMINAR_KONFERY_DIR = os.path.join('konfery') KOREKTURY_PDF_DIR = os.path.join('korektury', 'pdf') KOREKTURY_IMG_DIR = os.path.join('korektury', 'img') CISLO_IMG_DIR = os.path.join('cislo', 'img') +SOUSTREDENI_KONTAKTNICKY_DIR = os.path.join('soustredeni', 'kontaktnicky') diff --git a/soustredeni/migrations/0011_soustredeni_kontaktnicek_pdf.py b/soustredeni/migrations/0011_soustredeni_kontaktnicek_pdf.py new file mode 100644 index 00000000..7432f296 --- /dev/null +++ b/soustredeni/migrations/0011_soustredeni_kontaktnicek_pdf.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.13 on 2024-11-05 21:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('soustredeni', '0010_tvorba_post'), + ] + + operations = [ + migrations.AddField( + model_name='soustredeni', + name='kontaktnicek_pdf', + field=models.FileField(blank=True, upload_to='kontaktnicky', verbose_name='kontaktníček'), + ), + ] diff --git a/soustredeni/migrations/0012_soustredeni_kontaktnicek_vcf_and_more.py b/soustredeni/migrations/0012_soustredeni_kontaktnicek_vcf_and_more.py new file mode 100644 index 00000000..18767632 --- /dev/null +++ b/soustredeni/migrations/0012_soustredeni_kontaktnicek_vcf_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.13 on 2024-11-05 21:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('soustredeni', '0011_soustredeni_kontaktnicek_pdf'), + ] + + operations = [ + migrations.AddField( + model_name='soustredeni', + name='kontaktnicek_vcf', + field=models.FileField(blank=True, upload_to='kontaktnicky', verbose_name='kontaktníček vcf'), + ), + migrations.AlterField( + model_name='soustredeni', + name='kontaktnicek_pdf', + field=models.FileField(blank=True, upload_to='kontaktnicky', verbose_name='kontaktníček pdf'), + ), + ] diff --git a/soustredeni/models.py b/soustredeni/models.py index 57e3741f..9f7269cb 100644 --- a/soustredeni/models.py +++ b/soustredeni/models.py @@ -11,6 +11,17 @@ from personalni.models import Resitel, Organizator from various.models import SeminarModelBase from tvorba.models import Rocnik, Problem, aux_generate_filename +import secrets +import string +from django.utils import timezone + +def generate_filename_kontaktnicek(self, filename, file_type): + # generate random string + length = 32 + fname = timezone.now().strftime('%Y-%m-%d-%H_%M') + "-" + fname += ''.join(secrets.choice(string.ascii_uppercase + string.digits) for _ in range(length)) + fname += '.' + file_type + return os.path.join(settings.SOUSTREDENI_KONTAKTNICKY_DIR, fname) logger = logging.getLogger(__name__) @@ -65,7 +76,9 @@ class Soustredeni(SeminarModelBase): exportovat = models.BooleanField('export do AESOPa', db_column='exportovat', default=False, help_text='Exportuje se jen podle tohoto flagu (ne veřejnosti)') - + #using lambda to avoid circular import + kontaktnicek_vcf = models.FileField('kontaktníček vcf', upload_to=lambda instance, filename: generate_filename_kontaktnicek(instance, filename, 'vcf'), blank=True, null=True) + kontaktnicek_pdf = models.FileField('kontaktníček pdf', upload_to=lambda instance, filename: generate_filename_kontaktnicek(instance, filename, 'pdf'), blank=True, null=True) def __str__(self): return '{} ({})'.format(self.misto, self.datum_zacatku) diff --git a/soustredeni/templates/soustredeni/seznam_soustredeni.html b/soustredeni/templates/soustredeni/seznam_soustredeni.html index fb79a7a0..fe64a871 100644 --- a/soustredeni/templates/soustredeni/seznam_soustredeni.html +++ b/soustredeni/templates/soustredeni/seznam_soustredeni.html @@ -35,6 +35,14 @@ {% endif %} {% endfor %} {% endif %} + + {% for i in soustredeni.ucastnici.all %} + {% if i.osoba.user == user %} +