mirror of
https://github.com/FuzzyGrim/Yamtrack.git
synced 2026-03-03 02:27:01 +00:00
add post score
This commit is contained in:
@@ -2,13 +2,14 @@ from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
class Media(models.Model):
|
||||
code = models.IntegerField()
|
||||
media_id = models.IntegerField()
|
||||
title = models.CharField(max_length=100)
|
||||
description = models.TextField()
|
||||
image = models.TextField()
|
||||
year = models.IntegerField()
|
||||
content = models.CharField(max_length=10)
|
||||
seasons = models.IntegerField()
|
||||
media_type = models.CharField(max_length=100)
|
||||
seasons = models.JSONField(default=dict)
|
||||
ind_score = models.FloatField()
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.navbar-brand.abs .form-select {
|
||||
.navbar-brand.abs .form-select, #search main .box .content .input-group .form-select {
|
||||
border-radius: 0;
|
||||
width: auto;
|
||||
background-color: #262A2D;
|
||||
@@ -48,7 +48,7 @@ form .btn{
|
||||
}
|
||||
|
||||
main {
|
||||
padding: 6em 2em 2em 2em;
|
||||
margin: 6em 2em 2em 2em;
|
||||
}
|
||||
|
||||
#search main .box {
|
||||
@@ -88,16 +88,16 @@ main {
|
||||
width: 12rem;
|
||||
}
|
||||
|
||||
#search main .box .content .input-group .form-select{
|
||||
width: auto;
|
||||
}
|
||||
|
||||
#search main .box .content .input-group .form-control{
|
||||
border-width: 1px;
|
||||
width: 4rem;
|
||||
border-radius: 0;
|
||||
border-style: solid;
|
||||
border-color: #56595D;
|
||||
background-color: #232224;
|
||||
}
|
||||
|
||||
input[type=number] {
|
||||
#search input[type=number] {
|
||||
appearance: textfield;
|
||||
-moz-appearance: textfield;
|
||||
}
|
||||
@@ -45,16 +45,34 @@
|
||||
<div>
|
||||
<form class="d-flex input-group" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
{% if query.seasons and query.seasons != 1 %}
|
||||
<select name="content" class="form-select w-25">
|
||||
<select name="season" class="form-select w-25">
|
||||
{% load extras %}
|
||||
{% for i in query.seasons|times %}
|
||||
<option value="S{{forloop.counter}}">S{{forloop.counter}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
||||
{% endif %}
|
||||
<input type="number" class="form-control bg-dark text-white" placeholder="10" aria-label="10" maxlength="3" step="0.5" min="0" max="10">
|
||||
|
||||
<input type="number" class="form-control bg-dark text-white" name="score" placeholder="10" aria-label="10" maxlength="3" step="0.1" min="0" max="10" required>
|
||||
{% if query.name %}
|
||||
<input type="hidden" name="title" value="{{ query.name }}">
|
||||
{% if query.first_air_date %}
|
||||
<input type="hidden" name="year" value="{{ query.first_air_date|slice:"4" }}">
|
||||
{% endif %}
|
||||
<input type="hidden" name="media_type" value="tv">
|
||||
{% else %}
|
||||
<input type="hidden" name="title" value="{{ query.title }}">
|
||||
{% if query.release_date %}
|
||||
<input type="hidden" name="year" value="{{ query.release_date|slice:"4" }}">
|
||||
{% endif %}
|
||||
<input type="hidden" name="media_type" value="movie">
|
||||
{% endif %}
|
||||
<input type="hidden" name="media_id" value="{{ query.id }}">
|
||||
<input type="hidden" name="description" value="{{ query.overview }}">
|
||||
<input type="hidden" name="image" value="{{ query.poster_path }}">
|
||||
|
||||
<button class="btn bg-dark text-white" type="submit"><i class="bi bi-check-lg"></i></button>
|
||||
</form>
|
||||
|
||||
|
||||
89
app/views.py
89
app/views.py
@@ -1,14 +1,17 @@
|
||||
from django.shortcuts import render, redirect
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth import update_session_auth_hash
|
||||
from django.contrib.auth.forms import UserCreationForm, PasswordChangeForm
|
||||
from django.contrib.auth.decorators import login_required, user_passes_test
|
||||
from django.views.generic import ListView, CreateView
|
||||
from app.forms import UserUpdateForm
|
||||
from app.models import Media
|
||||
from app.utils import api
|
||||
|
||||
|
||||
def home(request):
|
||||
"""Home page"""
|
||||
if ("content" and "query") in request.POST:
|
||||
if ("query") in request.POST:
|
||||
return redirect(
|
||||
"/search/" + request.POST["content"] + "/" + request.POST["query"] + "/"
|
||||
)
|
||||
@@ -18,51 +21,95 @@ def home(request):
|
||||
|
||||
def search(request, content, query):
|
||||
"""Search page"""
|
||||
if ("content" and "query") in request.POST:
|
||||
if "query" in request.POST:
|
||||
return redirect(
|
||||
"/search/" + request.POST["content"] + "/" + request.POST["query"] + "/"
|
||||
)
|
||||
# elif ("season" and "number" and "title" and "description" and "image" and "year" and "media_id") in request.POST:
|
||||
|
||||
elif "score" in request.POST:
|
||||
if request.user.is_authenticated:
|
||||
add_media(request)
|
||||
else:
|
||||
messages.info(request, "Please log in to add media to your list.")
|
||||
|
||||
return redirect("/search/" + content + "/" + query + "/")
|
||||
|
||||
|
||||
context = {
|
||||
"query_list": api.search(content, query)
|
||||
}
|
||||
query_list = api.search(content, query)
|
||||
|
||||
|
||||
context = {"query_list": query_list}
|
||||
|
||||
return render(request, "app/search.html", context)
|
||||
|
||||
|
||||
@login_required
|
||||
def add_media(request):
|
||||
if "year" not in request.POST:
|
||||
year = 0
|
||||
else:
|
||||
year = request.POST["year"]
|
||||
|
||||
if "season" in request.POST:
|
||||
seasons = {request.POST["season"] : request.POST["score"]}
|
||||
Media.objects.create(
|
||||
media_id=request.POST["media_id"],
|
||||
title=request.POST["title"],
|
||||
description=request.POST["description"],
|
||||
image=request.POST["image"],
|
||||
year=year,
|
||||
media_type=request.POST["media_type"],
|
||||
seasons=seasons,
|
||||
user=request.user,
|
||||
)
|
||||
else:
|
||||
Media.objects.create(
|
||||
media_id=request.POST["media_id"],
|
||||
title=request.POST["title"],
|
||||
description=request.POST["description"],
|
||||
image=request.POST["image"],
|
||||
year=year,
|
||||
media_type=request.POST["media_type"],
|
||||
ind_score=request.POST["score"],
|
||||
user=request.user,
|
||||
)
|
||||
|
||||
|
||||
def register(request):
|
||||
if request.method == 'POST':
|
||||
if request.method == "POST":
|
||||
form = UserCreationForm(request.POST)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
username = form.cleaned_data.get('username')
|
||||
messages.success(request, f'Account created for {username}! You can now log in')
|
||||
return redirect('login')
|
||||
username = form.cleaned_data.get("username")
|
||||
messages.success(
|
||||
request, f"Account created for {username}! You can now log in"
|
||||
)
|
||||
return redirect("login")
|
||||
else:
|
||||
messages.info(request, "Please correct the error below.")
|
||||
else:
|
||||
form = UserCreationForm()
|
||||
return render(request, 'app/register.html', {'form': form})
|
||||
return render(request, "app/register.html", {"form": form})
|
||||
|
||||
|
||||
@login_required
|
||||
def profile(request):
|
||||
if request.method == 'POST':
|
||||
if request.method == "POST":
|
||||
user_form = UserUpdateForm(request.POST, instance=request.user)
|
||||
password_form = PasswordChangeForm(request.user, request.POST)
|
||||
if user_form.is_valid() and password_form.is_valid():
|
||||
user_form.save()
|
||||
password = password_form.save()
|
||||
update_session_auth_hash(request, password)
|
||||
messages.success(request, f'Your account has been updated!')
|
||||
return redirect('profile')
|
||||
messages.success(request, f"Your account has been updated!")
|
||||
return redirect("profile")
|
||||
else:
|
||||
messages.info(request, 'Please correct the error below.')
|
||||
messages.info(request, "Please correct the error below.")
|
||||
else:
|
||||
user_form = UserUpdateForm(instance=request.user)
|
||||
password_form = PasswordChangeForm(request.user)
|
||||
|
||||
context = {
|
||||
'user_form': user_form,
|
||||
'password_form': password_form
|
||||
}
|
||||
context = {"user_form": user_form, "password_form": password_form}
|
||||
|
||||
return render(request, 'app/profile.html', context)
|
||||
return render(request, "app/profile.html", context)
|
||||
|
||||
Reference in New Issue
Block a user