Skip to content

Commit

Permalink
Updated Code
Browse files Browse the repository at this point in the history
Added all my updates
  • Loading branch information
Isafatokun committed Aug 9, 2022
1 parent 19d0ca7 commit 03f8992
Show file tree
Hide file tree
Showing 14 changed files with 316 additions and 36 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added media/videos/zuri_figma.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions movies/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ class Meta:
model = Movie
fields = {'title' : '', 'description': '', 'video' : ''}

class EditMovieForm(MovieForm):
class Meta:
model = Movie
fields = {'title' : '', 'description': ''}

class MovieCommentForm(forms.ModelForm):
class Meta:
model = MovieComment
Expand Down
15 changes: 8 additions & 7 deletions movies/templates/1base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
</head>
<body>
<nav>
{% if user.is_authenticated %}
{% if user.userinfo.user_type == "Student" %}
{% if request.user.is_authenticated %}
{% if request.user.userinfo.user_type == "Student" %}
<ul>
<li>Hello, {{ user.username }}</li>
<li>You are a {{ user.userinfo.user_type }}</li>
<li>Hello, {{ request.user.username }}</li>
<li>You are a {{ request.user.userinfo.user_type }}</li>
<li><a class="nav-link" href="{% url 'movies:index'%}">Home</a></li>
<li><a class="nav-link" href="{% url 'movies:all_movies'%}">Movies</a></li>
<li><a class="nav-link" href="{% url 'accounts:list_favourites' %}">Favourites</a></li>
<li><a class="nav-link" href="{% url 'accounts:profile' %}">My Profile</a></li>
<li><a class="nav-link" href="{% url 'accounts:list_favourites' %}">My Favourites</a></li>
<li><a class="nav-link" href="{% url 'movies:new_movie'%}">Add Movie</a></li>
<li><a class="nav-link" href="{% url 'accounts:logout' %}">Log Out</a></li>

</ul>
{% else %}
<ul>
<li>Hello, {{ user.username }}</li>
<li>You are a {{ user.userinfo.user_type }}</li>
<li>Hello, {{ request.user.username }}</li>
<li>You are a {{ request.user.userinfo.user_type }}</li>
<li><a class="nav-link" href="{% url 'movies:index'%}">Home</a></li>
<li><a class="nav-link" href="{% url 'movies:all_movies'%}">Movies</a></li>
<li><a class="nav-link" href="{% url 'accounts:list_favourites' %}">Favourites</a></li>
Expand Down
17 changes: 17 additions & 0 deletions movies/templates/movies/edit_movie.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "base.html" %}

{% block content %}

<fieldset name="Video File Upload and Display">
{% if msg %} {% autoescape off %} {{ msg }} {% endautoescape %} {% endif %}

<form method="post" action="{% url 'movies:edit_movie' movie.id %}" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<p>
<button type="submit">Update Movie Details </button>
</p>
</form>
</fieldset>

{% endblock content %}
3 changes: 1 addition & 2 deletions movies/templates/movies/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

<h1>This is the Index Page</h1>


<body>
<div>
<form action="">
Expand All @@ -13,4 +12,4 @@ <h1>This is the Index Page</h1>
</div>
</body>

{% endblock content %}
{% endblock content %}
46 changes: 46 additions & 0 deletions movies/templates/movies/movies copy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% extends "base.html" %}

{% block content %}

<h1>Lists of all posts</h1>

{% for movie in page_obj %}

<a href="{% url 'movies:view_movie' movie.id %}">
<video width="320" height="240" controlsList="nodownload">
<source src="{{ MEDIA_URL }}/{{ movie.video }}" type="video/mp4">
</video>
</a>

{% empty %}

<h3>
No Movies have been added yet.
</h3>

<li><a class="nav-link" href="{% url 'movies:new_movie'%}">Add Movie</a></li>

{% endfor %}


<div class="pagination">
<span class="step-links">
{% if page_obj.has_previous %}
<a href="?page=1">&laquo; first</a>
<a href="?page={{ page_obj.previous_page_number }}">previous</a>
{% endif %}

<span class="current">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
</span>

{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}">next</a>
<a href="?page={{ page_obj.paginator.num_pages }}">last &raquo;</a>
{% endif %}
</span>
</div>



{% endblock content %}
153 changes: 140 additions & 13 deletions movies/templates/movies/movies.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,153 @@
{% extends "base.html" %}

{% load static %}
{% block content %}

<h1>Lists of all posts</h1>
<body>

<style>
p {
font-family: Roboto, Ariel;
margin-top: 0;
margin-bottom: 0;
}

.thumbnail {
width: 100%;
}

.search-bar {
display: block;
}

.author {}

.stats {}

.heading {
margin-top: 0px;
font-size: 14px;
font-weight: 500;
line-height: 20px;
margin-bottom: 10px;

}

.preview {}

.video-info-grid {
display: grid;
grid-template-columns: 50px 1fr
}


.video-info {
margin-left: 10px;
}

.profile-picture {
width: 100%;
border-radius: 80px;

}

.thumbnail-row {
margin-bottom: 12px;

}

.author,
.stats {
font-size: 12px;
color: rgb(96, 96, 96);
}

.author {
margin-bottom: 6px;
}

.all-video-grid {
column-gap: 16px;
row-gap: 30px;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
</style>

<input class="search-bar" type="text" placeholder="Search">
<br>

<section class="all-video-grid">

{% for movie in page_obj %}
<section class="preview">
<section class="thumbnail-row">
<!-- <img class="thumbnail" src="{{ movie.author. }}" alt="first image"> -->
<a href="{% url 'movies:view_movie' movie.id %}">
<video width="320" height="240" controlsList="nodownload">
<source src="{{ MEDIA_URL }}/{{ movie.video }}" type="video/mp4">
</video>
</a>
</section>

{% for movie in movies %}
<section class="video-info-grid">
{% if movie.author.userinfo.avatar %}
<section class="channel-picture">
<img class="profile-picture" src="{{ movie.author.userinfo.avatar.url }}" alt="">
</section>
{% else %}
<section class="channel-picture">
<img class="profile-picture" src="{% static 'dummy.png' %}" alt="">
</section>
{% endif %}

<a href="{% url 'movies:view_movie' movie.id %}">
<video width="320" height="240" controlsList="nodownload">
<source src="{{ MEDIA_URL }}/{{ movie.video }}" type="video/mp4">
</video>
</a>
<section class="video-info">
<p class="heading">
{{ movie.title }}
</p>

<p class="author">
<a href="{% url 'movies:view_profile' movie.id %}">{{movie.author}}</a>
</p>

<p class="stats">
{{ movie.liked.count }} Likes · Updated : {{ movie.updated }}
</p>
</section>
</section>
</section>


{% empty %}

<h3>
No Movies have been added yet.
</h3>

<li><a class="nav-link" href="{% url 'movies:new_movie'%}">Add Movie</a></li>

{% endfor %}
</section>


{% empty %}
</body>

<h3>
No Movies have been added yet.
</h3>
<div class="">
<span class="step-links">
{% if page_obj.has_previous %}
<a href="?page=1">&laquo; first</a>
<a href="?page={{ page_obj.previous_page_number }}">previous</a>
{% endif %}

<li><a class="nav-link" href="{% url 'movies:new_movie'%}">Add Movie</a></li>
<span class="current">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
</span>

{% endfor %}
{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}">next</a>
<a href="?page={{ page_obj.paginator.num_pages }}">last &raquo;</a>
{% endif %}
</span>
</div>

{% endblock content %}
57 changes: 49 additions & 8 deletions movies/templates/movies/new_movie.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,34 @@

<fieldset name="Video File Upload and Display">
{% if msg %} {% autoescape off %} {{ msg }} {% endautoescape %} {% endif %}
<form method="post" action="{% url 'movies:new_movie' %}" enctype="multipart/form-data">

<script>
var _validFileExtensions = [".mp4", ".mov"];
function Validate(oForm) {
var arrInputs = oForm.getElementsByTagName("input");
for (var i = 0; i < arrInputs.length; i++) {
var oInput = arrInputs[i]; if (oInput.type == "file") {
var
sFileName = oInput.value;
var blnValid = false;
for (var j = 0; j < _validFileExtensions.length; j++) {
var sCurExtension = _validFileExtensions[j]; if
(sFileName.substr(sFileName.length - sCurExtension.length,
sCurExtension.length).toLowerCase() == sCurExtension.toLowerCase()) { blnValid = true; break; }
} if (!blnValid) {
alert("Invalid File Format, allowed extensions are: " + _validFileExtensions.join(" , "));
return false;
}
}
}

return true;
}
</script>

<form method="post" action="{% url 'movies:new_movie' %}" enctype="multipart/form-data" onsubmit="return Validate(this);">

{% csrf_token %}
<dl>
<!-- <p>
<label>Add Video Title</label>&nbsp;&nbsp;
<br>
<input type="text" name="title" autocomplete="off" >
Expand All @@ -20,15 +44,32 @@
<br>
<label>Browse and select a video file</label>&nbsp;&nbsp;
<br>
<input type="file" name="video" autocomplete="off" required>
</p> -->
<input type="file" name="video" autocomplete="off" required accept="video/*">

<script>
// create the video element but don't add it to the page
var vid = document.createElement('video');

document.querySelector('input[name = "video"]').addEventListener('change', function valid() {
// create url to use as the src of the video
var fileURL = URL.createObjectURL(this.files[0]);

{{ form.as_p }}
vid.src = fileURL;
// wait for duration to change from NaN to the actual duration

vid.ondurationchange = function () {

</dl>
if ((this.duration) > 900) {
alert("Video must be less than 15 minutes");
window.location.reload();
}
};
});
</script>

<!-- {{ form.as_p }} -->
<p>
<input type="submit" value="Upload">
<button type="submit" onclick="valid()">Upload Video </button>
</p>
</form>
</fieldset>
Expand Down
6 changes: 5 additions & 1 deletion movies/templates/movies/view_movie.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h3>{{ movie.title }}</h3>
{% else %}
<button style="background-color: greenyellow;" type="submit">Like</button>
{% endif %}
</form>`
</form>
{% if movie.liked.count < 1 %}
No Likes Yet!
{% elif movie.liked.count == 1 %}
Expand All @@ -48,6 +48,10 @@ <h3>{{ movie.title }}</h3>
<a href="{% url 'accounts:add_favourite' movie.id %}">Add to Favourites</a>
{% endif %}
</li>
{% if request.user == movie.author %}
<li><a href="{% url 'movies:edit_movie' movie.id %}">Edit Movie</a></li>
<li><a href="{% url 'movies:delete_movie' movie.id %}">Delete</a></li>
{% endif %}

<li><a href="{{movie.video.url}}">Download</a></li>
<li><a href="{% url 'movies:new_comment' movie.id %}">Add Comment</a></li>
Expand Down
4 changes: 4 additions & 0 deletions movies/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
path('movies/', views.all_movies, name='all_movies'),

path('view_movie/<int:movie_id>', views.view_movie, name='view_movie'),

path('edit_movie/<int:movie_id>/', views.edit_movie, name='edit_movie'),

path('delete_movie/<int:movie_id>/', views.delete_movie, name='delete_movie'),

path('view-profile/<int:movie_id>/', views.view_profile, name='view_profile'),

Expand Down
Loading

0 comments on commit 03f8992

Please sign in to comment.