another lambad function
This commit is contained in:
parent
fcc2c7c374
commit
036c68bc2a
1 changed files with 5 additions and 10 deletions
|
@ -15,14 +15,10 @@ import secrets
|
||||||
import string
|
import string
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
def generate_filename_kontaktnicek(self, filename):
|
def generate_filename_kontaktnicek(self, filename, file_type):
|
||||||
# generate random string
|
# generate random string
|
||||||
length = 32
|
length = 32
|
||||||
if len(filename.split('.')) == 1:
|
fname = timezone.now().strftime('%Y-%m-%d-%H_%M') + "-"
|
||||||
file_type = 'lol_neumíš_tam_dát_příponu'
|
|
||||||
else:
|
|
||||||
file_type = filename.split('.')[-1]
|
|
||||||
fname = timezone.now().strftime('%Y-%m-%d-%H_%M') + ""
|
|
||||||
fname += ''.join(secrets.choice(string.ascii_uppercase + string.digits) for _ in range(length))
|
fname += ''.join(secrets.choice(string.ascii_uppercase + string.digits) for _ in range(length))
|
||||||
fname += '.' + file_type
|
fname += '.' + file_type
|
||||||
return os.path.join(settings.SOUSTREDENI_KONTAKTNICKY_DIR, fname)
|
return os.path.join(settings.SOUSTREDENI_KONTAKTNICKY_DIR, fname)
|
||||||
|
@ -80,10 +76,9 @@ class Soustredeni(SeminarModelBase):
|
||||||
|
|
||||||
exportovat = models.BooleanField('export do AESOPa', db_column='exportovat', default=False,
|
exportovat = models.BooleanField('export do AESOPa', db_column='exportovat', default=False,
|
||||||
help_text='Exportuje se jen podle tohoto flagu (ne veřejnosti)')
|
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=generate_filename_kontaktnicek, blank=True, null=True)
|
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=generate_filename_kontaktnicek, 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):
|
def __str__(self):
|
||||||
return '{} ({})'.format(self.misto, self.datum_zacatku)
|
return '{} ({})'.format(self.misto, self.datum_zacatku)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue