-
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52dd3f8
commit 09eb811
Showing
10 changed files
with
940 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
ASGI config for api 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/3.0/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.settings') | ||
|
||
application = get_asgi_application() |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
from django.contrib.auth import get_user_model | ||
from rest_framework import routers, serializers, viewsets | ||
from .models import SmartBlock, SmartBlockContents, SmartBlockCriteria, Country, File, ListenerCount, LiveLog, LoginAttempts, MountName, MusicDir, StreamSetting | ||
|
||
class UserSerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = get_user_model() | ||
fields = [ | ||
'url', | ||
'username', | ||
'type', | ||
'first_name', | ||
'last_name', | ||
'lastfail', | ||
'skype_contact', | ||
'jabber_contact', | ||
'email', | ||
'cell_phone', | ||
'login_attempts', | ||
] | ||
|
||
class UserViewSet(viewsets.ModelViewSet): | ||
queryset = get_user_model().objects.all() | ||
serializer_class = UserSerializer | ||
|
||
class StreamSettingSerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = StreamSetting | ||
fields = '__all__' | ||
|
||
class StreamSettingViewSet(viewsets.ModelViewSet): | ||
queryset = StreamSetting.objects.all() | ||
serializer_class = StreamSettingSerializer | ||
|
||
class SmartBlockSerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = SmartBlock | ||
fields = '__all__' | ||
|
||
class SmartBlockViewSet(viewsets.ModelViewSet): | ||
queryset = SmartBlock.objects.all() | ||
serializer_class = SmartBlockSerializer | ||
|
||
class SmartBlockContentsSerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = SmartBlockContents | ||
fields = '__all__' | ||
|
||
class SmartBlockContentsViewSet(viewsets.ModelViewSet): | ||
queryset = SmartBlockContents.objects.all() | ||
serializer_class = SmartBlockContentsSerializer | ||
|
||
class SmartBlockCriteriaSerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = SmartBlockCriteria | ||
fields = '__all__' | ||
|
||
class SmartBlockCriteriaViewSet(viewsets.ModelViewSet): | ||
queryset = SmartBlockCriteria.objects.all() | ||
serializer_class = SmartBlockCriteriaSerializer | ||
|
||
class CountrySerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = Country | ||
fields = '__all__' | ||
|
||
class CountryViewSet(viewsets.ModelViewSet): | ||
queryset = Country.objects.all() | ||
serializer_class = CountrySerializer | ||
|
||
class FileSerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = File | ||
fields = '__all__' | ||
|
||
class FileViewSet(viewsets.ModelViewSet): | ||
queryset = File.objects.all() | ||
serializer_class = FileSerializer | ||
|
||
class ListenerCountSerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = ListenerCount | ||
fields = '__all__' | ||
|
||
class ListenerCountViewSet(viewsets.ModelViewSet): | ||
queryset = ListenerCount.objects.all() | ||
serializer_class = ListenerCountSerializer | ||
|
||
class LiveLogSerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = LiveLog | ||
fields = '__all__' | ||
|
||
class LiveLogViewSet(viewsets.ModelViewSet): | ||
queryset = LiveLog.objects.all() | ||
serializer_class = LiveLogSerializer | ||
|
||
class LoginAttemptsSerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = LoginAttempts | ||
fields = '__all__' | ||
|
||
class LoginAttemptsViewSet(viewsets.ModelViewSet): | ||
queryset = LoginAttempts.objects.all() | ||
serializer_class = LoginAttemptsSerializer | ||
|
||
class MountNameSerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = MountName | ||
fields = '__all__' | ||
|
||
class MountNameViewSet(viewsets.ModelViewSet): | ||
queryset = MountName.objects.all() | ||
serializer_class = MountNameSerializer | ||
|
||
class MusicDirSerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = MusicDir | ||
fields = '__all__' | ||
|
||
class MusicDirViewSet(viewsets.ModelViewSet): | ||
queryset = MusicDir.objects.all() | ||
serializer_class = MusicDirSerializer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import os | ||
|
||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | ||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = '1!h&ak55eg5_1dee@mg8&9iy)m+94d!l_89=@$zg=^##z6msue' | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = True | ||
|
||
ALLOWED_HOSTS = [] | ||
|
||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = [ | ||
'api', | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
'rest_framework', | ||
] | ||
|
||
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', | ||
] | ||
|
||
ROOT_URLCONF = 'api.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 = 'api.wsgi.application' | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases | ||
|
||
DATABASES = { | ||
'default': { | ||
#'ENGINE': 'django.db.backends.sqlite3', | ||
#'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | ||
'ENGINE': 'django.db.backends.postgresql', | ||
'NAME': 'airtime', | ||
'USER': 'airtime', | ||
'PASSWORD': 'airtime', | ||
'HOST': 'localhost', | ||
'PORT': '5432', | ||
} | ||
} | ||
|
||
|
||
# Password validation | ||
# https://docs.djangoproject.com/en/3.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', | ||
}, | ||
] | ||
|
||
REST_FRAMEWORK = { | ||
'DEFAULT_PERMISSION_CLASSES': [ | ||
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly', | ||
] | ||
} | ||
|
||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/3.0/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/3.0/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' | ||
|
||
AUTH_USER_MODEL = 'api.User' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django.conf.urls import url, include | ||
from rest_framework import routers | ||
|
||
from .serializers import SmartBlockViewSet, SmartBlockContentsViewSet, SmartBlockCriteriaViewSet, CountryViewSet, FileViewSet, ListenerCountViewSet, LiveLogViewSet, LoginAttemptsViewSet, MountNameViewSet, MusicDirViewSet, UserViewSet, StreamSettingViewSet | ||
|
||
router = routers.DefaultRouter() | ||
router.register(r'users', UserViewSet) | ||
router.register(r'smartblock', SmartBlockViewSet) | ||
router.register(r'smartblock-contents', SmartBlockContentsViewSet) | ||
router.register(r'smartblock-criteria', SmartBlockCriteriaViewSet) | ||
router.register(r'country', CountryViewSet) | ||
router.register(r'files', FileViewSet) | ||
router.register(r'listener-counts', ListenerCountViewSet) | ||
router.register(r'live-log', LiveLogViewSet) | ||
router.register(r'login-attempts', LoginAttemptsViewSet) | ||
router.register(r'mount-names', MountNameViewSet) | ||
router.register(r'music-directories', MusicDirViewSet) | ||
router.register(r'login-attempts', LoginAttemptsViewSet) | ||
router.register(r'stream-settings', StreamSettingViewSet) | ||
|
||
urlpatterns = [ | ||
url(r'^', include(router.urls)), | ||
url(r'api-auth/', include('rest_framework.urls', namespace='rest_framework')), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
WSGI config for api 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/3.0/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.settings') | ||
|
||
application = get_wsgi_application() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env python | ||
"""Django's command-line utility for administrative tasks.""" | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name='libretime-api', | ||
version='2.0.0alpha1', | ||
packages=find_packages(), | ||
description='LibreTime API backend server', | ||
url='https://github.com/LibreTime/libretime', | ||
install_requires=[ | ||
'django', | ||
'djangorestframework', | ||
'markdown', | ||
'django-filter', | ||
'coreapi', | ||
'psycopg2', | ||
], | ||
project_urls={ | ||
'Bug Tracker': 'https://github.com/LibreTime/libretime/issues', | ||
'Documentation': 'https://libretime.org', | ||
'Source Code': 'https://github.com/LibreTime/libretime', | ||
}, | ||
) |