Commit 4c95c94a authored by NaweenTharuka's avatar NaweenTharuka

feat: video uploader

parent ceebc34c
...@@ -136,3 +136,7 @@ CRISPY_TEMPLATE_PACK = 'bootstrap4' ...@@ -136,3 +136,7 @@ CRISPY_TEMPLATE_PACK = 'bootstrap4'
LOGIN_REDIRECT_URL = 'home' LOGIN_REDIRECT_URL = 'home'
LOGIN_URL = 'login' LOGIN_URL = 'login'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,"media/")
...@@ -13,10 +13,15 @@ Including another URLconf ...@@ -13,10 +13,15 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path 1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from xml.dom.minidom import Document
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('', include('users.urls')) path('', include('users.urls'))
] ]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
from django.contrib import admin from django.contrib import admin
# Register your models here. # Register your models here.
from .models import Video
admin.site.register(Video)
\ No newline at end of file
from xml.parsers.expat import model
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.forms import UserCreationForm
from django import forms from django import forms
from .models import Video
class UserRegisterForm(UserCreationForm): class UserRegisterForm(UserCreationForm):
email = forms.EmailField() email = forms.EmailField()
...@@ -9,3 +10,8 @@ class UserRegisterForm(UserCreationForm): ...@@ -9,3 +10,8 @@ class UserRegisterForm(UserCreationForm):
class Meta: class Meta:
model = User model = User
fields = ['username', 'email', 'password1', 'password2'] fields = ['username', 'email', 'password1', 'password2']
class Video_form(forms.ModelForm):
class Meta:
model = Video
fields = ("caption","video")
\ No newline at end of file
# Generated by Django 3.2.6 on 2022-03-07 08:47
from django.db import migrations, models
import users.validator
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Video',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('caption', models.CharField(max_length=100)),
('video', models.FileField(upload_to='video/%y', validators=[users.validator.file_size])),
],
),
]
from wsgiref.validate import validator
from django.db import models from django.db import models
# from presently.users.validator import file_size
from .validator import file_size
# Create your models here. # Create your models here.
class Video(models.Model):
caption = models.CharField(max_length=100)
video=models.FileField(upload_to="video/%y",validators=[file_size])
def __str__(self) -> str:
return self.caption
\ No newline at end of file
...@@ -630,4 +630,12 @@ label { ...@@ -630,4 +630,12 @@ label {
#non-login-link h4:hover{ #non-login-link h4:hover{
color: #0074b6; color: #0074b6;
}
.alert{
z-index: 0 !important;
}
.modal-auto-open{
z-index: 999999 !important;
} }
\ No newline at end of file
...@@ -11,15 +11,16 @@ ...@@ -11,15 +11,16 @@
<div class="col-auto"> <div class="col-auto">
<div id="modalVideo" class="" style="max-width: 700px; min-height:380px"> <div id="modalVideo" class="" style="max-width: 700px; min-height:380px">
<div class="p-t-30 text-center"> <div class="p-t-30 text-center">
<h3 class="m-b-0 pb-4">Video Review</h3> {% for x in all %}
<h2 class="m-b-0">Video Review</h2>
<div class="video-wrap m-b-20"> <div class="video-wrap m-b-20">
<video id="video-js" class="video-js" controls loop preload="true" <video id="video-js" class="video-js" controls loop preload="false"
poster="video/for-benny/for-benny.jpg"> poster="video/for-benny/for-benny.jpg">
<source src="{% static 'users/videos/for-benny.mp4' %}" type="video/mp4" /> <source src="{{x.video.url}}" type="video/mp4" />
<source src="{% static 'users/videos/for-benny.webm' %}" type="video/webm" /> <source src="{{x.video.url}}" type="video/webm" />
</video> </video>
</div> </div>
{% endfor %}
</div> </div>
</div> </div>
</div> </div>
......
...@@ -22,20 +22,30 @@ ...@@ -22,20 +22,30 @@
<div id="modalVideo" class="modal modal-auto-open" data-delay="3000" <div id="modalVideo" class="modal modal-auto-open" data-delay="3000"
style="max-width: 700px; min-height:380px"> style="max-width: 700px; min-height:380px">
<div class="p-t-30 text-center"> <div class="p-t-30 text-center">
{% for x in all %}
<h2 class="m-b-0">Video Review</h2> <h2 class="m-b-0">Video Review</h2>
<h5 class="mb-4">Check out your uploaded presentation</h5> <h5 class="mb-4">Check out your uploaded {{x.caption}} presentation</h5>
<div class="video-wrap m-b-20"> <div class="video-wrap m-b-20">
<video id="video-js" class="video-js" controls loop preload="false" <video id="video-js" class="video-js" controls loop preload="false"
poster="video/for-benny/for-benny.jpg"> poster="video/for-benny/for-benny.jpg">
<source src="{% static 'users/videos/for-benny.mp4' %}" type="video/mp4" /> <source src="{{x.video.url}}" type="video/mp4" />
<source src="{% static 'users/videos/for-benny.webm' %}" type="video/webm" /> <source src="{{x.video.url}}" type="video/webm" />
</video> </video>
</div> </div>
{% endfor %}
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<!-- <div class="col-4">
{% for x in all %}
<h3 class="text-center mt-2 mb-2">{{x.caption}}</h3>
<video class="embed-responsive embed-responsive-16by9" controls="controls">
<source src="{{x.video.url}}" type="video/mp4" />
</video>
{% endfor %}
</div> -->
<div class="line"></div> <div class="line"></div>
<div class="heading-text heading-line text-center pb-3"> <div class="heading-text heading-line text-center pb-3">
<h3>Presently Reviews</h3> <h3>Presently Reviews</h3>
......
...@@ -79,20 +79,23 @@ ...@@ -79,20 +79,23 @@
<span class="lead">Upload your presentation here!</span> <span class="lead">Upload your presentation here!</span>
</div> </div>
<div> <div>
<div class="d-flex"> <div class="d-flex">
<div class="col-6 mx-2"> <div class="col-6 mx-2">
<h4 class="mb-4">Upload Video/Audio file</h4> <h4 class="mb-4">Upload Video/Audio file</h4>
<div> <div>
<form id="fileUpload1" action="https://inspirothemes.com/file-upload" class="dropzone"> <form action="." method="post" enctype="multipart/form-data">
<div class="fallback"> {% csrf_token %}
<input name="file" type="file" multiple /> <div class="dropzone p-5">
{{form.as_p}}
</div>
<div>
<small id="dropzoneHelp" class="form-text text-muted">Max file size is 200MB and max number of files is 1.</small>
</div> </div>
</form> <button class="btn btn-light mt-3" id="" type="submit">Upload</button>
<small id="dropzoneHelp" class="form-text text-muted">Max file size is 200MB and max number of files is 1.</small> </form>
</div> </div>
<a href="{% url 'feedback' %}" class="btn btn-light mt-3" id="" type="submit">Upload</a>
</div> </div>
<div class="col-6 mx-2"> <div class="col-6 mx-2">
...@@ -109,6 +112,7 @@ ...@@ -109,6 +112,7 @@
</div> </div>
</div> </div>
<div class="line mb-5"></div> <div class="line mb-5"></div>
</div> </div>
{% else %} {% else %}
...@@ -121,12 +125,9 @@ ...@@ -121,12 +125,9 @@
</div> </div>
</div> </div>
</div> </div>
{% endif %} {% endif %}
</div> </div>
<section class="p-t-100 p-b-100" style="background-image: url({% static 'users/images/title-banner.png' %});"> <section class="p-t-100 p-b-100" style="background-image: url({% static 'users/images/title-banner.png' %});">
<div class="bg-overlay"></div> <div class="bg-overlay"></div>
<div class="container xs-text-center sm-text-center text-light"> <div class="container xs-text-center sm-text-center text-light">
......
from django.core.exceptions import ValidationError
def file_size(value):
filesize=value.size
if filesize>209715200:
raise ValidationError("maximum size is 10 mb")
\ No newline at end of file
from http.client import HTTPResponse
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.forms import UserCreationForm
from .forms import UserRegisterForm from .forms import UserRegisterForm
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from .forms import Video_form
from .models import Video
def home(request): def home(request):
return render(request, 'users/home.html') all_video=Video.objects.all()
if request.method == "POST":
form = Video_form(data=request.POST,files=request.FILES)
if form.is_valid():
form.save()
messages.success(request, f'Your video was successfully uploaded')
return redirect('feedback')
# return HTTPResponse("<h3>Uploaded Successfully</h3>")
else:
form=Video_form()
return render(request, 'users/home.html',{"form":form,"all":all_video})
def contactus(request): def contactus(request):
return render(request, 'users/contactus.html') return render(request, 'users/contactus.html')
...@@ -15,10 +27,14 @@ def aboutus(request): ...@@ -15,10 +27,14 @@ def aboutus(request):
return render(request, 'users/aboutus.html') return render(request, 'users/aboutus.html')
def feedback(request): def feedback(request):
return render(request, 'users/feedback.html') all_video=Video.objects.all()
return render(request, 'users/feedback.html',{"all":all_video})
def emotionaudio(request): def emotionaudio(request):
return render(request, 'users/emotionaudio.html') all_video=Video.objects.all()
return render(request, 'users/emotionaudio.html',{"all":all_video})
def overallfeedback(request): def overallfeedback(request):
return render(request, 'users/overallfeedback.html') return render(request, 'users/overallfeedback.html')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment