Verified Commit 62ca3bd7 authored by Agate's avatar Agate 💬

Blacked the code

parent b6fc0051
...@@ -12,70 +12,70 @@ from dynamic_preferences.api.viewsets import GlobalPreferencesViewSet ...@@ -12,70 +12,70 @@ from dynamic_preferences.api.viewsets import GlobalPreferencesViewSet
from dynamic_preferences.users.viewsets import UserPreferencesViewSet from dynamic_preferences.users.viewsets import UserPreferencesViewSet
router = routers.SimpleRouter() router = routers.SimpleRouter()
router.register(r'settings', GlobalPreferencesViewSet, base_name='settings') router.register(r"settings", GlobalPreferencesViewSet, base_name="settings")
router.register(r'activity', activity_views.ActivityViewSet, 'activity') router.register(r"activity", activity_views.ActivityViewSet, "activity")
router.register(r'tags', views.TagViewSet, 'tags') router.register(r"tags", views.TagViewSet, "tags")
router.register(r'tracks', views.TrackViewSet, 'tracks') router.register(r"tracks", views.TrackViewSet, "tracks")
router.register(r'trackfiles', views.TrackFileViewSet, 'trackfiles') router.register(r"trackfiles", views.TrackFileViewSet, "trackfiles")
router.register(r'artists', views.ArtistViewSet, 'artists') router.register(r"artists", views.ArtistViewSet, "artists")
router.register(r'albums', views.AlbumViewSet, 'albums') router.register(r"albums", views.AlbumViewSet, "albums")
router.register(r'import-batches', views.ImportBatchViewSet, 'import-batches') router.register(r"import-batches", views.ImportBatchViewSet, "import-batches")
router.register(r'import-jobs', views.ImportJobViewSet, 'import-jobs') router.register(r"import-jobs", views.ImportJobViewSet, "import-jobs")
router.register(r'submit', views.SubmitViewSet, 'submit') router.register(r"submit", views.SubmitViewSet, "submit")
router.register(r'playlists', playlists_views.PlaylistViewSet, 'playlists') router.register(r"playlists", playlists_views.PlaylistViewSet, "playlists")
router.register( router.register(
r'playlist-tracks', r"playlist-tracks", playlists_views.PlaylistTrackViewSet, "playlist-tracks"
playlists_views.PlaylistTrackViewSet, )
'playlist-tracks')
v1_patterns = router.urls v1_patterns = router.urls
subsonic_router = routers.SimpleRouter(trailing_slash=False) subsonic_router = routers.SimpleRouter(trailing_slash=False)
subsonic_router.register(r'subsonic/rest', SubsonicViewSet, base_name='subsonic') subsonic_router.register(r"subsonic/rest", SubsonicViewSet, base_name="subsonic")
v1_patterns += [ v1_patterns += [
url(r'^instance/', url(
r"^instance/",
include(("funkwhale_api.instance.urls", "instance"), namespace="instance"),
),
url(
r"^manage/",
include(("funkwhale_api.manage.urls", "manage"), namespace="manage"),
),
url(
r"^federation/",
include( include(
('funkwhale_api.instance.urls', 'instance'), ("funkwhale_api.federation.api_urls", "federation"), namespace="federation"
namespace='instance')), ),
url(r'^manage/', ),
include( url(
('funkwhale_api.manage.urls', 'manage'), r"^providers/",
namespace='manage')), include(("funkwhale_api.providers.urls", "providers"), namespace="providers"),
url(r'^federation/', ),
include( url(
('funkwhale_api.federation.api_urls', 'federation'), r"^favorites/",
namespace='federation')), include(("funkwhale_api.favorites.urls", "favorites"), namespace="favorites"),
url(r'^providers/', ),
include( url(r"^search$", views.Search.as_view(), name="search"),
('funkwhale_api.providers.urls', 'providers'), url(
namespace='providers')), r"^radios/",
url(r'^favorites/', include(("funkwhale_api.radios.urls", "radios"), namespace="radios"),
include( ),
('funkwhale_api.favorites.urls', 'favorites'), url(
namespace='favorites')), r"^history/",
url(r'^search$', include(("funkwhale_api.history.urls", "history"), namespace="history"),
views.Search.as_view(), name='search'), ),
url(r'^radios/', url(
include( r"^users/",
('funkwhale_api.radios.urls', 'radios'), include(("funkwhale_api.users.api_urls", "users"), namespace="users"),
namespace='radios')), ),
url(r'^history/', url(
include( r"^requests/",
('funkwhale_api.history.urls', 'history'), include(("funkwhale_api.requests.api_urls", "requests"), namespace="requests"),
namespace='history')), ),
url(r'^users/', url(r"^token/$", jwt_views.obtain_jwt_token, name="token"),
include( url(r"^token/refresh/$", jwt_views.refresh_jwt_token, name="token_refresh"),
('funkwhale_api.users.api_urls', 'users'),
namespace='users')),
url(r'^requests/',
include(
('funkwhale_api.requests.api_urls', 'requests'),
namespace='requests')),
url(r'^token/$', jwt_views.obtain_jwt_token, name='token'),
url(r'^token/refresh/$', jwt_views.refresh_jwt_token, name='token_refresh'),
] ]
urlpatterns = [ urlpatterns = [
url(r'^v1/', include((v1_patterns, 'v1'), namespace='v1')) url(r"^v1/", include((v1_patterns, "v1"), namespace="v1"))
] + format_suffix_patterns(subsonic_router.urls, allowed=['view']) ] + format_suffix_patterns(subsonic_router.urls, allowed=["view"])
...@@ -7,12 +7,13 @@ from funkwhale_api.common.auth import TokenAuthMiddleware ...@@ -7,12 +7,13 @@ from funkwhale_api.common.auth import TokenAuthMiddleware
from funkwhale_api.instance import consumers from funkwhale_api.instance import consumers
application = ProtocolTypeRouter({ application = ProtocolTypeRouter(
# Empty for now (http->django views is added by default) {
"websocket": TokenAuthMiddleware( # Empty for now (http->django views is added by default)
URLRouter([ "websocket": TokenAuthMiddleware(
url("^api/v1/instance/activity$", URLRouter(
consumers.InstanceActivityConsumer), [url("^api/v1/instance/activity$", consumers.InstanceActivityConsumer)]
]) )
), )
}) }
)
This diff is collapsed.
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
''' """
Local settings Local settings
- Run in Debug mode - Run in Debug mode
- Use console backend for emails - Use console backend for emails
- Add Django Debug Toolbar - Add Django Debug Toolbar
- Add django-extensions as app - Add django-extensions as app
''' """
from .common import * # noqa from .common import * # noqa
# DEBUG # DEBUG
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
DEBUG = env.bool('DJANGO_DEBUG', default=True) DEBUG = env.bool("DJANGO_DEBUG", default=True)
TEMPLATES[0]['OPTIONS']['debug'] = DEBUG TEMPLATES[0]["OPTIONS"]["debug"] = DEBUG
# SECRET CONFIGURATION # SECRET CONFIGURATION
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key # See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
# Note: This key only used for development and testing. # Note: This key only used for development and testing.
SECRET_KEY = env("DJANGO_SECRET_KEY", default='mc$&b=5j#6^bv7tld1gyjp2&+^-qrdy=0sw@r5sua*1zp4fmxc') SECRET_KEY = env(
"DJANGO_SECRET_KEY", default="mc$&b=5j#6^bv7tld1gyjp2&+^-qrdy=0sw@r5sua*1zp4fmxc"
)
# Mail settings # Mail settings
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
EMAIL_HOST = 'localhost' EMAIL_HOST = "localhost"
EMAIL_PORT = 1025 EMAIL_PORT = 1025
# django-debug-toolbar # django-debug-toolbar
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
MIDDLEWARE += ('debug_toolbar.middleware.DebugToolbarMiddleware',) MIDDLEWARE += ("debug_toolbar.middleware.DebugToolbarMiddleware",)
# INTERNAL_IPS = ('127.0.0.1', '10.0.2.2',) # INTERNAL_IPS = ('127.0.0.1', '10.0.2.2',)
DEBUG_TOOLBAR_CONFIG = { DEBUG_TOOLBAR_CONFIG = {
'DISABLE_PANELS': [ "DISABLE_PANELS": ["debug_toolbar.panels.redirects.RedirectsPanel"],
'debug_toolbar.panels.redirects.RedirectsPanel', "SHOW_TEMPLATE_CONTEXT": True,
], "SHOW_TOOLBAR_CALLBACK": lambda request: True,
'SHOW_TEMPLATE_CONTEXT': True,
'SHOW_TOOLBAR_CALLBACK': lambda request: True,
} }
# django-extensions # django-extensions
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# INSTALLED_APPS += ('django_extensions', ) # INSTALLED_APPS += ('django_extensions', )
INSTALLED_APPS += ('debug_toolbar', ) INSTALLED_APPS += ("debug_toolbar",)
# TESTING # TESTING
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
TEST_RUNNER = 'django.test.runner.DiscoverRunner' TEST_RUNNER = "django.test.runner.DiscoverRunner"
########## CELERY ########## CELERY
# In development, all tasks will be executed locally by blocking until the task returns # In development, all tasks will be executed locally by blocking until the task returns
...@@ -57,23 +57,15 @@ CELERY_TASK_ALWAYS_EAGER = False ...@@ -57,23 +57,15 @@ CELERY_TASK_ALWAYS_EAGER = False
# Your local stuff: Below this line define 3rd party library settings # Your local stuff: Below this line define 3rd party library settings
LOGGING = { LOGGING = {
'version': 1, "version": 1,
'handlers': { "handlers": {"console": {"level": "DEBUG", "class": "logging.StreamHandler"}},
'console':{ "loggers": {
'level':'DEBUG', "django.request": {
'class':'logging.StreamHandler', "handlers": ["console"],
}, "propagate": True,
}, "level": "DEBUG",
'loggers': {
'django.request': {
'handlers':['console'],
'propagate': True,
'level':'DEBUG',
},
'': {
'level': 'DEBUG',
'handlers': ['console'],
}, },
"": {"level": "DEBUG", "handlers": ["console"]},
}, },
} }
CSRF_TRUSTED_ORIGINS = [o for o in ALLOWED_HOSTS] CSRF_TRUSTED_ORIGINS = [o for o in ALLOWED_HOSTS]
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
''' """
Production Configurations Production Configurations
- Use djangosecure - Use djangosecure
...@@ -8,7 +8,7 @@ Production Configurations ...@@ -8,7 +8,7 @@ Production Configurations
- Use Redis on Heroku - Use Redis on Heroku
''' """
from __future__ import absolute_import, unicode_literals from __future__ import absolute_import, unicode_literals
from django.utils import six from django.utils import six
...@@ -58,19 +58,24 @@ CSRF_TRUSTED_ORIGINS = ALLOWED_HOSTS ...@@ -58,19 +58,24 @@ CSRF_TRUSTED_ORIGINS = ALLOWED_HOSTS
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Uploaded Media Files # Uploaded Media Files
# ------------------------ # ------------------------
DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage' DEFAULT_FILE_STORAGE = "django.core.files.storage.FileSystemStorage"
# Static Assets # Static Assets
# ------------------------ # ------------------------
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage"
# TEMPLATE CONFIGURATION # TEMPLATE CONFIGURATION
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# See: # See:
# https://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.loaders.cached.Loader # https://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.loaders.cached.Loader
TEMPLATES[0]['OPTIONS']['loaders'] = [ TEMPLATES[0]["OPTIONS"]["loaders"] = [
('django.template.loaders.cached.Loader', [ (
'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ]), "django.template.loaders.cached.Loader",
[
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
],
)
] ]
# CACHING # CACHING
...@@ -78,7 +83,6 @@ TEMPLATES[0]['OPTIONS']['loaders'] = [ ...@@ -78,7 +83,6 @@ TEMPLATES[0]['OPTIONS']['loaders'] = [
# Heroku URL does not pass the DB number, so we parse it in # Heroku URL does not pass the DB number, so we parse it in
# LOGGING CONFIGURATION # LOGGING CONFIGURATION
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#logging # See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
...@@ -88,43 +92,39 @@ TEMPLATES[0]['OPTIONS']['loaders'] = [ ...@@ -88,43 +92,39 @@ TEMPLATES[0]['OPTIONS']['loaders'] = [
# See http://docs.djangoproject.com/en/dev/topics/logging for # See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration. # more details on how to customize your logging configuration.
LOGGING = { LOGGING = {
'version': 1, "version": 1,
'disable_existing_loggers': False, "disable_existing_loggers": False,
'filters': { "filters": {"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}},
'require_debug_false': { "formatters": {
'()': 'django.utils.log.RequireDebugFalse' "verbose": {
"format": "%(levelname)s %(asctime)s %(module)s "
"%(process)d %(thread)d %(message)s"
} }
}, },
'formatters': { "handlers": {
'verbose': { "mail_admins": {
'format': '%(levelname)s %(asctime)s %(module)s ' "level": "ERROR",
'%(process)d %(thread)d %(message)s' "filters": ["require_debug_false"],
"class": "django.utils.log.AdminEmailHandler",
},
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "verbose",
}, },
}, },
'handlers': { "loggers": {
'mail_admins': { "django.request": {
'level': 'ERROR', "handlers": ["mail_admins"],
'filters': ['require_debug_false'], "level": "ERROR",
'class': 'django.utils.log.AdminEmailHandler' "propagate": True,
}, },
'console': { "django.security.DisallowedHost": {
'level': 'DEBUG', "level": "ERROR",
'class': 'logging.StreamHandler', "handlers": ["console", "mail_admins"],
'formatter': 'verbose', "propagate": True,
}, },
}, },
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True
},
'django.security.DisallowedHost': {
'level': 'ERROR',
'handlers': ['console', 'mail_admins'],
'propagate': True
}
}
} }
......
...@@ -11,32 +11,30 @@ from django.views import defaults as default_views ...@@ -11,32 +11,30 @@ from django.views import defaults as default_views
urlpatterns = [ urlpatterns = [
# Django Admin, use {% url 'admin:index' %} # Django Admin, use {% url 'admin:index' %}
url(settings.ADMIN_URL, admin.site.urls), url(settings.ADMIN_URL, admin.site.urls),
url(r"^api/", include(("config.api_urls", "api"), namespace="api")),
url(r'^api/', include(("config.api_urls", 'api'), namespace="api")), url(
url(r'^', include( r"^",
('funkwhale_api.federation.urls', 'federation'), include(
namespace="federation")), ("funkwhale_api.federation.urls", "federation"), namespace="federation"
url(r'^api/v1/auth/', include('rest_auth.urls')), ),
url(r'^api/v1/auth/registration/', include('funkwhale_api.users.rest_auth_urls')), ),
url(r'^accounts/', include('allauth.urls')), url(r"^api/v1/auth/", include("rest_auth.urls")),
url(r"^api/v1/auth/registration/", include("funkwhale_api.users.rest_auth_urls")),
url(r"^accounts/", include("allauth.urls")),
# Your stuff: custom urls includes go here # Your stuff: custom urls includes go here
] ]
if settings.DEBUG: if settings.DEBUG:
# This allows the error pages to be debugged during development, just visit # This allows the error pages to be debugged during development, just visit
# these url in browser to see how these error pages look like. # these url in browser to see how these error pages look like.
urlpatterns += [ urlpatterns += [
url(r'^400/$', default_views.bad_request), url(r"^400/$", default_views.bad_request),
url(r'^403/$', default_views.permission_denied), url(r"^403/$", default_views.permission_denied),
url(r'^404/$', default_views.page_not_found), url(r"^404/$", default_views.page_not_found),
url(r'^500/$', default_views.server_error), url(r"^500/$", default_views.server_error),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
if 'debug_toolbar' in settings.INSTALLED_APPS: if "debug_toolbar" in settings.INSTALLED_APPS:
import debug_toolbar import debug_toolbar
urlpatterns += [
url(r'^__debug__/', include(debug_toolbar.urls)), urlpatterns += [url(r"^__debug__/", include(debug_toolbar.urls))]
]
from funkwhale_api.users.models import User from funkwhale_api.users.models import User
u = User.objects.create(email='demo@demo.com', username='demo', is_staff=True) u = User.objects.create(email="demo@demo.com", username="demo", is_staff=True)
u.set_password('demo') u.set_password("demo")
u.subsonic_api_token = 'demo' u.subsonic_api_token = "demo"
u.save() u.save()
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
__version__ = '0.14.1' __version__ = "0.14.1"
__version_info__ = tuple([int(num) if num.isdigit() else num for num in __version__.replace('-', '.', 1).split('.')]) __version_info__ = tuple(
[
int(num) if num.isdigit() else num
for num in __version__.replace("-", ".", 1).split(".")
]
)
...@@ -2,8 +2,9 @@ from django.apps import AppConfig, apps ...@@ -2,8 +2,9 @@ from django.apps import AppConfig, apps
from . import record from . import record
class ActivityConfig(AppConfig): class ActivityConfig(AppConfig):
name = 'funkwhale_api.activity' name = "funkwhale_api.activity"
def ready(self): def ready(self):
super(ActivityConfig, self).ready() super(ActivityConfig, self).ready()
......
...@@ -2,37 +2,36 @@ import persisting_theory ...@@ -2,37 +2,36 @@ import persisting_theory
class ActivityRegistry(persisting_theory.Registry): class ActivityRegistry(persisting_theory.Registry):
look_into = 'activities' look_into = "activities"
def _register_for_model(self, model, attr, value): def _register_for_model(self, model, attr, value):
key = model._meta.label key = model._meta.label
d = self.setdefault(key, {'consumers': []}) d = self.setdefault(key, {"consumers": []})
d[attr] = value d[attr] = value
def register_serializer(self, serializer_class): def register_serializer(self, serializer_class):
model = serializer_class.Meta.model model = serializer_class.Meta.model
self._register_for_model(model, 'serializer', serializer_class) self._register_for_model(model, "serializer", serializer_class)
return serializer_class return serializer_class
def register_consumer(self, label): def register_consumer(self, label):
def decorator(func): def decorator(func):
consumers = self[label]['consumers'] consumers = self[label]["consumers"]
if func not in consumers: if func not in consumers:
consumers.append(func) consumers.append(func)
return func return func
return decorator return decorator