added pdf liste and pdf can now be viewed. added filname uuid added copy static script

This commit is contained in:
Alexander Schulz
2024-08-31 15:56:15 +02:00
parent 3d8803a54b
commit 69c723d20d
6 changed files with 40 additions and 4 deletions

4
copyStaticScrips.sh Normal file
View File

@ -0,0 +1,4 @@
rm -d -r /var/www/testapp/
mkdir /var/www/testapp
cp -a /root/appdirectory/assets/. /var/www/testapp/static
chown -R www-data:www-data /var/www

View File

@ -1,5 +1,6 @@
from django.db import models
from django.contrib.auth.models import User
from dynamic_filenames import FilePattern
# Create your models here.
class Post(models.Model):
@ -16,6 +17,8 @@ class Post(models.Model):
def user_directory_path(instance, filename):
return "user_{0}/{1}".format(instance.user.id, filename)
upload_to_pattern = FilePattern(filename_pattern='PDFuploads/{app_label:.25}/{model_name:.30}/{uuid:base32}{ext}')
class ConusFilePDF(models.Model):
fileName = models.CharField(max_length=32)
file = models.FileField(upload_to="PDFuploads/")
#file = models.FileField(upload_to="PDFuploads/")
file = models.FileField(upload_to=upload_to_pattern)

View File

@ -0,0 +1,23 @@
{% extends 'layout.html' %}
{% block title %}
PDF
{% endblock %}
{% block content %}
<section>
<h1>PDFs</h1>
{% for pdf in pdfs %}
<article class="post">
<h2>
<a href="{{ pdf.file.url }}">
{{ pdf.fileName }}
</a>
</h2>
</article>
{% endfor %}
</section>
{% endblock %}

View File

@ -7,6 +7,7 @@ urlpatterns = [
path('', views.post_list, name="list"),
path('new-post/', views.post_new, name="new-post"),
path('pdf/', views.pdf_page, name="pdf_page"),
path('pdf-list', views.pdf_list, name="pdf_list"),
path('<slug:slug>', views.post_page, name="page")

View File

@ -1,5 +1,5 @@
from django.shortcuts import render,redirect
from .models import Post
from .models import Post, ConusFilePDF
from django.contrib.auth.decorators import login_required
from . import forms
@ -38,3 +38,8 @@ def pdf_page(request):
else:
form = forms.UploadFileForm()
return render(request, 'post/pdf_page.html', {'form' : form})
def pdf_list(request):
pdfs = ConusFilePDF.objects.all()
return render(request, 'post/pdf_list.html', {'pdfs': pdfs})

View File

@ -8,5 +8,5 @@
<h1>Home</h1>
<p>Check out my <a href="/about">About</a> page.</p>
<p>Upload a new PDF <a href="{% url 'post:pdf_page' %}">click here</a></p>
<p>show pdfs <a href="{% url 'post:pdf_page' %}">click here</a></p>
<p>show pdfs <a href="{% url 'post:pdf_list' %}">click here</a></p>
{% endblock %}