From 80014458d96dcc049b5d3f639ffc7c10353c48f1 Mon Sep 17 00:00:00 2001 From: FredMagas Date: Thu, 8 Aug 2024 22:42:15 -0300 Subject: [PATCH] Added new function in download CV button to upload PDF via admin panel --- db.sqlite3 | Bin 143360 -> 147456 bytes fredmagaweb/admin.py | 5 ++- ...lter_contato_empresa_alter_contato_nome.py | 35 ++++++++++++++++++ fredmagaweb/models.py | 12 ++++++ fredmagaweb/templates/index.html | 16 ++++++-- fredmagaweb/views.py | 8 +++- portfolioweb/settings.py | 4 ++ portfolioweb/urls.py | 5 ++- 8 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 fredmagaweb/migrations/0005_curriculo_alter_contato_empresa_alter_contato_nome.py diff --git a/db.sqlite3 b/db.sqlite3 index 656f9840583388fd25b4e754923ae0d168754d00..cd959b2bc6f59244b035dcc3371a173dbec6b8a8 100644 GIT binary patch delta 3279 zcmai04Qv}{8NSbF$2rI6*GcNQ$q+d^j@sbaxj*}Cmn67Zva-7EijtPKD&EDuq$%-F z{FAa&BS~9}{_j#Z1eZQZZf6zETPrdk9^KpV8JZnFM|6?ybE}-LAp1lO5le%3p+kFP= zb~$Q)nM%k`6VY`hI-XOKDS1LZt&FiO8;B>0x!h!;IF*UZQw1d#Ph`>sxsZt~sccTk z%XOpaOiJNdUi7gc9~)*^HX?>2Ea#V`a4^i3{T+8rJAXh>U?Jg8&;vh#8Mpvn0}Gsh zfwGJJxvlhj|EFD!_7+k?HA<=~8n6;)b1B~IMV``y-hGHF-R<>0=Ct6+QLu-Azrt;J z7v6+#K_2$NC|tm_F6d}Cc6HV=R;ERjMhBKikL5_o{E29z<(}m=%bev%*~K(i=5~2Z z1nLo}nMvhzRl=a0X0#Dz5SQlWWvw>eF6`)&sH8Hb6qJpwt7Em!?p5c+NjW`H=e#<$ z=Iqs|yIt6O7e~p-y^1%jc6CzD8W^pJTcVbtm$-si*UR@9O8H}SiY4RU@W9{k+8i>U$rh` zCFiZX&$^7J1LqD$#Z$@RbEn3#>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644 --- a/fredmagaweb/admin.py +++ b/fredmagaweb/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from .models import PortfolioItem +from .models import PortfolioItem, Curriculo def make_unpublished(modeladmin, request, queryset): queryset.update(publicado=False) @@ -13,4 +13,5 @@ class PortfolioItemAdmin(admin.ModelAdmin): actions = [make_published, make_unpublished] list_display = ('title', 'publicado') -admin.site.register(PortfolioItem, PortfolioItemAdmin) \ No newline at end of file +admin.site.register(PortfolioItem, PortfolioItemAdmin) +admin.site.register(Curriculo) \ No newline at end of file diff --git a/fredmagaweb/migrations/0005_curriculo_alter_contato_empresa_alter_contato_nome.py b/fredmagaweb/migrations/0005_curriculo_alter_contato_empresa_alter_contato_nome.py new file mode 100644 index 0000000..1ddf278 --- /dev/null +++ b/fredmagaweb/migrations/0005_curriculo_alter_contato_empresa_alter_contato_nome.py @@ -0,0 +1,35 @@ +# Generated by Django 4.2.3 on 2024-08-09 00:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fredmagaweb', '0004_portfolioitem_publicado_alter_portfolioitem_image'), + ] + + operations = [ + migrations.CreateModel( + name='Curriculo', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('arquivo', models.FileField(upload_to='curriculos/')), + ('data_upload', models.DateTimeField(auto_now_add=True)), + ], + options={ + 'verbose_name': 'Currículo', + 'verbose_name_plural': 'Currículos', + }, + ), + migrations.AlterField( + model_name='contato', + name='empresa', + field=models.CharField(max_length=40), + ), + migrations.AlterField( + model_name='contato', + name='nome', + field=models.CharField(max_length=40), + ), + ] diff --git a/fredmagaweb/models.py b/fredmagaweb/models.py index a89a94e..68240ae 100644 --- a/fredmagaweb/models.py +++ b/fredmagaweb/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.conf import settings class Contato(models.Model): nome = models.CharField(max_length=40) @@ -19,3 +20,14 @@ class PortfolioItem(models.Model): def __str__(self): return self.title + +class Curriculo(models.Model): + arquivo = models.FileField(upload_to='curriculos/', storage=settings.PDF_STORAGE) + data_upload = models.DateTimeField(auto_now_add=True) + + def __str__(self): + return f"Curriculo {self.id} - {self.data_upload.strftime('%d/%m/%Y')}" + + class Meta: + verbose_name = "Currículo" + verbose_name_plural = "Currículos" \ No newline at end of file diff --git a/fredmagaweb/templates/index.html b/fredmagaweb/templates/index.html index 75cb28a..d56f85f 100644 --- a/fredmagaweb/templates/index.html +++ b/fredmagaweb/templates/index.html @@ -87,9 +87,19 @@

- - - + {% if curriculo %} + + + + {% else %} + {% if messages %} +
    + {% for message in messages %} + {{ message }} + {% endfor %} +
+ {% endif %} + {% endif %}
diff --git a/fredmagaweb/views.py b/fredmagaweb/views.py index 9a96256..fdbbea7 100644 --- a/fredmagaweb/views.py +++ b/fredmagaweb/views.py @@ -3,7 +3,7 @@ from django.urls import reverse from django.core.mail import EmailMessage from .forms import ContatoForm -from .models import PortfolioItem +from .models import PortfolioItem, Curriculo from django.contrib import messages from decouple import config import requests @@ -12,6 +12,10 @@ def index(request): portfolio_items = PortfolioItem.objects.filter(publicado=True) + curriculo = Curriculo.objects.last() # Obtém o currículo mais recente + + if not curriculo: + messages.error(request, 'O currículo não está disponível para download no momento.') if request.method == 'POST': form = ContatoForm(request.POST) @@ -71,4 +75,4 @@ def index(request): else: form = ContatoForm() - return render(request, 'index.html', {'portfolio_items': portfolio_items, 'form': form}) \ No newline at end of file + return render(request, 'index.html', {'portfolio_items': portfolio_items,'curriculo': curriculo, 'form': form}) \ No newline at end of file diff --git a/portfolioweb/settings.py b/portfolioweb/settings.py index 1fbeb1d..ec7dd0a 100644 --- a/portfolioweb/settings.py +++ b/portfolioweb/settings.py @@ -13,9 +13,11 @@ from pathlib import Path from decouple import config from django.core.management.utils import get_random_secret_key +from django.core.files.storage import FileSystemStorage import dj_database_url + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -146,6 +148,8 @@ MEDIA_ROOT = BASE_DIR / "media" +PDF_STORAGE = FileSystemStorage(location=os.path.join(BASE_DIR, 'media/')) + WHITENOISE_KEEP_ONLY_HASHED_FILES = True DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/portfolioweb/urls.py b/portfolioweb/urls.py index 41a9912..e45aa96 100644 --- a/portfolioweb/urls.py +++ b/portfolioweb/urls.py @@ -15,11 +15,14 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.urls import include - +from django.conf import settings from django.contrib import admin from django.urls import path +from django.conf.urls.static import static urlpatterns = [ path('admin/', admin.site.urls), path('', include('fredmagaweb.urls')), ] + +urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)