Skip to content

Commit

Permalink
Added new function in download CV button to upload PDF via admin panel
Browse files Browse the repository at this point in the history
  • Loading branch information
FredMagas committed Aug 9, 2024
1 parent f045b32 commit 8001445
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 8 deletions.
Binary file modified db.sqlite3
Binary file not shown.
5 changes: 3 additions & 2 deletions fredmagaweb/admin.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -13,4 +13,5 @@ class PortfolioItemAdmin(admin.ModelAdmin):
actions = [make_published, make_unpublished]
list_display = ('title', 'publicado')

admin.site.register(PortfolioItem, PortfolioItemAdmin)
admin.site.register(PortfolioItem, PortfolioItemAdmin)
admin.site.register(Curriculo)
Original file line number Diff line number Diff line change
@@ -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),
),
]
12 changes: 12 additions & 0 deletions fredmagaweb/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models
from django.conf import settings

class Contato(models.Model):
nome = models.CharField(max_length=40)
Expand All @@ -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"
16 changes: 13 additions & 3 deletions fredmagaweb/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,19 @@ <h4>
</div>

<div class="curriculo" data-aos="flip-left">
<a href="{% static 'files/Curriculo Frederico Augusto Magalhaes - 2023.pdf' %}" target="_blank">
<button class="btn-curriculo">Download CV</button>
</a>
{% if curriculo %}
<a href="{{ curriculo.arquivo.url }}" target="_blank">
<button class="btn-curriculo">Download CV</button>
</a>
{% else %}
{% if messages %}
<ul>
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endif %}
</div>
</div>
</section>
Expand Down
8 changes: 6 additions & 2 deletions fredmagaweb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -71,4 +75,4 @@ def index(request):
else:
form = ContatoForm()

return render(request, 'index.html', {'portfolio_items': portfolio_items, 'form': form})
return render(request, 'index.html', {'portfolio_items': portfolio_items,'curriculo': curriculo, 'form': form})
4 changes: 4 additions & 0 deletions portfolioweb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'
Expand Down
5 changes: 4 additions & 1 deletion portfolioweb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 8001445

Please sign in to comment.