move to git

This commit is contained in:
Mike0001-droid 2024-05-24 16:20:49 +05:00
parent 63f3f04669
commit 9c7b456c1d
165 changed files with 11071 additions and 1 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
ITRadio/ITRadioBackend/db.sqlite3

View File

@ -0,0 +1,16 @@
"""
ASGI config for ITRadioBackend project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ITRadioBackend.settings')
application = get_asgi_application()

View File

@ -0,0 +1,163 @@
"""
Django settings for ITRadioBackend project.
Generated by 'django-admin startproject' using Django 5.0.4.
For more information on this file, see
https://docs.djangoproject.com/en/5.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.0/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-z242=*-knp4h=0l1*o-nyid^y0bwt4bvg3tf*wvr(qszj&!8$c'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
'rest_framework_simplejwt',
'rest_framework.authtoken',
'news',
'rubricks',
'loginApi',
'userProfile',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
]
ROOT_URLCONF = 'ITRadioBackend.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'ITRadioBackend.wsgi.application'
# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/
STATIC_URL = 'static/'
# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
],
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
'rest_framework_simplejwt.authentication.JWTStatelessUserAuthentication',
),
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
}
CORS_ALLOWED_ORIGINS = [
'http://localhost:5173', # Adjust the port if your Vue app is served on a different one
'http://127.0.0.1:5173',
]
from datetime import timedelta
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=180),
'REFRESH_TOKEN_LIFETIME': timedelta(days=30),
}
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOWED_ORIGINS = [
'http://localhost:5173',
]

View File

@ -0,0 +1,34 @@
from django.contrib import admin
from rest_framework.documentation import include_docs_urls
from django.urls import path, include
# from api.views import AzuraNowPlayingWebhookView
from loginApi.views import login, register
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
TokenVerifyView,
)
from news import views as newsViews
from rest_framework import routers, serializers, viewsets
from userProfile.views import ProfileViewSet
router = routers.DefaultRouter()
router.register(r'news', newsViews.NewsViewSet)
router.register(r'profiles', ProfileViewSet, basename='profiles')
urlpatterns = [
path('admin/', admin.site.urls),
path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
path('api/token/verify/', TokenVerifyView.as_view(), name='token_verify'),
path('api/', include_docs_urls(title='API docs')),
path('', include(router.urls)),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
# path('webhook/', AzuraNowPlayingWebhookView.as_view(), name='webhook-receiver'),
path('api/login/', login, name='login'),
path('api/register/', register, name='register'),
]

View File

@ -0,0 +1,16 @@
"""
WSGI config for ITRadioBackend project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ITRadioBackend.settings')
application = get_wsgi_application()

View File

View File

@ -0,0 +1,5 @@
# from django.contrib import admin
# from .models import NowPlayingSong
# # Register your models here.
# admin.site.register(NowPlayingSong)

View File

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

View File

@ -0,0 +1,26 @@
# Generated by Django 5.0.4 on 2024-04-21 17:43
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='NowPlayingSong',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255)),
('artist', models.CharField(max_length=255)),
('album', models.CharField(blank=True, max_length=255, null=True)),
('genre', models.CharField(blank=True, max_length=100, null=True)),
('art_url', models.URLField(blank=True, null=True)),
('duration', models.IntegerField()),
],
),
]

View File

@ -0,0 +1,17 @@
# Generated by Django 5.0.4 on 2024-04-21 18:13
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('api', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='nowplayingsong',
name='duration',
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 5.0.4 on 2024-04-21 18:51
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('api', '0002_remove_nowplayingsong_duration'),
]
operations = [
migrations.RenameField(
model_name='nowplayingsong',
old_name='art_url',
new_name='art',
),
]

View File

@ -0,0 +1,16 @@
# Generated by Django 5.0.4 on 2024-04-24 14:17
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('api', '0003_rename_art_url_nowplayingsong_art'),
]
operations = [
migrations.DeleteModel(
name='NowPlayingSong',
),
]

View File

@ -0,0 +1,10 @@
# from django.db import models
# class NowPlayingSong(models.Model):
# title = models.CharField(max_length=255)
# artist = models.CharField(max_length=255)
# album = models.CharField(max_length=255, blank=True, null=True)
# genre = models.CharField(max_length=100, blank=True, null=True)
# art = models.URLField(blank=True, null=True)

View File

@ -0,0 +1,16 @@
# from rest_framework import serializers
# from .models import NowPlayingSong
# class NowPlayingSongSerializer(serializers.ModelSerializer):
# class Meta:
# model = NowPlayingSong
# fields = ['title', 'artist', 'album', 'genre', 'art']
# class WebhookSerializer(serializers.Serializer):
# song = NowPlayingSongSerializer()
# def create(self, validated_data):
# print("create")
# song_data = validated_data.get('song')
# print(song_data)
# return NowPlayingSong.objects.create(**song_data)

View File

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

View File

@ -0,0 +1,18 @@
# from rest_framework.views import APIView
# from rest_framework.response import Response
# from .models import NowPlayingSong
# from .serializers import WebhookSerializer
# import json
# class AzuraNowPlayingWebhookView(APIView):
# queryset = NowPlayingSong.objects.all()
# def post(self, request, *args, **kwargs):
# # Ensure the 'now_playing' data includes a 'song' key
# data = request.data.get('now_playing')
# serializer = WebhookSerializer(data=data)
# print(data)
# if serializer.is_valid():
# song = serializer.save()
# print("valid")
# return Response(data, status=201)
# return Response(serializer.errors, status=400)

View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View File

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

View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

View File

@ -0,0 +1,18 @@
from django.contrib.auth.models import User
from rest_framework import serializers
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ['username', 'email', 'password']
extra_kwargs = {
'password': {'write_only': True}
}
def create(self, validated_data):
user = User.objects.create_user(
username=validated_data['username'],
email=validated_data['email'],
password=validated_data['password']
)
return user

View File

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

View File

@ -0,0 +1,53 @@
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
from django.contrib.auth import authenticate
from rest_framework_simplejwt.tokens import RefreshToken
from rest_framework import generics
from django.contrib.auth.models import User
from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import AllowAny
from userProfile.serializers import ProfileSerializer
from loginApi.serializers import UserSerializer
@api_view(['POST'])
@permission_classes([AllowAny])
def login(request):
def post(self, request):
username = request.data.get('username')
password = request.data.get('password')
user = authenticate(username=username, password=password)
if user is not None:
refresh = RefreshToken.for_user(user)
return Response({
'refresh': str(refresh),
'access': str(refresh.access_token),
})
return Response({'error': 'Invalid Credentials'}, status=status.HTTP_401_UNAUTHORIZED)
@api_view(['POST'])
@permission_classes([AllowAny])
def register(request):
user_serializer = UserSerializer(data=request.data)
if user_serializer.is_valid():
user = user_serializer.save()
profile_data = request.data.get('profile', {})
profile_data['user'] = user.id # Ensure the user ID is included in the profile data
profile_serializer = ProfileSerializer(data=profile_data)
if profile_serializer.is_valid():
profile_serializer.save()
refresh = RefreshToken.for_user(user)
return Response({
'user': user_serializer.data,
'profile': profile_serializer.data,
'refresh': str(refresh),
'access': str(refresh.access_token),
}, status=status.HTTP_201_CREATED)
else:
return Response(profile_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
return Response(user_serializer.errors, status=status.HTTP_400_BAD_REQUEST)

View File

@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ITRadioBackend.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

View File

View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View File

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

View File

@ -0,0 +1,14 @@
from django.db import models
# class Song(models.Model):
# name = models.CharField(max_length=255)
# artist = models.CharField(max_length=255)
# album = models.ForeignKey('Album', on_delete=models.CASCADE)
# ...
# class Playlist(models.Model):
# songs = models.ManyToManyField(Song)
# class Podcast(models.Model):
# name = models.CharField(max_length=255)
# hosts = models.CharField(max_length=255)

View File

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

View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View File

View File

@ -0,0 +1,8 @@
from django.contrib import admin
from .models import News
class NewsAdmin(admin.ModelAdmin):
list_display = ('name', 'date') # поля, которые будут отображаться
ordering = ('-date',) # сортировка по дате в обратном порядке
admin.site.register(News, NewsAdmin)

View File

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

View File

@ -0,0 +1,24 @@
# Generated by Django 5.0.4 on 2024-04-16 15:16
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='News',
fields=[
('id', models.BigAutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=255)),
('description', models.TextField()),
('date', models.DateTimeField()),
('author', models.CharField(max_length=255)),
],
),
]

View File

@ -0,0 +1,23 @@
# Generated by Django 5.0.4 on 2024-04-16 15:47
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('news', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='news',
name='author',
field=models.CharField(blank=True, max_length=255),
),
migrations.AlterField(
model_name='news',
name='date',
field=models.DateTimeField(blank=True),
),
]

View File

@ -0,0 +1,9 @@
from django.db import models
class News(models.Model):
id = models.BigAutoField(primary_key=True)
name = models.CharField(max_length=255)
description = models.TextField()
date = models.DateTimeField(blank=True)
author = models.CharField(max_length=255, blank=True)

View File

@ -0,0 +1,7 @@
from rest_framework import serializers
from .models import News
class NewsSerializer(serializers.ModelSerializer):
class Meta:
model = News
fields = ['id', 'name', 'description', 'date', 'author']

View File

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

View File

@ -0,0 +1,10 @@
# Create your views here.
from rest_framework import viewsets
from .models import News
from news.serializers import NewsSerializer
class NewsViewSet(viewsets.ModelViewSet):
queryset = News.objects.all()
serializer_class = NewsSerializer

View File

@ -0,0 +1,7 @@
from django.contrib import admin
from .models import Rubric
class RubricAdmin(admin.ModelAdmin):
list_display = ('name', 'description')
admin.site.register(Rubric, RubricAdmin)

View File

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

View File

@ -0,0 +1,23 @@
# Generated by Django 5.0.4 on 2024-04-16 15:16
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Rubric',
fields=[
('id', models.BigAutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=255)),
('description', models.TextField()),
('time', models.DateTimeField()),
],
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 5.0.4 on 2024-04-16 16:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('rubricks', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='rubric',
name='time',
field=models.DateTimeField(blank=True),
),
]

View File

@ -0,0 +1,17 @@
# Generated by Django 5.0.4 on 2024-05-06 19:19
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('rubricks', '0002_alter_rubric_time'),
]
operations = [
migrations.RemoveField(
model_name='rubric',
name='time',
),
]

View File

@ -0,0 +1,7 @@
from django.db import models
class Rubric(models.Model):
id = models.BigAutoField(primary_key=True)
name = models.CharField(max_length=255)
description = models.TextField()

View File

@ -0,0 +1,7 @@
from rest_framework import serializers
from .models import Rubric
class RubricSerializer(serializers.ModelSerializer):
class Meta:
model = Rubric
fields = ['id', 'name', 'description', 'time']

View File

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

View File

@ -0,0 +1,7 @@
from rest_framework import viewsets
from .models import Rubric
from .serializers import RubricSerializer
class RubricViewSet(viewsets.ModelViewSet):
queryset = Rubric.objects.all()
serializer_class = RubricSerializer

View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View File

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

View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

View File

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

View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View File

@ -0,0 +1,15 @@
from django.contrib import admin
from rest_framework.authtoken.admin import TokenAdmin
from .models import Profile
TokenAdmin.raw_id_fields = ['user']
class ProfileAdmin(admin.ModelAdmin):
list_display = ('user', 'likedSongs') # Add other fields if necessary
admin.site.register(Profile, ProfileAdmin)

View File

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

View File

@ -0,0 +1,25 @@
# Generated by Django 5.0.4 on 2024-04-25 14:58
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Profile',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('likedSongs', models.JSONField(default=list)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]

Some files were not shown because too many files have changed in this diff Show More