mirror of
https://github.com/boostorg/website-v2.git
synced 2026-01-19 04:42:17 +00:00
Support release report pdf attachment to news (#1543)
This commit is contained in:
@@ -21,7 +21,10 @@ class FileTypeValidator:
|
||||
)
|
||||
|
||||
|
||||
image_validator = FileTypeValidator(extensions=[".jpg", ".jpeg", ".png"])
|
||||
IMAGE_EXTENSIONS = [".jpg", ".jpeg", ".png"]
|
||||
|
||||
image_validator = FileTypeValidator(extensions=IMAGE_EXTENSIONS)
|
||||
attachment_validator = FileTypeValidator(extensions=IMAGE_EXTENSIONS + [".pdf"])
|
||||
|
||||
|
||||
@deconstructible
|
||||
@@ -42,3 +45,6 @@ class MaxFileSizeValidator:
|
||||
|
||||
# 1 MB max file size
|
||||
max_file_size_validator = MaxFileSizeValidator(max_size=1 * 1024 * 1024)
|
||||
|
||||
# 50 MB allowed for certain large files - to be used on staff-only fields
|
||||
large_file_max_size_validator = MaxFileSizeValidator(max_size=50 * 1024 * 1024)
|
||||
|
||||
29
news/migrations/0010_news_attachment.py
Normal file
29
news/migrations/0010_news_attachment.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# Generated by Django 4.2.16 on 2024-12-11 22:10
|
||||
|
||||
import core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("news", "0009_alter_news_options"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="news",
|
||||
name="attachment",
|
||||
field=models.FileField(
|
||||
blank=True,
|
||||
null=True,
|
||||
upload_to="news/files/%Y/%m/",
|
||||
validators=[
|
||||
core.validators.MaxFileSizeValidator(max_size=52428800),
|
||||
core.validators.FileTypeValidator(
|
||||
extensions=[".jpg", ".jpeg", ".png", ".pdf"]
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -1,3 +1,5 @@
|
||||
from pathlib import Path
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import models
|
||||
from django.db.models import Case, Value, When
|
||||
@@ -7,7 +9,12 @@ from django.utils.text import slugify
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from core.validators import image_validator, max_file_size_validator
|
||||
from core.validators import (
|
||||
attachment_validator,
|
||||
image_validator,
|
||||
max_file_size_validator,
|
||||
large_file_max_size_validator,
|
||||
)
|
||||
|
||||
from . import acl
|
||||
|
||||
@@ -183,6 +190,16 @@ class Entry(models.Model):
|
||||
|
||||
class News(Entry):
|
||||
news_type = "news"
|
||||
attachment = models.FileField(
|
||||
upload_to="news/files/%Y/%m/",
|
||||
null=True,
|
||||
blank=True,
|
||||
validators=[large_file_max_size_validator, attachment_validator],
|
||||
)
|
||||
|
||||
@property
|
||||
def attachment_filename(self):
|
||||
return Path(self.attachment.name).name
|
||||
|
||||
class Meta:
|
||||
verbose_name = "News"
|
||||
|
||||
@@ -71,6 +71,11 @@
|
||||
<div class="break-words">
|
||||
{{ entry.content|urlize|url_target_blank:'text-sky-600 dark:text-sky-300 hover:text-orange dark:hover:text-orange'|linebreaks }}
|
||||
</div>
|
||||
{% if entry.news.attachment %}
|
||||
<a href="{{ entry.news.attachment.url }}" class="text-sky-600 dark:text-sky-300 hover:text-orange dark:hover:text-orange">
|
||||
{{ entry.news.attachment_filename }}
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user