Skip to content

Commit 89a18a2

Browse files
committed
Fix static file serving: update .gitignore and Apache config
- Fix .gitignore to allow source static files while ignoring collected static files - Update Apache config to use modern Apache 2.4 syntax (Require all granted) - Add missing variant_uris_admin.css and other static files
1 parent f040b3a commit 89a18a2

File tree

5 files changed

+210
-5
lines changed

5 files changed

+210
-5
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ build
55
roundware/settings/local_settings.py
66

77
build
8-
static
8+
# Ignore collected static files (production static directory)
9+
/var/www/roundware/static/
10+
# But allow source static files to be tracked
11+
!roundware/*/static/
912
local_settings.py
1013
.coverage
1114
.idea/*

files/etc-apache2-sites-available-roundware

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
<Directory /var/www/roundware/static>
77
Options -Indexes
88
AllowOverride None
9-
Order allow,deny
10-
allow from all
9+
Require all granted
1110
</Directory>
1211

1312
<Directory /var/www/roundware/rwmedia>
1413
Options -Indexes
1514
AllowOverride None
16-
Order allow,deny
17-
allow from all
15+
Require all granted
1816
</Directory>
1917

2018
Alias /static /var/www/roundware/static
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#id_shape_map {
2+
height: 600px;
3+
width: 1000px;
4+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* CSS for VariantURIsWidget in Django admin */
2+
3+
.variant-uris-container {
4+
margin: 10px 0;
5+
}
6+
7+
/* Simple fix: just make all text in audio file field dark */
8+
.form-row .field-audio_file label {
9+
color: #000 !important;
10+
font-weight: bold !important;
11+
}
12+
13+
.form-row .field-audio_file .help,
14+
.form-row .field-audio_file .helptext {
15+
color: #333 !important;
16+
font-style: italic !important;
17+
}
18+
19+
/* Make sure the file input and any text is dark */
20+
.form-row .field-audio_file input[type="file"] {
21+
color: #000 !important;
22+
}
23+
24+
/* Target any text that might be light */
25+
.form-row .field-audio_file {
26+
color: #000 !important;
27+
}
28+
29+
.variant-uris-container textarea {
30+
width: 100%;
31+
max-width: 600px;
32+
font-family: monospace;
33+
font-size: 12px;
34+
line-height: 1.4;
35+
border: 1px solid #ddd;
36+
border-radius: 4px;
37+
padding: 8px;
38+
background-color: #fff;
39+
color: #333 !important;
40+
}
41+
42+
.variant-uris-container textarea:focus {
43+
border-color: #79aec8;
44+
box-shadow: 0 0 0 2px rgba(121, 174, 200, 0.2);
45+
outline: none;
46+
}
47+
48+
.variant-uris-help {
49+
margin-top: 10px;
50+
padding: 10px;
51+
background-color: #f0f8ff;
52+
border: 1px solid #b3d9ff;
53+
border-radius: 4px;
54+
font-size: 12px;
55+
}
56+
57+
.variant-uris-help p {
58+
margin: 0 0 5px 0;
59+
font-weight: bold;
60+
color: #2c5aa0;
61+
}
62+
63+
.variant-uris-help ul {
64+
margin: 5px 0 0 0;
65+
padding-left: 20px;
66+
}
67+
68+
.variant-uris-help li {
69+
margin: 2px 0;
70+
color: #555;
71+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// Speaker Audio Upload Admin JavaScript
2+
(function($) {
3+
'use strict';
4+
5+
$(document).ready(function() {
6+
console.log('Speaker upload admin script loaded');
7+
8+
// Find the audio file input
9+
var audioFileInput = $('#audio-file-input');
10+
var variantUrisTextarea = $('textarea[name="varianturis"]');
11+
12+
console.log('Audio file input found:', audioFileInput.length);
13+
console.log('Variant URIs textarea found:', variantUrisTextarea.length);
14+
15+
if (audioFileInput.length === 0) {
16+
console.error('Audio file input not found!');
17+
return;
18+
}
19+
20+
// Create upload button
21+
var uploadButton = $('<button type="button" class="default" style="margin-top: 10px; margin-left: 10px;">Upload Audio File</button>');
22+
23+
// Add button after the file input
24+
audioFileInput.after(uploadButton);
25+
console.log('Upload button added');
26+
27+
// Handle file upload
28+
uploadButton.on('click', function() {
29+
var file = audioFileInput[0].files[0];
30+
if (!file) {
31+
alert('Please select an audio file first.');
32+
return;
33+
}
34+
35+
// Show loading state
36+
uploadButton.prop('disabled', true).text('Uploading...');
37+
38+
// Create FormData
39+
var formData = new FormData();
40+
formData.append('audio_file', file);
41+
42+
// Get the current speaker ID from the URL
43+
var urlParts = window.location.pathname.split('/');
44+
var speakerId = null;
45+
46+
// Look for the speaker ID in the URL pattern /admin/rw/speaker/{id}/change/
47+
for (var i = 0; i < urlParts.length; i++) {
48+
if (urlParts[i] === 'speaker' && i + 1 < urlParts.length) {
49+
speakerId = urlParts[i + 1];
50+
break;
51+
}
52+
}
53+
54+
console.log('URL parts:', urlParts);
55+
console.log('Uploading to speaker ID:', speakerId);
56+
57+
if (!speakerId) {
58+
alert('Could not determine speaker ID from URL');
59+
return;
60+
}
61+
62+
// Make AJAX request
63+
$.ajax({
64+
url: '/admin/rw/speaker/' + speakerId + '/upload-audio/',
65+
type: 'POST',
66+
data: formData,
67+
processData: false,
68+
contentType: false,
69+
headers: {
70+
'X-CSRFToken': $('[name=csrfmiddlewaretoken]').val()
71+
},
72+
success: function(data) {
73+
console.log('Upload response:', data);
74+
if (data.success) {
75+
// Update the varianturis textarea
76+
var currentUris = variantUrisTextarea.val().split('\n').filter(function(uri) {
77+
return uri.trim();
78+
});
79+
currentUris.push(data.uri);
80+
variantUrisTextarea.val(currentUris.join('\n'));
81+
82+
// Clear the file input
83+
audioFileInput.val('');
84+
85+
// Show success message
86+
alert('Audio file uploaded successfully! URI added to varianturis.');
87+
} else {
88+
alert('Upload failed: ' + data.error);
89+
}
90+
},
91+
error: function(xhr, status, error) {
92+
console.error('Upload error:', xhr.responseText);
93+
var errorMsg = 'Upload failed: ' + error;
94+
try {
95+
var response = JSON.parse(xhr.responseText);
96+
if (response.error) {
97+
errorMsg = 'Upload failed: ' + response.error;
98+
}
99+
} catch (e) {
100+
// Use default error message
101+
}
102+
alert(errorMsg);
103+
},
104+
complete: function() {
105+
// Reset button state
106+
uploadButton.prop('disabled', false).text('Upload Audio File');
107+
}
108+
});
109+
});
110+
111+
// Simple fix: just make text dark
112+
var audioFileField = audioFileInput.closest('.form-row');
113+
if (audioFileField.length) {
114+
// Force text colors to be visible
115+
audioFileField.find('label').css({
116+
'color': '#000 !important',
117+
'font-weight': 'bold !important'
118+
});
119+
120+
audioFileField.find('.help, .helptext').css({
121+
'color': '#333 !important',
122+
'font-style': 'italic !important'
123+
});
124+
125+
// Make sure all text in the field is dark
126+
audioFileField.css('color', '#000 !important');
127+
}
128+
});
129+
})(django.jQuery);

0 commit comments

Comments
 (0)