first commit

This commit is contained in:
ayxan
2022-08-24 17:37:03 +04:00
commit f9930c2476
53 changed files with 785 additions and 0 deletions

0
src/series/__init__.py Normal file
View File

5
src/series/admin.py Normal file
View File

@@ -0,0 +1,5 @@
from django.contrib import admin
from .models import SeriesModel
admin.site.register(SeriesModel)

6
src/series/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class SeriesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'series'

42
src/series/models.py Normal file
View File

@@ -0,0 +1,42 @@
from django.db import models
from django.core.exceptions import ValidationError
from API_client import APIClient
from django.core.validators import (MaxValueValidator,
MinValueValidator,
MinLengthValidator)
class SeriesModel(models.Model):
user = models.ForeignKey('account.User', on_delete=models.CASCADE, related_name='series')
title = models.CharField(max_length=35, blank=False, null=False)
imdb_id = models.CharField(max_length=10, validators=[MinLengthValidator(9)],
blank=False, null=False)
last_season = models.IntegerField(validators=[
MaxValueValidator(30),
MinValueValidator(1)
], blank=False, null=False)
last_episode = models.IntegerField(validators=[
MaxValueValidator(60),
MinValueValidator(1)
], blank=False, null=False)
show = models.BooleanField(default=True)
def clean(self) -> None:
if len(self.imdb_id) < 9:
raise ValidationError(f'Ensure this value has at least 9 characters (it has {len(self.imdb_id)}).')
if len(self.imdb_id) > 10:
raise ValidationError(f'Make sure this value is no more than 10 characters (it has {len(self.imdb_id)}).')
client = APIClient(self.user.imdb_api_key)
seasons = client.get_seasons(self.imdb_id)
if str(self.last_season) not in seasons:
raise ValidationError('The season number you entered is not correct.')
episodes_count = client.get_episodes_count(self.last_season, self.imdb_id)
if self.last_episode > episodes_count:
raise ValidationError('The episode number you entered is not correct.')
def __str__(self) -> str:
return f"{self.user.username} - {self.title}"

View File

@@ -0,0 +1,9 @@
{% extends 'base.html' %}
{% block title %} Home Page {% endblock title %}
{% block content %}
{% include 'components/message.html' %}
{% endblock content %}

3
src/series/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

8
src/series/urls.py Normal file
View File

@@ -0,0 +1,8 @@
from django.urls import path
from series import views
urlpatterns = [
path('', views.homepage_view, name='homepage'),
# path('series/create', views.homepage_view, name='homepage'),
]

View File

@@ -0,0 +1 @@
from .homepage import homepage_view

View File

@@ -0,0 +1,7 @@
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
@login_required(login_url='/account/login')
def homepage_view(request):
return render(request, 'homepage.html')