Skip to content
Snippets Groups Projects
Commit f07a8634 authored by Dorian Lesbre's avatar Dorian Lesbre
Browse files

Reworked file upload

parent 8ac2ed95
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
- Custom title to error pages
- Update FAQ
- More captions for planning
- Reworked file upload to allow for file replacement (and not just upload to a new unique name)
- Fix bugs
## Version 1.2.3 - 2021-04-25
......
from datetime import timedelta
from pathlib import Path
from django.db import models
from django.core.cache import cache
from django.core.files.storage import FileSystemStorage
from django.utils.timezone import now
class OverwriteStorage(FileSystemStorage):
"""used to enforcing a fixed filename to upload file
This allow for a constant link to a changeable file"""
filename = "PlanningInterludes"
def get_available_name(self, name, **kwargs):
"""
Returns a filename that's free on the target storage system, and
available for new content to be written to.
"""
# If the filename already exists, remove it as if it was a true file system
extension = Path(name).suffix
new_name = self.filename + extension
if self.exists(new_name):
self.delete(new_name)
return super(FileSystemStorage, self).get_available_name(new_name, **kwargs)
class SingletonModel(models.Model):
"""Table de la BDD qui ne possède qu'un seul élément"""
class Meta:
......@@ -54,6 +74,7 @@ class SiteSettings(SingletonModel):
display_planning = models.BooleanField("Afficher le planning", default=False)
planning_file = models.FileField(
verbose_name="Version PDF du planning", null=True, blank=True,
storage=OverwriteStorage(),
)
activities_allocated = models.BooleanField(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment