mirror of
https://github.com/Eugeny/tabby-web.git
synced 2026-08-18 07:16:03 +01:00
lint
This commit is contained in:
@@ -4,14 +4,17 @@ from . import app_version, auth, config, gateway, user
|
||||
|
||||
|
||||
router = routers.DefaultRouter(trailing_slash=False)
|
||||
router.register('api/1/configs', config.ConfigViewSet)
|
||||
router.register('api/1/versions', app_version.AppVersionViewSet, basename='app-versions')
|
||||
router.register("api/1/configs", config.ConfigViewSet)
|
||||
router.register(
|
||||
"api/1/versions", app_version.AppVersionViewSet, basename="app-versions"
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
path('api/1/auth/logout', auth.LogoutView.as_view()),
|
||||
path('api/1/user', user.UserViewSet.as_view({'get': 'retrieve', 'put': 'update'})),
|
||||
path('api/1/gateways/choose', gateway.ChooseGatewayViewSet.as_view({'post': 'retrieve'})),
|
||||
|
||||
|
||||
path('', include(router.urls)),
|
||||
path("api/1/auth/logout", auth.LogoutView.as_view()),
|
||||
path("api/1/user", user.UserViewSet.as_view({"get": "retrieve", "put": "update"})),
|
||||
path(
|
||||
"api/1/gateways/choose",
|
||||
gateway.ChooseGatewayViewSet.as_view({"post": "retrieve"}),
|
||||
),
|
||||
path("", include(router.urls)),
|
||||
]
|
||||
|
||||
@@ -25,27 +25,28 @@ class AppVersionSerializer(DataclassSerializer):
|
||||
|
||||
class AppVersionViewSet(ListModelMixin, GenericViewSet):
|
||||
serializer_class = AppVersionSerializer
|
||||
lookup_field = 'id'
|
||||
lookup_value_regex = r'[\w\d.-]+'
|
||||
queryset = ''
|
||||
lookup_field = "id"
|
||||
lookup_value_regex = r"[\w\d.-]+"
|
||||
queryset = ""
|
||||
|
||||
def _get_versions(self):
|
||||
fs = fsspec.filesystem(urlparse(settings.APP_DIST_STORAGE).scheme)
|
||||
return [
|
||||
self._get_version(x['name'])
|
||||
self._get_version(x["name"])
|
||||
for x in fs.listdir(settings.APP_DIST_STORAGE)
|
||||
if x['type'] == 'directory'
|
||||
if x["type"] == "directory"
|
||||
]
|
||||
|
||||
def _get_version(self, dir):
|
||||
fs = fsspec.filesystem(urlparse(settings.APP_DIST_STORAGE).scheme)
|
||||
plugins = [
|
||||
os.path.basename(x['name'])
|
||||
os.path.basename(x["name"])
|
||||
for x in fs.listdir(dir)
|
||||
if x['type'] == 'directory' and os.path.basename(x['name'])
|
||||
if x["type"] == "directory"
|
||||
and os.path.basename(x["name"])
|
||||
not in [
|
||||
'tabby-web-container',
|
||||
'tabby-web-demo',
|
||||
"tabby-web-container",
|
||||
"tabby-web-demo",
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ class ConfigSerializer(ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = Config
|
||||
read_only_fields = ('user', 'created_at', 'modified_at')
|
||||
fields = '__all__'
|
||||
read_only_fields = ("user", "created_at", "modified_at")
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class ConfigViewSet(ModelViewSet):
|
||||
|
||||
@@ -14,7 +14,7 @@ class GatewaySerializer(ModelSerializer):
|
||||
auth_token = fields.CharField()
|
||||
|
||||
class Meta:
|
||||
fields = '__all__'
|
||||
fields = "__all__"
|
||||
model = Gateway
|
||||
|
||||
def get_url(self, gw):
|
||||
@@ -23,8 +23,8 @@ class GatewaySerializer(ModelSerializer):
|
||||
|
||||
class NoGatewaysError(APIException):
|
||||
status_code = status.HTTP_503_SERVICE_UNAVAILABLE
|
||||
default_detail = 'No connection gateways available.'
|
||||
default_code = 'no_gateways'
|
||||
default_detail = "No connection gateways available."
|
||||
default_code = "no_gateways"
|
||||
|
||||
|
||||
class ChooseGatewayViewSet(RetrieveModelMixin, GenericViewSet):
|
||||
|
||||
@@ -19,30 +19,34 @@ class UserSerializer(ModelSerializer):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = (
|
||||
'id',
|
||||
'username',
|
||||
'active_config',
|
||||
'custom_connection_gateway',
|
||||
'custom_connection_gateway_token',
|
||||
'config_sync_token',
|
||||
'is_pro',
|
||||
'is_sponsor',
|
||||
'github_username',
|
||||
"id",
|
||||
"username",
|
||||
"active_config",
|
||||
"custom_connection_gateway",
|
||||
"custom_connection_gateway_token",
|
||||
"config_sync_token",
|
||||
"is_pro",
|
||||
"is_sponsor",
|
||||
"github_username",
|
||||
)
|
||||
read_only_fields = ('id', 'username')
|
||||
read_only_fields = ("id", "username")
|
||||
|
||||
def get_is_pro(self, obj):
|
||||
return obj.force_pro or not settings.GITHUB_ELIGIBLE_SPONSORSHIPS or check_is_sponsor_cached(obj)
|
||||
return (
|
||||
obj.force_pro
|
||||
or not settings.GITHUB_ELIGIBLE_SPONSORSHIPS
|
||||
or check_is_sponsor_cached(obj)
|
||||
)
|
||||
|
||||
def get_is_sponsor(self, obj):
|
||||
return check_is_sponsor_cached(obj)
|
||||
|
||||
def get_github_username(self, obj):
|
||||
social_auth = UserSocialAuth.objects.filter(user=obj, provider='github').first()
|
||||
social_auth = UserSocialAuth.objects.filter(user=obj, provider="github").first()
|
||||
if not social_auth:
|
||||
return None
|
||||
|
||||
return social_auth.extra_data.get('login')
|
||||
return social_auth.extra_data.get("login")
|
||||
|
||||
|
||||
class UserViewSet(RetrieveModelMixin, UpdateModelMixin, GenericViewSet):
|
||||
|
||||
Reference in New Issue
Block a user