mirror of
https://github.com/aykhans/series-robot-web.git
synced 2025-09-08 15:30:43 +00:00
API_clien app removed
This commit is contained in:
@@ -1,21 +1,10 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from API_client import APIClient
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
imdb_api_key = models.CharField(max_length=15, blank=False, null=False)
|
||||
|
||||
def clean(self) -> None:
|
||||
client = APIClient(self.imdb_api_key)
|
||||
client.key_control()
|
||||
# raw_data = get(f"https://imdb-api.com/en/API/Title/{self.imdb_api_key}/tt0110413")
|
||||
|
||||
# if raw_data.status_code == 200: data = raw_data.json()
|
||||
# else: raise ValidationError('Account not created. Please try again later')
|
||||
# if not data['errorMessage']: raise ValidationError(data['errorMessage'])
|
||||
|
||||
class Meta:
|
||||
db_table = 'user'
|
||||
verbose_name = 'User'
|
||||
|
@@ -5,6 +5,7 @@
|
||||
{% block title %} Signup {% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
{% include 'components/message.html' %}
|
||||
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
|
@@ -2,7 +2,6 @@ from django.shortcuts import render, redirect
|
||||
from django.contrib import messages
|
||||
from account.forms import RegisterForm
|
||||
from django.contrib.auth import login, authenticate
|
||||
from django.core.exceptions import ValidationError
|
||||
from requests import get
|
||||
|
||||
|
||||
@@ -10,15 +9,16 @@ def register_view(request):
|
||||
if request.method == 'POST':
|
||||
form = RegisterForm(request.POST)
|
||||
if form.is_valid():
|
||||
# raw_data = get(f"https://imdb-api.com/en/API/Title/{request.POST['imdb_api_key']}/tt0110413")
|
||||
# if raw_data.status_code == 200: data = raw_data.json()
|
||||
# else:
|
||||
# messages.info(request, 'Account not created. Please try again later')
|
||||
# return redirect('register')
|
||||
raw_data = get(f"https://imdb-api.com/en/API/Title/{request.POST['imdb_api_key']}/tt0110413")
|
||||
|
||||
# if data['errorMessage'] == 'Invalid API Key':
|
||||
# messages.info(request, 'Invalid API Key')
|
||||
# return redirect('register')
|
||||
if raw_data.status_code != 200:
|
||||
messages.info(request, 'Account not created. Please try again later')
|
||||
return redirect('register')
|
||||
data = raw_data.json()
|
||||
|
||||
if data['errorMessage'] == 'Invalid API Key':
|
||||
form.add_error('imdb_api_key', 'Invalid API Key')
|
||||
return render(request, 'register.html', context={"form": form})
|
||||
|
||||
form.save()
|
||||
username = form.cleaned_data.get('username')
|
||||
|
Reference in New Issue
Block a user