verejny kontaktnicek #71
7 changed files with 54 additions and 26 deletions
10
Dockerfile
Normal file
10
Dockerfile
Normal file
|
@ -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"]
|
12
docker-compose.yaml
Normal file
12
docker-compose.yaml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
django_app:
|
||||||
|
build: .
|
||||||
|
volumes:
|
||||||
|
- this_vol:/usr/src/app/
|
||||||
|
ports:
|
||||||
|
- 8000:8000
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
this_vol:
|
|
@ -342,6 +342,7 @@ SEMINAR_KONFERY_DIR = os.path.join('konfery')
|
||||||
KOREKTURY_PDF_DIR = os.path.join('korektury', 'pdf')
|
KOREKTURY_PDF_DIR = os.path.join('korektury', 'pdf')
|
||||||
KOREKTURY_IMG_DIR = os.path.join('korektury', 'img')
|
KOREKTURY_IMG_DIR = os.path.join('korektury', 'img')
|
||||||
CISLO_IMG_DIR = os.path.join('cislo', 'img')
|
CISLO_IMG_DIR = os.path.join('cislo', 'img')
|
||||||
|
SOUSTREDENI_KONTAKTNICKY_DIR = os.path.join('soustredeni', 'kontaktnicky')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
-c constraints.txt
|
# -c constraints.txt
|
||||||
setuptools # django-polymorphic má rozbité dependencies
|
setuptools # django-polymorphic má rozbité dependencies
|
||||||
|
|
||||||
# basic libs
|
# basic libs
|
||||||
psycopg2 # PostgreSQL adaptér
|
# psycopg2 # PostgreSQL adaptér
|
||||||
ipython # Interaktivní shell
|
ipython # Interaktivní shell
|
||||||
Unidecode # Přepisuje unicode do ASCII (např. soubory nebo e-maily)
|
Unidecode # Přepisuje unicode do ASCII (např. soubory nebo e-maily)
|
||||||
Pillow
|
Pillow
|
||||||
|
|
|
@ -18,9 +18,11 @@ from django.utils import timezone
|
||||||
def generate_filename_kontaktnicek(self, filename):
|
def generate_filename_kontaktnicek(self, filename):
|
||||||
# generate random string
|
# generate random string
|
||||||
length = 32
|
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))
|
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__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -76,8 +78,8 @@ 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)')
|
||||||
|
|
||||||
kontaktnicek_vcf = models.FileField('kontaktníček vcf', 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,)
|
kontaktnicek_pdf = models.FileField('kontaktníček pdf', upload_to=generate_filename_kontaktnicek, blank=True, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{} ({})'.format(self.misto, self.datum_zacatku)
|
return '{} ({})'.format(self.misto, self.datum_zacatku)
|
||||||
|
|
|
@ -47,12 +47,12 @@ urlpatterns = [
|
||||||
path(
|
path(
|
||||||
'kontaktnicek_pdf',
|
'kontaktnicek_pdf',
|
||||||
views.soustredeniKontaktnicekPdfView,
|
views.soustredeniKontaktnicekPdfView,
|
||||||
name='soustredeni_kontaktnicek'
|
name='soustredeni_kontaktnicek_pdf'
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
'kontaktnicek_vcf',
|
'kontaktnicek_vcf',
|
||||||
views.soustredeniKontaktnicekVcfView,
|
views.soustredeniKontaktnicekVcfView,
|
||||||
name='soustredeni_kontaktnicek'
|
name='soustredeni_kontaktnicek_vcf'
|
||||||
),
|
),
|
||||||
zelvuska marked this conversation as resolved
|
|||||||
path(
|
path(
|
||||||
'fotogalerie/',
|
'fotogalerie/',
|
||||||
|
|
|
@ -3,6 +3,7 @@ from django.http import HttpResponse
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
from django.contrib.staticfiles.finders import find
|
from django.contrib.staticfiles.finders import find
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
|
from django.core.exceptions import PermissionDenied
|
||||||
|
|
||||||
import csv
|
import csv
|
||||||
import tempfile
|
import tempfile
|
||||||
|
@ -108,7 +109,7 @@ class SoustredeniAbstraktyView(generic.DetailView):
|
||||||
template_name = 'soustredeni/export_do_abstraktu.html'
|
template_name = 'soustredeni/export_do_abstraktu.html'
|
||||||
pk_url_kwarg = 'soustredeni' # v url bude <int:soustredeni> místo defaultně požadovaného <int:pk>
|
pk_url_kwarg = 'soustredeni' # v url bude <int:soustredeni> místo defaultně požadovaného <int:pk>
|
||||||
|
|
||||||
# kontaktnicek
|
# Kontaktníčky
|
||||||
def soustredeniKontaktnicekPdfView(request, soustredeni):
|
def soustredeniKontaktnicekPdfView(request, soustredeni):
|
||||||
return soustredeniKontaktnicekView(request, soustredeni, "pdf")
|
return soustredeniKontaktnicekView(request, soustredeni, "pdf")
|
||||||
|
|
||||||
|
@ -117,22 +118,24 @@ def soustredeniKontaktnicekVcfView(request, soustredeni):
|
||||||
|
|
||||||
def soustredeniKontaktnicekView(request, soustredeni, typ):
|
def soustredeniKontaktnicekView(request, soustredeni, typ):
|
||||||
soustredeni = get_object_or_404(Soustredeni, id=soustredeni)
|
soustredeni = get_object_or_404(Soustredeni, id=soustredeni)
|
||||||
|
# nebyl jsi tam, nebo nejsi org
|
||||||
if (not request.user in [u.osoba.user for u in soustredeni.ucastnici.all()]):
|
if (not request.user in [u.osoba.user for u in soustredeni.ucastnici.all()]) and not request.user.je_org:
|
||||||
if not request.user.je_org: # nebyl jsi tam, nebo nejsi org
|
raise PermissionDenied()
|
||||||
raise Http404()
|
# není k dispozici
|
||||||
if not soustredeni.kontaktnicek_pdf and typ == "pdf": # není k dispozici
|
if (not soustredeni.kontaktnicek_pdf and typ == "pdf") or (not soustredeni.kontaktnicek_vcf and typ == "vcf"):
|
||||||
raise Http404()
|
|
||||||
elif not soustredeni.kontaktnicek_vcf and typ == "vcf": # není k dispozici
|
|
||||||
raise Http404()
|
raise Http404()
|
||||||
|
|
||||||
if typ == "pdf":
|
kontaktnicky = {
|
||||||
with open(soustredeni.kontaktnicek_pdf.path, 'rb') as pdf:
|
'pdf': (soustredeni.kontaktnicek_pdf, 'applcation/pdf', 'rb'),
|
||||||
response = HttpResponse(pdf.read(), content_type='application/pdf')
|
'vcf': (soustredeni.kontaktnicek_vcf, 'text/vcard', 'rb'), # vcf je texťák, nevím, jestli je potřeba ho otevítat binárně.
|
||||||
return response
|
}
|
||||||
elif typ == "vcf":
|
|
||||||
with open(soustredeni.kontaktnicek_vcf.path, 'rb') as vcf:
|
try:
|
||||||
response = HttpResponse(vcf.read(), content_type='text/vcard')
|
field, mime, otevreni = kontaktnicky[typ]
|
||||||
return response
|
except KeyError as e:
|
||||||
else:
|
raise ValueError("Neznámý typ kontaktníčku") from e
|
||||||
raise ValueError("Nepodporovaný typ kontaktníčku")
|
|
||||||
|
with open(field.path, otevreni) as kontaktnicek:
|
||||||
|
response = HttpResponse(kontaktnicek.read(), content_type=mime)
|
||||||
|
response['Content-Disposition'] = 'attachment; filename="kontaktnicek.{}"'.format(typ)
|
||||||
|
return response
|
||||||
|
|
Loading…
Reference in a new issue
Tady je nějaké divné odsazení…