From 0f6f6a85b63a6a6bdf056a28d52ae2abd666066d Mon Sep 17 00:00:00 2001
From: ticvac
Date: Tue, 5 Nov 2024 22:47:18 +0100
Subject: [PATCH 01/14] verejny kontaktnicek
---
.../0011_soustredeni_kontaktnicek_pdf.py | 18 ++++++++++++
...2_soustredeni_kontaktnicek_vcf_and_more.py | 23 +++++++++++++++
soustredeni/models.py | 13 +++++++++
.../soustredeni/seznam_soustredeni.html | 8 +++++
soustredeni/urls.py | 10 +++++++
soustredeni/views.py | 29 +++++++++++++++++++
6 files changed, 101 insertions(+)
create mode 100644 soustredeni/migrations/0011_soustredeni_kontaktnicek_pdf.py
create mode 100644 soustredeni/migrations/0012_soustredeni_kontaktnicek_vcf_and_more.py
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..c456aacd 100644
--- a/soustredeni/models.py
+++ b/soustredeni/models.py
@@ -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__)
@@ -65,6 +75,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)
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 %}
+ kontaktnicek pdf
+ kontaktnicek vcf
+ {% endif %}
+ {% endfor %}
+
{% if user.je_org %}
diff --git a/soustredeni/urls.py b/soustredeni/urls.py
index 181700f5..a194218c 100644
--- a/soustredeni/urls.py
+++ b/soustredeni/urls.py
@@ -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'
+ ),
path(
'fotogalerie/',
include('galerie.urls')
diff --git a/soustredeni/views.py b/soustredeni/views.py
index 67a0305f..b0145ff0 100644
--- a/soustredeni/views.py
+++ b/soustredeni/views.py
@@ -106,3 +106,32 @@ class SoustredeniAbstraktyView(generic.DetailView):
model = Soustredeni
template_name = 'soustredeni/export_do_abstraktu.html'
pk_url_kwarg = 'soustredeni' # v url bude
místo defaultně požadovaného
+
+# kontaktnicek
+def soustredeniKontaktnicekPdfView(request, soustredeni):
+ return soustredeniKontaktnicekView(request, soustredeni, "pdf")
+
+def soustredeniKontaktnicekVcfView(request, soustredeni):
+ return soustredeniKontaktnicekView(request, soustredeni, "vcf")
+
+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")
\ No newline at end of file
From c8dd54e8ba330cd55d6d96528bc20b518ff61435 Mon Sep 17 00:00:00 2001
From: ticvac
Date: Tue, 12 Nov 2024 18:37:21 +0100
Subject: [PATCH 02/14] opravy bad designu
---
soustredeni/urls.py | 18 +++++++++---------
soustredeni/views.py | 15 ++++++++-------
2 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/soustredeni/urls.py b/soustredeni/urls.py
index a194218c..af88e456 100644
--- a/soustredeni/urls.py
+++ b/soustredeni/urls.py
@@ -44,15 +44,15 @@ urlpatterns = [
org_required(views.SoustredeniAbstraktyView.as_view()),
name='soustredeni_abstrakty'
),
- path(
- 'kontaktnicek_pdf',
- views.soustredeniKontaktnicekPdfView,
- name='soustredeni_kontaktnicek'
+ path(
+ 'kontaktnicek_pdf',
+ views.soustredeniKontaktnicekPdfView,
+ name='soustredeni_kontaktnicek'
),
- path(
- 'kontaktnicek_vcf',
- views.soustredeniKontaktnicekVcfView,
- name='soustredeni_kontaktnicek'
+ path(
+ 'kontaktnicek_vcf',
+ views.soustredeniKontaktnicekVcfView,
+ name='soustredeni_kontaktnicek'
),
path(
'fotogalerie/',
@@ -60,5 +60,5 @@ urlpatterns = [
),
]
)
- )
+ )
]
diff --git a/soustredeni/views.py b/soustredeni/views.py
index b0145ff0..615ba10d 100644
--- a/soustredeni/views.py
+++ b/soustredeni/views.py
@@ -2,6 +2,7 @@ from django.shortcuts import get_object_or_404, render
from django.http import HttpResponse
from django.views import generic
from django.contrib.staticfiles.finders import find
+from django.http import Http404
import csv
import tempfile
@@ -118,12 +119,12 @@ 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 not request.user.je_org: # nebyl jsi tam, nebo nejsi org
+ raise Http404()
+ if not soustredeni.kontaktnicek_pdf and typ == "pdf": # není k dispozici
+ raise Http404()
+ elif not soustredeni.kontaktnicek_vcf and typ == "vcf": # není k dispozici
+ raise Http404()
if typ == "pdf":
with open(soustredeni.kontaktnicek_pdf.path, 'rb') as pdf:
@@ -134,4 +135,4 @@ def soustredeniKontaktnicekView(request, soustredeni, typ):
response = HttpResponse(vcf.read(), content_type='text/vcard')
return response
else:
- return HttpResponse("Neplatný typ kontaktníčku")
\ No newline at end of file
+ raise ValueError("Nepodporovaný typ kontaktníčku")
From 2dbbb588d038efbe0b62fa6d0e35fd155aacac7c Mon Sep 17 00:00:00 2001
From: ticvac
Date: Tue, 12 Nov 2024 20:15:09 +0100
Subject: [PATCH 03/14] opravy pro pull
---
Dockerfile | 10 ++++++++++
docker-compose.yaml | 12 ++++++++++++
mamweb/settings_common.py | 1 +
requirements.txt | 4 ++--
soustredeni/models.py | 10 ++++++----
soustredeni/urls.py | 4 ++--
soustredeni/views.py | 39 +++++++++++++++++++++------------------
7 files changed, 54 insertions(+), 26 deletions(-)
create mode 100644 Dockerfile
create mode 100644 docker-compose.yaml
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 00000000..ed660d66
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,10 @@
+FROM python:3.11.10-bookworm
+WORKDIR /usr/src/app
+
+RUN pip install --upgrade pip
+COPY ./requirements.txt .
+RUN pip install -r requirements.txt
+
+COPY . .
+
+CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
diff --git a/docker-compose.yaml b/docker-compose.yaml
new file mode 100644
index 00000000..052fd593
--- /dev/null
+++ b/docker-compose.yaml
@@ -0,0 +1,12 @@
+version: '3'
+
+services:
+ django_app:
+ build: .
+ volumes:
+ - this_vol:/usr/src/app/
+ ports:
+ - 8000:8000
+
+volumes:
+ this_vol:
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/requirements.txt b/requirements.txt
index bba1bad0..74ee4c6b 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,8 +1,8 @@
--c constraints.txt
+# -c constraints.txt
setuptools # django-polymorphic má rozbité dependencies
# basic libs
-psycopg2 # PostgreSQL adaptér
+# psycopg2 # PostgreSQL adaptér
ipython # Interaktivní shell
Unidecode # Přepisuje unicode do ASCII (např. soubory nebo e-maily)
Pillow
diff --git a/soustredeni/models.py b/soustredeni/models.py
index c456aacd..e5d11ae9 100644
--- a/soustredeni/models.py
+++ b/soustredeni/models.py
@@ -18,9 +18,11 @@ 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')
+ file_type = filename.split('.')[-1]
+ 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)
+ fname += '.' + file_type
+ return os.path.join(settings.SOUSTREDENI_KONTAKTNICKY_DIR, fname)
logger = logging.getLogger(__name__)
@@ -76,8 +78,8 @@ 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,)
+ kontaktnicek_vcf = models.FileField('kontaktníček vcf', upload_to=generate_filename_kontaktnicek, blank=True, null=True)
+ kontaktnicek_pdf = models.FileField('kontaktníček pdf', upload_to=generate_filename_kontaktnicek, blank=True, null=True)
def __str__(self):
return '{} ({})'.format(self.misto, self.datum_zacatku)
diff --git a/soustredeni/urls.py b/soustredeni/urls.py
index af88e456..6e7f25e5 100644
--- a/soustredeni/urls.py
+++ b/soustredeni/urls.py
@@ -47,12 +47,12 @@ urlpatterns = [
path(
'kontaktnicek_pdf',
views.soustredeniKontaktnicekPdfView,
- name='soustredeni_kontaktnicek'
+ name='soustredeni_kontaktnicek_pdf'
),
path(
'kontaktnicek_vcf',
views.soustredeniKontaktnicekVcfView,
- name='soustredeni_kontaktnicek'
+ name='soustredeni_kontaktnicek_vcf'
),
path(
'fotogalerie/',
diff --git a/soustredeni/views.py b/soustredeni/views.py
index 615ba10d..cd326002 100644
--- a/soustredeni/views.py
+++ b/soustredeni/views.py
@@ -3,6 +3,7 @@ from django.http import HttpResponse
from django.views import generic
from django.contrib.staticfiles.finders import find
from django.http import Http404
+from django.core.exceptions import PermissionDenied
import csv
import tempfile
@@ -108,7 +109,7 @@ class SoustredeniAbstraktyView(generic.DetailView):
template_name = 'soustredeni/export_do_abstraktu.html'
pk_url_kwarg = 'soustredeni' # v url bude místo defaultně požadovaného
-# kontaktnicek
+# Kontaktníčky
def soustredeniKontaktnicekPdfView(request, soustredeni):
return soustredeniKontaktnicekView(request, soustredeni, "pdf")
@@ -117,22 +118,24 @@ def soustredeniKontaktnicekVcfView(request, soustredeni):
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: # nebyl jsi tam, nebo nejsi org
- raise Http404()
- if not soustredeni.kontaktnicek_pdf and typ == "pdf": # není k dispozici
- raise Http404()
- elif not soustredeni.kontaktnicek_vcf and typ == "vcf": # není k dispozici
+ # nebyl jsi tam, nebo nejsi org
+ if (not request.user in [u.osoba.user for u in soustredeni.ucastnici.all()]) and not request.user.je_org:
+ raise PermissionDenied()
+ # není k dispozici
+ if (not soustredeni.kontaktnicek_pdf and typ == "pdf") or (not soustredeni.kontaktnicek_vcf and typ == "vcf"):
raise Http404()
- 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:
- raise ValueError("Nepodporovaný typ kontaktníčku")
+ kontaktnicky = {
+ 'pdf': (soustredeni.kontaktnicek_pdf, 'applcation/pdf', 'rb'),
+ 'vcf': (soustredeni.kontaktnicek_vcf, 'text/vcard', 'rb'), # vcf je texťák, nevím, jestli je potřeba ho otevítat binárně.
+ }
+
+ try:
+ field, mime, otevreni = kontaktnicky[typ]
+ except KeyError as e:
+ raise ValueError("Neznámý typ kontaktníčku") from e
+
+ with open(field.path, otevreni) as kontaktnicek:
+ response = HttpResponse(kontaktnicek.read(), content_type=mime)
+ response['Content-Disposition'] = 'attachment; filename="kontaktnicek.{}"'.format(typ)
+ return response
From 7a781e463f3a5ff4c6fee3be07579128a279949f Mon Sep 17 00:00:00 2001
From: ticvac
Date: Tue, 12 Nov 2024 20:20:43 +0100
Subject: [PATCH 04/14] lol docker tu nemel byt
---
Dockerfile | 10 ----------
docker-compose.yaml | 12 ------------
2 files changed, 22 deletions(-)
delete mode 100644 Dockerfile
delete mode 100644 docker-compose.yaml
diff --git a/Dockerfile b/Dockerfile
deleted file mode 100644
index ed660d66..00000000
--- a/Dockerfile
+++ /dev/null
@@ -1,10 +0,0 @@
-FROM python:3.11.10-bookworm
-WORKDIR /usr/src/app
-
-RUN pip install --upgrade pip
-COPY ./requirements.txt .
-RUN pip install -r requirements.txt
-
-COPY . .
-
-CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
diff --git a/docker-compose.yaml b/docker-compose.yaml
deleted file mode 100644
index 052fd593..00000000
--- a/docker-compose.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
-version: '3'
-
-services:
- django_app:
- build: .
- volumes:
- - this_vol:/usr/src/app/
- ports:
- - 8000:8000
-
-volumes:
- this_vol:
From 6186914a7cffeab9073c3afd07bbda729368ef04 Mon Sep 17 00:00:00 2001
From: ticvac
Date: Tue, 12 Nov 2024 20:27:51 +0100
Subject: [PATCH 05/14] aaaaa another bug
---
requirements.txt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/requirements.txt b/requirements.txt
index 74ee4c6b..bba1bad0 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,8 +1,8 @@
-# -c constraints.txt
+-c constraints.txt
setuptools # django-polymorphic má rozbité dependencies
# basic libs
-# psycopg2 # PostgreSQL adaptér
+psycopg2 # PostgreSQL adaptér
ipython # Interaktivní shell
Unidecode # Přepisuje unicode do ASCII (např. soubory nebo e-maily)
Pillow
From ad5a242f8db3f1e53ae851d09621ca8b1a0abb43 Mon Sep 17 00:00:00 2001
From: ticvac
Date: Tue, 12 Nov 2024 20:31:08 +0100
Subject: [PATCH 06/14] upravy generate filename
---
soustredeni/models.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/soustredeni/models.py b/soustredeni/models.py
index e5d11ae9..d18d8da6 100644
--- a/soustredeni/models.py
+++ b/soustredeni/models.py
@@ -18,8 +18,11 @@ from django.utils import timezone
def generate_filename_kontaktnicek(self, filename):
# generate random string
length = 32
- file_type = filename.split('.')[-1]
- fname = "kontaktnicky/" + timezone.now().strftime('%Y-%m-%d-%H_%M') + ""
+ if len(filename.split('.')) == 1:
+ 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 += '.' + file_type
return os.path.join(settings.SOUSTREDENI_KONTAKTNICKY_DIR, fname)
From 1b755ad1f753c9e1a847e2acf6daa78449943a78 Mon Sep 17 00:00:00 2001
From: ticvac
Date: Tue, 12 Nov 2024 20:37:14 +0100
Subject: [PATCH 07/14] deduplikace listu
---
soustredeni/views.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/soustredeni/views.py b/soustredeni/views.py
index cd326002..83ddee19 100644
--- a/soustredeni/views.py
+++ b/soustredeni/views.py
@@ -121,9 +121,6 @@ def soustredeniKontaktnicekView(request, soustredeni, typ):
# nebyl jsi tam, nebo nejsi org
if (not request.user in [u.osoba.user for u in soustredeni.ucastnici.all()]) and not request.user.je_org:
raise PermissionDenied()
- # není k dispozici
- if (not soustredeni.kontaktnicek_pdf and typ == "pdf") or (not soustredeni.kontaktnicek_vcf and typ == "vcf"):
- raise Http404()
kontaktnicky = {
'pdf': (soustredeni.kontaktnicek_pdf, 'applcation/pdf', 'rb'),
@@ -134,6 +131,10 @@ def soustredeniKontaktnicekView(request, soustredeni, typ):
field, mime, otevreni = kontaktnicky[typ]
except KeyError as e:
raise ValueError("Neznámý typ kontaktníčku") from e
+
+ # není k dispozici
+ if not field:
+ raise Http404()
with open(field.path, otevreni) as kontaktnicek:
response = HttpResponse(kontaktnicek.read(), content_type=mime)
From fcc2c7c37447958ec7690fff219f15da963a08a1 Mon Sep 17 00:00:00 2001
From: ticvac
Date: Tue, 12 Nov 2024 20:37:50 +0100
Subject: [PATCH 08/14] lol komentar
---
soustredeni/views.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/soustredeni/views.py b/soustredeni/views.py
index 83ddee19..fcd2bf01 100644
--- a/soustredeni/views.py
+++ b/soustredeni/views.py
@@ -124,7 +124,7 @@ def soustredeniKontaktnicekView(request, soustredeni, typ):
kontaktnicky = {
'pdf': (soustredeni.kontaktnicek_pdf, 'applcation/pdf', 'rb'),
- 'vcf': (soustredeni.kontaktnicek_vcf, 'text/vcard', 'rb'), # vcf je texťák, nevím, jestli je potřeba ho otevítat binárně.
+ 'vcf': (soustredeni.kontaktnicek_vcf, 'text/vcard', 'rb'),
}
try:
From 036c68bc2a70409aad9280127095a67239fecf9e Mon Sep 17 00:00:00 2001
From: ticvac
Date: Tue, 12 Nov 2024 21:07:13 +0100
Subject: [PATCH 09/14] another lambad function
---
soustredeni/models.py | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/soustredeni/models.py b/soustredeni/models.py
index d18d8da6..9f7269cb 100644
--- a/soustredeni/models.py
+++ b/soustredeni/models.py
@@ -15,14 +15,10 @@ import secrets
import string
from django.utils import timezone
-def generate_filename_kontaktnicek(self, filename):
+def generate_filename_kontaktnicek(self, filename, file_type):
# generate random string
length = 32
- if len(filename.split('.')) == 1:
- 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 = 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)
@@ -80,10 +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, null=True)
- kontaktnicek_pdf = models.FileField('kontaktníček pdf', upload_to=generate_filename_kontaktnicek, blank=True, null=True)
-
+ #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)
From e224ee66a77526818e63896d3d8b4116b13d59fd Mon Sep 17 00:00:00 2001
From: ticvac
Date: Tue, 12 Nov 2024 21:23:13 +0100
Subject: [PATCH 10/14] push to master quick fix zobratzeni pro orrrgy
---
soustredeni/templates/soustredeni/seznam_soustredeni.html | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/soustredeni/templates/soustredeni/seznam_soustredeni.html b/soustredeni/templates/soustredeni/seznam_soustredeni.html
index fe64a871..b737d6de 100644
--- a/soustredeni/templates/soustredeni/seznam_soustredeni.html
+++ b/soustredeni/templates/soustredeni/seznam_soustredeni.html
@@ -81,6 +81,10 @@
Nic!
{% endfor %}
+
{% endif %}
From 042246e9485b79cd9e3d6cd5b975ce5ed591b5e1 Mon Sep 17 00:00:00 2001
From: ticvac
Date: Tue, 12 Nov 2024 21:39:17 +0100
Subject: [PATCH 11/14] =?UTF-8?q?dals=C3=AD=20do=20masteru=20zobrazovani?=
=?UTF-8?q?=20kontaktnicku?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
soustredeni/templates/soustredeni/seznam_soustredeni.html | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/soustredeni/templates/soustredeni/seznam_soustredeni.html b/soustredeni/templates/soustredeni/seznam_soustredeni.html
index b737d6de..7ba6cd29 100644
--- a/soustredeni/templates/soustredeni/seznam_soustredeni.html
+++ b/soustredeni/templates/soustredeni/seznam_soustredeni.html
@@ -38,8 +38,8 @@
{% for i in soustredeni.ucastnici.all %}
{% if i.osoba.user == user %}
- kontaktnicek pdf
- kontaktnicek vcf
+ {% if soustredeni.kontaktnicek_pdf %} kontaktnicek pdf{% endif %}
+ {% if soustredeni.kontaktnicek_vcf %} kontaktnicek vcf{% endif %}
{% endif %}
{% endfor %}
@@ -82,8 +82,8 @@
{% endfor %}
{% endif %}
From e6a21a5f1b09de9d8f4c6de81502bf1570760585 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?=
Date: Tue, 12 Nov 2024 21:41:32 +0100
Subject: [PATCH 12/14] =?UTF-8?q?Koment=C3=A1=C5=99,=20abychom=20kdy=C5=BE?=
=?UTF-8?q?tak=20um=C4=9Bli=20duplikovat=20p=C5=99id=C3=A1n=C3=AD=20deadli?=
=?UTF-8?q?nu?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
tvorba/models.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tvorba/models.py b/tvorba/models.py
index 3a3a6b4e..f63cedd4 100644
--- a/tvorba/models.py
+++ b/tvorba/models.py
@@ -334,7 +334,7 @@ class Deadline(SeminarModelBase):
on_delete=models.CASCADE)
TYP_CISLA = 'cisla'
- TYP_PRVNI_A_SOUS = 'prvniasous'
+ TYP_PRVNI_A_SOUS = 'prvniasous' # Přidáno https://gitea.ks.matfyz.cz/mam/mamweb/pulls/74
TYP_PRVNI = 'prvni'
TYP_SOUS = 'sous'
TYP_CHOICES = [
From 5b330567f8a1fadbccc10b69c0189b3997945da0 Mon Sep 17 00:00:00 2001
From: ticvac
Date: Tue, 12 Nov 2024 21:44:17 +0100
Subject: [PATCH 13/14] generating file names with three functions
---
soustredeni/models.py | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/soustredeni/models.py b/soustredeni/models.py
index 9f7269cb..c8b36741 100644
--- a/soustredeni/models.py
+++ b/soustredeni/models.py
@@ -15,6 +15,12 @@ import secrets
import string
from django.utils import timezone
+def generate_filename_vcf(self, filename):
+ return generate_filename_kontaktnicek(self, filename, 'vcf')
+
+def generate_filemane_pdf(self, filename):
+ return generate_filename_kontaktnicek(self, filename, 'pdf')
+
def generate_filename_kontaktnicek(self, filename, file_type):
# generate random string
length = 32
@@ -77,8 +83,8 @@ 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)
+ kontaktnicek_vcf = models.FileField('kontaktníček vcf', upload_to=generate_filename_vcf, blank=True, null=True)
+ kontaktnicek_pdf = models.FileField('kontaktníček pdf', upload_to=generate_filemane_pdf, blank=True, null=True)
def __str__(self):
return '{} ({})'.format(self.misto, self.datum_zacatku)
From 44766efe2ae8e903150d27c8909fe5420ffc0351 Mon Sep 17 00:00:00 2001
From: MaM Web user
Date: Tue, 12 Nov 2024 21:47:10 +0100
Subject: [PATCH 14/14] =?UTF-8?q?Je=C5=A1t=C4=9B=20migrace?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
— LEdo
---
...r_soustredeni_kontaktnicek_pdf_and_more.py | 24 +++++++++++++++++++
1 file changed, 24 insertions(+)
create mode 100644 soustredeni/migrations/0013_alter_soustredeni_kontaktnicek_pdf_and_more.py
diff --git a/soustredeni/migrations/0013_alter_soustredeni_kontaktnicek_pdf_and_more.py b/soustredeni/migrations/0013_alter_soustredeni_kontaktnicek_pdf_and_more.py
new file mode 100644
index 00000000..20ea60f1
--- /dev/null
+++ b/soustredeni/migrations/0013_alter_soustredeni_kontaktnicek_pdf_and_more.py
@@ -0,0 +1,24 @@
+# Generated by Django 4.2.16 on 2024-11-12 20:47
+
+from django.db import migrations, models
+import soustredeni.models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('soustredeni', '0012_soustredeni_kontaktnicek_vcf_and_more'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='soustredeni',
+ name='kontaktnicek_pdf',
+ field=models.FileField(blank=True, null=True, upload_to=soustredeni.models.generate_filemane_pdf, verbose_name='kontaktníček pdf'),
+ ),
+ migrations.AlterField(
+ model_name='soustredeni',
+ name='kontaktnicek_vcf',
+ field=models.FileField(blank=True, null=True, upload_to=soustredeni.models.generate_filename_vcf, verbose_name='kontaktníček vcf'),
+ ),
+ ]