Browse Source

opravy pro pull

pull/71/head
ticvac 1 month ago
parent
commit
2dbbb588d0
  1. 10
      Dockerfile
  2. 12
      docker-compose.yaml
  3. 1
      mamweb/settings_common.py
  4. 4
      requirements.txt
  5. 10
      soustredeni/models.py
  6. 4
      soustredeni/urls.py
  7. 39
      soustredeni/views.py

10
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"]

12
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:

1
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')

4
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

10
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)

4
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/',

39
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 <int:soustredeni> místo defaultně požadovaného <int:pk>
# 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

Loading…
Cancel
Save