Skip to content

Commit

Permalink
add config for uwsgi and nginx - fix bug with upload progressbar and …
Browse files Browse the repository at this point in the history
…file input in video form
  • Loading branch information
ptitloup committed Jul 2, 2018
1 parent 4a1f7c1 commit 4fe88a5
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 6 deletions.
4 changes: 4 additions & 0 deletions create_data_base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
python manage.py makemigrations
python manage.py migrate
python manage.py loaddata pod/video/fixtures/initial_data.json
python manage.py loaddata pod/main/fixtures/initial_data.json
2 changes: 1 addition & 1 deletion pod/main/static/css/pod.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ div.card a img {
}
div.card a:hover>img {
-webkit-transform:scale(1.1);
transform:scale(1.1)
transform:scale(1.1);
z-index:0;
}
.card-footer {
Expand Down
6 changes: 5 additions & 1 deletion pod/main/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,11 @@ var videocheck = function(form,event) {
$("#video_form fieldset").hide();
$("#video_form button").hide();
$("#js-process").show();
window.scrollTo($("#js-process").scrollTop(), 0);
window.scrollTo($("#js-process").scrollTop(), 0);
if(!show_progress_bar(form)) {
event.preventDefault();
event.stopPropagation();
}
}
} else {
window.scrollTo($("#video_form").scrollTop(), 0);
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pod/main/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="{% static 'bootstrap-4/css/bootstrap.min.css' %}" crossorigin="anonymous">

<!-- octicons -->
<!-- pod.css -->
<link rel="stylesheet" href="{% static 'css/pod.css' %}" media="screen" title="no title">
{% if CSS_OVERRIDE %}
<link rel="stylesheet" href="{% static CSS_OVERRIDE %}" media="screen" title="no title">
Expand Down
2 changes: 1 addition & 1 deletion pod/podfile/templates/podfile/customfilewidget.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% else %}<i data-feather="file"></i>&nbsp;{%endif%}
<strong>{{document.name}}</strong>&nbsp;({{document.file_type}} - {{document.file.size|filesizeformat}})
</span>
<button type="button" class="btn btn-primary btn-fileinput" data-toggle="modal" data-target="#fileModal">
<button type="button" class="btn btn-primary btn-fileinput" data-toggle="modal" data-target="#fileModal_{{id}}">
{% trans 'Change file' %}
</button>
{% else %}
Expand Down
2 changes: 2 additions & 0 deletions pod/video/encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@

def start_encode(video_id):
log.info("START ENCODE VIDEO ID %s" % video_id)
"""
t = threading.Thread(target=encode_video,
args=[video_id])
t.setDaemon(True)
t.start()
"""


# ##########################################################################
Expand Down
28 changes: 26 additions & 2 deletions pod/video/templates/videos/video_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h3>{% if form.instance.title %}{% trans "Editing the video" %} "{{form.instance
{% spaceless %}
<div class="{% if "description_" in field.name or "title_" in field.name %}collapse hide{% else %}{% endif %}{% if "description_" in field.name %} description{%endif%}{% if "title_" in field.name %} title{%endif%}{% with 'is_restricted restrict_access_to_groups password' as res %}{% if field.name in res.split %}collapse restricted_access{% endif %}{% endwith %}">
<div class="list-group-item">
<div class="form-group {% if field.field.required %}form-group-required {%endif%}" >
<div class="form-group {% if field.field.required %}form-group-required{%endif%}" {% if "form-control-file" in field.field.widget.attrs.class and form.instance.video %}style="max-width:44rem; overflow-x:hidden"{%endif%}>
{{ field.errors }}
{% if "form-check-input" in field.field.widget.attrs.class %}
<div class="form-check">
Expand All @@ -77,7 +77,6 @@ <h3>{% if form.instance.title %}{% trans "Editing the video" %} "{{form.instance
<small id="{{field.id_for_label}}Help" class="form-text text-muted">{{ field.help_text|safe }}</small>
{% endif %}
{% if field.field.required %}<div class="invalid-feedback">{% trans "Please provide a valid value for this field" %}.</div>{%endif%}

{% if field.name == "description" %}<button class="btn btn-link" type="button" data-toggle="collapse" data-target=".description" aria-expanded="false"> > {% trans "Other language" %}</button>{%endif%}
{% if field.name == "title" %}<button class="btn btn-link" type="button" data-toggle="collapse" data-target=".title" aria-expanded="false"> > {% trans "Other language" %}</button>{%endif%}
</div>
Expand Down Expand Up @@ -195,9 +194,34 @@ <h5 class="card-title pl-2">{% trans "Form fields"%}</h5>
<link rel="stylesheet" type="text/css" href="{% static 'admin/css/widgets.css' %}" />
<!-- form . media -->
{{form.media}}
<!--
{% progress_bar_media %}
-->
<!-- fin form . media -->
<script>
/** progress_bar **/
uuid = $('#progressBar').data('progress_bar_uuid');
function show_progress_bar(form) {
if ($.data(form, 'submitted')) return false;
form.action += (form.action.indexOf('?') == -1 ? '?' : '&') + 'X-Progress-ID=' + uuid;
window.setTimeout(update_progress_info, 200);
$.data(form, 'submitted', true); // mark form as submitted.
return true;
}
function update_progress_info() {
$.getJSON(upload_progress_url, {'X-Progress-ID': uuid}, function(data, status){
console.log(data);
if(data){
$('#progressBar').removeAttr('hidden'); // show progress bar if there are datas
var progress = parseInt(data.received, 10)/parseInt(data.size, 10)*100;
$('#progressBar').attr('value', progress);
}
else {
$('#progressBar').attr('hidden', ''); // hide progress bar if no datas
}
window.setTimeout(update_progress_info, 200);
});
}
/** formulaire **/
$("#js-process").hide();
var VIDEO_MAX_UPLOAD_SIZE = {{form.VIDEO_MAX_UPLOAD_SIZE}};
Expand Down
52 changes: 52 additions & 0 deletions pod_nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# mysite_nginx.conf
# Add this line in /etc/nginx/nginx.conf
#http {
# [...]
# # reserve 1MB under the name 'uploads' to track uploads
# upload_progress uploadp 1m;
# [...]
#}
# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server unix:///usr/local/django_projects/podv2/podv2.sock;
# server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name pc-lci-info-01.univ-lille1.fr; # substitute your machine's IP address or FQDN
charset utf-8;

# max upload size
client_max_body_size 4G; # adjust to taste

#location ^~ /video_edit {
# track_uploads uploadp 30s
#}

location ^~ /progressbarupload/upload_progress {
# JSON document rather than JSONP callback, pls
upload_progress_json_output;
report_uploads uploadp;
}

# Django media
location /media {
alias /usr/local/django_projects/podv2/pod/media; # your Django project's media files - amend as required
}

location /static {
alias /usr/local/django_projects/podv2/pod/static; # your Django project's static files - amend as required
}

# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /usr/local/django_projects/podv2/uwsgi_params; # the uwsgi_params file you installed
track_uploads uploadp 30s;
}
}
24 changes: 24 additions & 0 deletions pod_uwsgi.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# pod_uwsgi.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir = /home/pod/django_projects/podv2
# Django's wsgi file
module = pod.wsgi
# the virtualenv (full path)
home = /home/pod/.virtualenvs/django_pod
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /home/pod/django_projects/podv2/podv2.sock
# http = :8000
# ... with appropriate permissions - may be needed
chmod-socket = 666
# clear environment on exit
vacuum = true


5 changes: 5 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# test.py
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"] # python3

17 changes: 17 additions & 0 deletions uwsgi_params
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;

uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REQUEST_SCHEME $scheme;
uwsgi_param HTTPS $https if_not_empty;

uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;

0 comments on commit 4fe88a5

Please sign in to comment.