verejny kontaktnicek #71
					 6 changed files with 101 additions and 0 deletions
				
			
		
							
								
								
									
										18
									
								
								soustredeni/migrations/0011_soustredeni_kontaktnicek_pdf.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								soustredeni/migrations/0011_soustredeni_kontaktnicek_pdf.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -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'), | ||||
|         ), | ||||
|     ] | ||||
|  | @ -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'), | ||||
|         ), | ||||
|     ] | ||||
|  | @ -11,6 +11,16 @@ 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): | ||||
| 	# generate random string | ||||
| 	length = 32 | ||||
| 	fname = "kontaktnicky/" + timezone.now().strftime('%Y-%m-%d-%H_%M') | ||||
| 	fname += ''.join(secrets.choice(string.ascii_uppercase + string.digits) for _ in range(length)) | ||||
| 	return os.path.join(settings.KOREKTURY_PDF_DIR, fname) | ||||
| 
 | ||||
| logger = logging.getLogger(__name__) | ||||
| 
 | ||||
|  | @ -66,6 +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)') | ||||
| 	 | ||||
| 	kontaktnicek_vcf = models.FileField('kontaktníček vcf', upload_to=generate_filename_kontaktnicek, blank=True,) | ||||
| 	kontaktnicek_pdf = models.FileField('kontaktníček pdf', upload_to=generate_filename_kontaktnicek, blank=True,) | ||||
| 
 | ||||
| 	def __str__(self): | ||||
| 		return '{} ({})'.format(self.misto, self.datum_zacatku) | ||||
| 
 | ||||
|  |  | |||
|  | @ -35,6 +35,14 @@ | |||
|             {% endif %} | ||||
|           {% endfor %} | ||||
|         {% endif %} | ||||
| 
 | ||||
|         {% for i in soustredeni.ucastnici.all %} | ||||
|           {% if i.osoba.user == user %} | ||||
|           <li><a href="../{{soustredeni.pk}}/kontaktnicek_pdf">kontaktnicek pdf</a></li> | ||||
|           <li><a href="../{{soustredeni.pk}}/kontaktnicek_vcf">kontaktnicek vcf</a></li>  | ||||
|           {% endif %} | ||||
|         {% endfor %} | ||||
| 
 | ||||
|       </ul> | ||||
|       {% if user.je_org %} | ||||
|         <div class="mam-org-only"> | ||||
|  |  | |||
|  | @ -44,6 +44,16 @@ urlpatterns = [ | |||
| 					org_required(views.SoustredeniAbstraktyView.as_view()), | ||||
| 					name='soustredeni_abstrakty' | ||||
| 				), | ||||
|                 path( | ||||
|                     'kontaktnicek_pdf', | ||||
|                     views.soustredeniKontaktnicekPdfView, | ||||
|                     name='soustredeni_kontaktnicek' | ||||
| 				), | ||||
|                 path( | ||||
|                     'kontaktnicek_vcf', | ||||
|                     views.soustredeniKontaktnicekVcfView, | ||||
|                     name='soustredeni_kontaktnicek' | ||||
| 				), | ||||
| 
				
				zelvuska marked this conversation as resolved
				
			 | ||||
| 				path( | ||||
| 					'fotogalerie/', | ||||
| 					include('galerie.urls') | ||||
|  |  | |||
|  | @ -106,3 +106,32 @@ class SoustredeniAbstraktyView(generic.DetailView): | |||
| 	model = Soustredeni | ||||
| 	template_name = 'soustredeni/export_do_abstraktu.html' | ||||
| 	pk_url_kwarg = 'soustredeni' # v url bude <int:soustredeni> místo defaultně požadovaného <int:pk> | ||||
| 
 | ||||
| # kontaktnicek | ||||
| def soustredeniKontaktnicekPdfView(request, soustredeni): | ||||
| 	return soustredeniKontaktnicekView(request, soustredeni, "pdf") | ||||
| 
 | ||||
| def soustredeniKontaktnicekVcfView(request, soustredeni): | ||||
| 	return soustredeniKontaktnicekView(request, soustredeni, "vcf") | ||||
| 
 | ||||
| 
				
				ledoian marked this conversation as resolved
				
			 
				
					
						ledoian
						commented  Ty views jsou OK-ish. (Šlo by mít URL typu  Ty views jsou OK-ish. (Šlo by mít URL typu `kontaktnicek_<typ:str>` a rovnou používat výsledný view, ale asi to nepřidává moc a spíš to zhoršuje čitelnost…) | ||||
| def soustredeniKontaktnicekView(request, soustredeni, typ): | ||||
| 	soustredeni = get_object_or_404(Soustredeni, id=soustredeni) | ||||
| 
 | ||||
| 	if (not request.user in [u.osoba.user for u in soustredeni.ucastnici.all()]): | ||||
| 		if not request.user.je_org: | ||||
| 			return HttpResponse("Nebyl jsi tam nebo nejsi org") | ||||
| 	if not soustredeni.kontaktnicek_pdf and typ == "pdf": | ||||
| 		return HttpResponse("Kontaktníček není k dispozici") | ||||
| 	elif not soustredeni.kontaktnicek_vcf and typ == "vcf": | ||||
| 		return HttpResponse("Kontaktníček není k dispozici") | ||||
| 	 | ||||
| 	if typ == "pdf": | ||||
| 		with open(soustredeni.kontaktnicek_pdf.path, 'rb') as pdf: | ||||
| 			response = HttpResponse(pdf.read(), content_type='application/pdf') | ||||
| 		return response | ||||
| 	elif typ == "vcf": | ||||
| 		with open(soustredeni.kontaktnicek_vcf.path, 'rb') as vcf: | ||||
| 			response = HttpResponse(vcf.read(), content_type='text/vcard') | ||||
| 		return response | ||||
| 	else: | ||||
| 		return HttpResponse("Neplatný typ kontaktníčku") | ||||
		Loading…
	
		Reference in a new issue
	
	
Tady je nějaké divné odsazení…