Porównaj commity

...

5 Commity

Autor SHA1 Wiadomość Data
Hartmut Holzgraefe 77dba38814 make the "translation status" message itself translateable 2023-09-25 17:36:27 +00:00
Hartmut Holzgraefe 9566cca720 only try to delete old upload files not marked as deleted yet (#90 / #116) 2023-09-25 17:35:34 +00:00
Hartmut Holzgraefe f0912d4752 make "file no longer present" message more specific, and translatable 2023-09-25 13:30:13 +00:00
Hartmut Holzgraefe 082d3e445f prevent exception on showing removed upload files details 2023-09-25 11:52:12 +00:00
Hartmut Holzgraefe 8eb49047b6 final touches on upload retention (Issues #90 / #116 complete) 2023-09-23 09:09:53 +00:00
13 zmienionych plików z 71 dodań i 11 usunięć

Wyświetl plik

@ -270,7 +270,7 @@ class RenderingsGarbageCollector:
LOG.info("Cleanup remove old upload files")
files = UploadFile.objects.filter(keep_until__lte = datetime.now())
files = UploadFile.objects.filter(keep_until__lte = datetime.now(), deleted_on__isnull = True)
for file in files:
try:

Wyświetl plik

@ -540,7 +540,12 @@ class JobRenderer(threading.Thread):
for file in self.job.uploads.all():
if file.keep_until is None:
os.remove(os.path.join(MEDIA_ROOT, file.uploaded_file.name))
try:
os.remove(os.path.join(MEDIA_ROOT, file.uploaded_file.name))
file.deleted_on = datetime.datetime.now()
file.save()
except Exception as e:
LOG.warning("Purging upload file %s failed: %s" % (file.uploaded_file.name, e))
return self.result

Wyświetl plik

@ -0,0 +1,23 @@
# Generated by Django 4.2.4 on 2023-09-23 04:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('maposmatic', '0033_uploadfile_keep_until'),
]
operations = [
migrations.AddField(
model_name='uploadfile',
name='created_on',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='uploadfile',
name='deleted_on',
field=models.DateTimeField(blank=True, null=True),
),
]

Wyświetl plik

@ -0,0 +1,17 @@
# created manually
from django.db import migrations, models
def default_keep_until_for_old_rows(apps, schema_editor):
files = apps.get_model("maposmatic", "uploadfile")
files.objects.filter(keep_until__isnull = True, deleted_on__isnull = True).update(keep_until = '2999-12-30')
class Migration(migrations.Migration):
dependencies = [
('maposmatic', '0034_uploadfile_created_on_uploadfile_deleted_on'),
]
operations = [
migrations.RunPython(default_keep_until_for_old_rows),
]

Wyświetl plik

@ -369,4 +369,6 @@ class UploadFile(models.Model):
job = models.ManyToManyField(MapRenderingJob, related_name = 'uploads')
created_on = models.DateTimeField(auto_now = True)
keep_until = models.DateTimeField(null = True, blank = True)
deleted_on = models.DateTimeField(null = True, blank = True)

Wyświetl plik

@ -66,7 +66,7 @@
{% if LANGUAGE_CODE != "en" %}
<li class="nav-item">
<a class="nav-link" target=_blank" href="{{ WEBLATE_BASE_URL }}engage/maposmatic/?utm_source=widget">
<img src="{{ WEBLATE_BASE_URL }}widgets/maposmatic/{{ LANGUAGE_CODE }}/svg-badge.svg" alt="Translation status" />
<img src="{{ WEBLATE_BASE_URL }}widgets/maposmatic/{{ LANGUAGE_CODE }}/svg-badge.svg" alt="{% trans "Translation status" %}" />
</a>
</li>
{% endif %}

Wyświetl plik

@ -100,7 +100,7 @@
{% if map.uploads.all %}
<tr><td><strong>{% trans "Uploaded files" %}</strong></td><td>
{% for upload in map.uploads.all %}
<tt>{{ upload.uploaded_file|file_basename }}</tt> <em>({{ upload.file_type }}, {{ upload.uploaded_file.size|filesizeformat }})</em><br/>
<tt>{{ upload.uploaded_file|file_basename }}</tt> <em>({{ upload.file_type }}, {{ upload.uploaded_file|file_readable_size }})</em><br/>
{% endfor %}
</td></tr>
{% endif %}

Wyświetl plik

@ -70,13 +70,13 @@
<fieldset id="track-file">
<legend><i class="fas fa-file-upload"></i> {% trans "Upload files" %}</legend>
{{ form.uploadfile }}
<tt id="file-list">
</tt>
<tt id="file-list"> <!-- TODO: not used yet --></tt>
</fieldset>
<fieldset>
{{ form.delete_files_after_rendering }}
<label>{% trans "Delete files after rendering" %}</label>
</fieldset>
<button type="button" id="upload_preview_button" class="btn btn-primary" style="display:none" onclick=" $('#step-location-bbox-tab').tab('show');"><i class="fa-solid fa-magnifying-glass"></i> {% trans "Upload preview" %}</button>
</div>
<div class="col">
<div class="alert alert-danger">

Wyświetl plik

@ -46,10 +46,15 @@ function add_upload_layer(filename, new_layer) {
// TODO: fill file list display
// $("#file-list").text(txt);
$('#step-location-bbox-tab').tab('show'); // Select geo location tab
// we need to have the map visible to correctly apply the new bounds, apparently
// so we are quickly switching between tabs back and forth
$('#step-location-bbox-tab').tab('show');
locationFilter.setBounds(upload_file_bounds);
locationFilter.enable();
$('#step-location-file-tab').tab('show');
// enable "to preview" button
$('#upload_preview_button').show();
}
function get_layer_titles() {

Wyświetl plik

@ -1,5 +1,7 @@
import os
from django.utils.translation import gettext_lazy as _
import www.settings
from .extratags import register
@ -24,4 +26,4 @@ def file_readable_size(value):
size = size / 1024
else:
return "not found"
return _("no longer present")

Wyświetl plik

@ -193,7 +193,10 @@ def new(request):
if form.cleaned_data.get('delete_files_after_rendering'):
keep_until = None
else:
keep_until = '1999-01-01'
if www.settings.UPLOAD_FILE_LIFETIME > 0:
keep_until = datetime.datetime.now() + datetime.timedelta(days=www.settings.UPLOAD_FILE_LIFETIME)
else:
keep_until = '2999-12-30' # arbitrary 'max' value
for file in files:
create_upload_file(job, file, keep_until)

Wyświetl plik

@ -354,7 +354,7 @@ LOG = logging.getLogger('maposmatic')
# render user should be in www-data group to be able to clean up
FILE_UPLOAD_PERMISSIONS = 0o664
FILE_UPLOAD_DIRECTORY_PERMISSIONS = 0o664
FILE_UPLOAD_DIRECTORY_PERMISSIONS = 0o775
# Maintenance mode settings

Wyświetl plik

@ -172,6 +172,9 @@ SUBMITTER_IP_LIFETIME=-1
# set to 0 to keep them forever
SUBMITTER_MAIL_LIFETIME=24
# Upload file lifetime in days, set to 0 for "forever"
UPLOAD_FILE_LIFETIME=365
# Weblate base URL - link to translation service
WEBLATE_BASE_URL = 'https://translate.get-map.org/'