From f365f2b342e50a94ddd2821dbd0da234b3456dc4 Mon Sep 17 00:00:00 2001 From: lian Date: Mon, 12 Jun 2023 09:53:31 +0800 Subject: [PATCH] django 4.2 --- requirements.txt | 2 +- seahub/admin_log/signals.py | 2 +- seahub/api2/authentication.py | 4 +- seahub/api2/endpoints/admin/account.py | 2 +- .../endpoints/admin/address_book/groups.py | 2 +- .../api2/endpoints/admin/default_library.py | 2 +- seahub/api2/endpoints/admin/groups.py | 2 +- .../api2/endpoints/admin/institution_users.py | 2 +- seahub/api2/endpoints/admin/libraries.py | 2 +- .../api2/endpoints/admin/library_history.py | 2 +- seahub/api2/endpoints/admin/org_users.py | 2 +- seahub/api2/endpoints/admin/revision_tag.py | 2 +- seahub/api2/endpoints/admin/share_links.py | 2 +- seahub/api2/endpoints/admin/shares.py | 2 +- seahub/api2/endpoints/admin/statistics.py | 2 +- seahub/api2/endpoints/admin/users.py | 2 +- seahub/api2/endpoints/admin/users_batch.py | 2 +- .../endpoints/admin/virus_scan_records.py | 2 +- seahub/api2/endpoints/copy_move_task.py | 2 +- seahub/api2/endpoints/dir.py | 4 +- seahub/api2/endpoints/dir_shared_items.py | 2 +- seahub/api2/endpoints/draft_reviewer.py | 2 +- seahub/api2/endpoints/file.py | 2 +- seahub/api2/endpoints/file_participants.py | 2 +- seahub/api2/endpoints/file_tag.py | 2 +- seahub/api2/endpoints/group_members.py | 2 +- .../api2/endpoints/group_owned_libraries.py | 2 +- seahub/api2/endpoints/groups.py | 2 +- seahub/api2/endpoints/invitation.py | 2 +- seahub/api2/endpoints/invitations.py | 2 +- seahub/api2/endpoints/move_folder_merge.py | 2 +- seahub/api2/endpoints/multi_share_links.py | 2 +- .../endpoints/query_copy_move_progress.py | 2 +- seahub/api2/endpoints/repo_api_tokens.py | 2 +- seahub/api2/endpoints/repo_commit_revert.py | 2 +- seahub/api2/endpoints/repo_draft_info.py | 2 +- .../api2/endpoints/repo_send_new_password.py | 2 +- seahub/api2/endpoints/repo_set_password.py | 2 +- .../api2/endpoints/repo_share_invitations.py | 2 +- seahub/api2/endpoints/repo_share_links.py | 2 +- seahub/api2/endpoints/repos_batch.py | 2 +- seahub/api2/endpoints/revision_tag.py | 2 +- .../api2/endpoints/send_share_link_email.py | 2 +- .../api2/endpoints/send_upload_link_email.py | 2 +- seahub/api2/endpoints/share_link_zip_task.py | 2 +- seahub/api2/endpoints/share_links.py | 6 +- seahub/api2/endpoints/starred_items.py | 4 +- seahub/api2/endpoints/upload_links.py | 2 +- seahub/api2/endpoints/user.py | 2 +- seahub/api2/endpoints/user_avatar.py | 2 +- seahub/api2/endpoints/via_repo_token.py | 2 +- seahub/api2/endpoints/webdav_secret.py | 2 +- seahub/api2/endpoints/wiki_pages.py | 2 +- seahub/api2/endpoints/wikis.py | 2 +- seahub/api2/endpoints/zip_task.py | 2 +- seahub/api2/serializers.py | 4 +- seahub/api2/throttling.py | 2 +- seahub/api2/urls.py | 164 ++-- seahub/api2/utils.py | 2 +- seahub/api2/views.py | 6 +- seahub/auth/decorators.py | 8 +- seahub/auth/forms.py | 2 +- seahub/auth/models.py | 2 +- seahub/auth/signals.py | 4 +- seahub/auth/utils.py | 2 +- seahub/auth/views.py | 19 +- seahub/avatar/forms.py | 2 +- seahub/avatar/models.py | 2 +- seahub/avatar/signals.py | 2 +- seahub/avatar/urls.py | 6 +- seahub/avatar/util.py | 4 +- seahub/avatar/views.py | 4 +- seahub/base/__init__.py | 1 - seahub/base/accounts.py | 6 +- seahub/base/context_processors.py | 3 +- seahub/base/decorators.py | 6 +- .../management/commands/check_user_quota.py | 2 +- .../management/commands/createsuperuser.py | 2 +- .../commands/export_file_access_log.py | 2 +- .../commands/export_user_storage_report.py | 2 +- .../commands/export_user_traffic_report.py | 2 +- .../base/management/commands/export_users.py | 2 +- seahub/base/middleware.py | 2 +- seahub/base/registration_urls.py | 12 +- seahub/base/templatetags/rest_framework.py | 4 +- seahub/base/templatetags/seahub_tags.py | 26 +- seahub/base/utils.py | 12 +- seahub/cad/urls.py | 4 +- seahub/contacts/models.py | 2 +- seahub/contacts/signals.py | 4 +- seahub/contacts/urls.py | 12 +- seahub/contacts/views.py | 2 +- seahub/dingtalk/views.py | 2 +- seahub/django_cas_ng/decorators.py | 4 +- seahub/django_cas_ng/signals.py | 6 +- seahub/django_cas_ng/utils.py | 4 +- seahub/drafts/signals.py | 6 +- seahub/drafts/urls.py | 6 +- seahub/drafts/views.py | 2 +- seahub/forms.py | 2 +- seahub/group/error_msg.py | 2 +- seahub/group/forms.py | 2 +- seahub/group/signals.py | 6 +- seahub/group/urls.py | 4 +- seahub/group/views.py | 8 +- seahub/help/urls.py | 58 +- seahub/institutions/urls.py | 16 +- seahub/institutions/views.py | 4 +- seahub/invitations/models.py | 2 +- seahub/invitations/signals.py | 3 +- seahub/invitations/urls.py | 4 +- seahub/invitations/views.py | 4 +- .../commands/notify_admins_on_virus.py | 2 +- .../commands/send_dingtalk_notifications.py | 4 +- .../management/commands/send_file_updates.py | 2 +- .../management/commands/send_notices.py | 2 +- .../send_notices_to_social_account.py | 2 +- seahub/notifications/models.py | 2 +- seahub/notifications/urls.py | 4 +- seahub/notifications/views.py | 2 +- seahub/oauth/urls.py | 6 +- seahub/oauth/views.py | 2 +- seahub/onlyoffice/utils.py | 2 +- seahub/options/urls.py | 6 +- seahub/options/views.py | 6 +- seahub/organizations/api/admin/info.py | 2 +- seahub/organizations/api/admin/logo.py | 2 +- seahub/organizations/api/admin/statistics.py | 2 +- seahub/organizations/api/admin/user_repos.py | 2 +- seahub/organizations/api/admin/users.py | 2 +- seahub/organizations/api_urls.py | 82 +- seahub/organizations/forms.py | 2 +- seahub/organizations/middleware.py | 2 +- seahub/organizations/signals.py | 2 +- seahub/organizations/urls.py | 66 +- seahub/organizations/views.py | 2 +- seahub/profile/forms.py | 2 +- seahub/profile/urls.py | 14 +- seahub/profile/views.py | 8 +- seahub/repo_api_tokens/utils.py | 4 +- seahub/seadoc/apis.py | 10 +- seahub/seadoc/urls.py | 14 +- seahub/search/views.py | 2 +- seahub/settings.py | 12 +- seahub/share/decorators.py | 2 +- seahub/share/forms.py | 2 +- seahub/share/models.py | 2 +- seahub/share/signals.py | 6 +- seahub/share/urls.py | 14 +- seahub/share/views.py | 4 +- seahub/signals.py | 18 +- seahub/sysadmin_extra/views.py | 12 +- seahub/test_settings.py | 3 +- seahub/thirdparty_editor/urls.py | 6 +- seahub/thumbnail/urls.py | 10 +- seahub/thumbnail/views.py | 8 +- seahub/two_factor/forms.py | 2 +- seahub/two_factor/gateways/twilio/gateway.py | 4 +- seahub/two_factor/gateways/twilio/views.py | 2 +- seahub/two_factor/models/base.py | 2 +- seahub/two_factor/models/phone.py | 2 +- seahub/two_factor/urls.py | 28 +- seahub/two_factor/views/core.py | 2 +- seahub/two_factor/views/login.py | 6 +- seahub/two_factor/views/utils.py | 2 +- seahub/urls.py | 920 +++++++++--------- seahub/utils/__init__.py | 20 +- seahub/utils/error_msg.py | 2 +- seahub/utils/ip.py | 2 +- seahub/utils/rooturl.py | 4 +- seahub/utils/slugify/__init__.py | 4 +- seahub/utils/timeutils.py | 15 +- seahub/views/__init__.py | 22 +- seahub/views/ajax.py | 8 +- seahub/views/file.py | 26 +- seahub/views/repo.py | 6 +- seahub/views/sso.py | 9 +- seahub/views/sysadmin.py | 18 +- seahub/weixin/urls.py | 6 +- seahub/weixin/views.py | 2 +- seahub/wiki/models.py | 2 +- seahub/wiki/urls.py | 8 +- seahub/wiki/utils.py | 2 +- seahub/wiki/views.py | 2 +- seahub/wopi/urls.py | 6 +- seahub/wopi/views.py | 8 +- seahub/work_weixin/urls.py | 12 +- seahub/work_weixin/views.py | 4 +- .../endpoints/admin/test_sys_notifications.py | 4 +- tests/seahub/auth/views/test_login.py | 16 +- .../commands/test_notify_admins_on_virus.py | 4 +- .../thirdpart/shibboleth/test_middleware.py | 10 +- tests/seahub/views/init/test_fpath_to_link.py | 4 +- tests/seahub/views/test_sso.py | 4 +- thirdpart/constance/__init__.py | 1 - thirdpart/constance/admin.py | 10 +- thirdpart/constance/apps.py | 12 +- .../constance/backends/database/__init__.py | 2 +- .../constance/backends/database/models.py | 2 +- thirdpart/constance/checks.py | 2 +- .../management/commands/constance.py | 2 +- thirdpart/constance/signals.py | 6 +- thirdpart/registration/admin.py | 12 +- thirdpart/registration/auth_urls.py | 22 +- .../registration/backends/default/urls.py | 14 +- thirdpart/registration/forms.py | 2 +- thirdpart/registration/models.py | 8 +- thirdpart/registration/signals.py | 6 +- thirdpart/shibboleth/middleware.py | 3 - thirdpart/shibboleth/urls.py | 8 +- thirdpart/termsandconditions/admin.py | 4 +- thirdpart/termsandconditions/urls.py | 10 +- 212 files changed, 1152 insertions(+), 1143 deletions(-) diff --git a/requirements.txt b/requirements.txt index b58ff91348..774933cb2d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Django==3.2.* +Django==4.2.* django-statici18n==2.3.* django_webpack_loader==1.7.* django_picklefield==3.1 diff --git a/seahub/admin_log/signals.py b/seahub/admin_log/signals.py index 2751f0249a..29bd8981b0 100644 --- a/seahub/admin_log/signals.py +++ b/seahub/admin_log/signals.py @@ -1,4 +1,4 @@ # Copyright (c) 2012-2017 Seafile Ltd. import django.dispatch -admin_operation = django.dispatch.Signal(providing_args=["admin_name", "operation", "detail"]) +admin_operation = django.dispatch.Signal() diff --git a/seahub/api2/authentication.py b/seahub/api2/authentication.py index 6f11ec8d29..7f07d23ea3 100644 --- a/seahub/api2/authentication.py +++ b/seahub/api2/authentication.py @@ -51,7 +51,7 @@ class TokenAuthentication(BaseAuthentication): """ def authenticate(self, request): - auth = request.META.get('HTTP_AUTHORIZATION', '').split() + auth = request.headers.get('authorization', '').split() if not auth or auth[0].lower() != 'token': return None @@ -164,7 +164,7 @@ class RepoAPITokenAuthentication(BaseAuthentication): :param request: request :return: AnonymousUser, repo_api_token """ - auth = request.META.get('HTTP_AUTHORIZATION', '').split() + auth = request.headers.get('authorization', '').split() if not auth or auth[0].lower() != 'token': return None diff --git a/seahub/api2/endpoints/admin/account.py b/seahub/api2/endpoints/admin/account.py index 9fffdedbd6..686abca7a3 100644 --- a/seahub/api2/endpoints/admin/account.py +++ b/seahub/api2/endpoints/admin/account.py @@ -3,7 +3,7 @@ import logging from dateutil.relativedelta import relativedelta from django.utils import timezone -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from rest_framework import status from rest_framework.authentication import SessionAuthentication from rest_framework.permissions import IsAdminUser diff --git a/seahub/api2/endpoints/admin/address_book/groups.py b/seahub/api2/endpoints/admin/address_book/groups.py index f4f5e368ad..765f997223 100644 --- a/seahub/api2/endpoints/admin/address_book/groups.py +++ b/seahub/api2/endpoints/admin/address_book/groups.py @@ -6,7 +6,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api, ccnet_api from pysearpc import SearpcError diff --git a/seahub/api2/endpoints/admin/default_library.py b/seahub/api2/endpoints/admin/default_library.py index ecce6ce8b6..fdd6291e1f 100644 --- a/seahub/api2/endpoints/admin/default_library.py +++ b/seahub/api2/endpoints/admin/default_library.py @@ -7,7 +7,7 @@ from rest_framework.permissions import IsAdminUser from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api diff --git a/seahub/api2/endpoints/admin/groups.py b/seahub/api2/endpoints/admin/groups.py index 7654357541..14f7959919 100644 --- a/seahub/api2/endpoints/admin/groups.py +++ b/seahub/api2/endpoints/admin/groups.py @@ -6,7 +6,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api, ccnet_api from pysearpc import SearpcError diff --git a/seahub/api2/endpoints/admin/institution_users.py b/seahub/api2/endpoints/admin/institution_users.py index 3d4726bf73..87dc186357 100644 --- a/seahub/api2/endpoints/admin/institution_users.py +++ b/seahub/api2/endpoints/admin/institution_users.py @@ -5,7 +5,7 @@ from rest_framework.authentication import SessionAuthentication from rest_framework.permissions import IsAdminUser from rest_framework.response import Response from rest_framework.views import APIView -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api, ccnet_api diff --git a/seahub/api2/endpoints/admin/libraries.py b/seahub/api2/endpoints/admin/libraries.py index a5a8230f3e..1e226b8b30 100644 --- a/seahub/api2/endpoints/admin/libraries.py +++ b/seahub/api2/endpoints/admin/libraries.py @@ -7,7 +7,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status from django.template.defaultfilters import filesizeformat -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import ccnet_api, seafile_api from seahub.api2.authentication import TokenAuthentication diff --git a/seahub/api2/endpoints/admin/library_history.py b/seahub/api2/endpoints/admin/library_history.py index c290ac4506..716506fa29 100644 --- a/seahub/api2/endpoints/admin/library_history.py +++ b/seahub/api2/endpoints/admin/library_history.py @@ -5,7 +5,7 @@ from rest_framework.permissions import IsAdminUser from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from pysearpc import SearpcError from seaserv import seafile_api diff --git a/seahub/api2/endpoints/admin/org_users.py b/seahub/api2/endpoints/admin/org_users.py index 7686b2a30e..b503dc635c 100644 --- a/seahub/api2/endpoints/admin/org_users.py +++ b/seahub/api2/endpoints/admin/org_users.py @@ -2,7 +2,7 @@ import logging from types import FunctionType -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from rest_framework.authentication import SessionAuthentication from rest_framework.permissions import IsAdminUser from rest_framework.response import Response diff --git a/seahub/api2/endpoints/admin/revision_tag.py b/seahub/api2/endpoints/admin/revision_tag.py index 92cb100be0..28cf5a9202 100644 --- a/seahub/api2/endpoints/admin/revision_tag.py +++ b/seahub/api2/endpoints/admin/revision_tag.py @@ -7,7 +7,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.api2.throttling import UserRateThrottle from seahub.api2.authentication import TokenAuthentication diff --git a/seahub/api2/endpoints/admin/share_links.py b/seahub/api2/endpoints/admin/share_links.py index bace9dff61..78478f5f0c 100644 --- a/seahub/api2/endpoints/admin/share_links.py +++ b/seahub/api2/endpoints/admin/share_links.py @@ -13,7 +13,7 @@ from rest_framework import status from django.contrib.auth.hashers import check_password -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api import seaserv diff --git a/seahub/api2/endpoints/admin/shares.py b/seahub/api2/endpoints/admin/shares.py index 6056d4bc12..fa4f225878 100644 --- a/seahub/api2/endpoints/admin/shares.py +++ b/seahub/api2/endpoints/admin/shares.py @@ -6,7 +6,7 @@ from rest_framework.permissions import IsAdminUser from rest_framework.response import Response from rest_framework.views import APIView -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api, ccnet_api diff --git a/seahub/api2/endpoints/admin/statistics.py b/seahub/api2/endpoints/admin/statistics.py index 448cf88084..81a7af3140 100644 --- a/seahub/api2/endpoints/admin/statistics.py +++ b/seahub/api2/endpoints/admin/statistics.py @@ -9,7 +9,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status from django.utils import timezone -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.http import HttpResponse from seaserv import ccnet_api diff --git a/seahub/api2/endpoints/admin/users.py b/seahub/api2/endpoints/admin/users.py index a2a4a29038..dc38c0f872 100644 --- a/seahub/api2/endpoints/admin/users.py +++ b/seahub/api2/endpoints/admin/users.py @@ -12,7 +12,7 @@ from rest_framework.views import APIView from django.db.models import Q from django.core.cache import cache -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.utils.timezone import make_naive, is_aware from seaserv import seafile_api, ccnet_api diff --git a/seahub/api2/endpoints/admin/users_batch.py b/seahub/api2/endpoints/admin/users_batch.py index c8e0057b55..6b56897f72 100644 --- a/seahub/api2/endpoints/admin/users_batch.py +++ b/seahub/api2/endpoints/admin/users_batch.py @@ -11,7 +11,7 @@ from rest_framework.permissions import IsAdminUser from rest_framework.response import Response from rest_framework.views import APIView -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api diff --git a/seahub/api2/endpoints/admin/virus_scan_records.py b/seahub/api2/endpoints/admin/virus_scan_records.py index 5d37d0637a..052af7d455 100644 --- a/seahub/api2/endpoints/admin/virus_scan_records.py +++ b/seahub/api2/endpoints/admin/virus_scan_records.py @@ -8,7 +8,7 @@ from rest_framework.permissions import IsAdminUser from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api diff --git a/seahub/api2/endpoints/copy_move_task.py b/seahub/api2/endpoints/copy_move_task.py index c11870dd35..9e682096b3 100644 --- a/seahub/api2/endpoints/copy_move_task.py +++ b/seahub/api2/endpoints/copy_move_task.py @@ -8,7 +8,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.utils.html import escape from seahub.api2.throttling import UserRateThrottle diff --git a/seahub/api2/endpoints/dir.py b/seahub/api2/endpoints/dir.py index 5d69be7811..31e394239f 100644 --- a/seahub/api2/endpoints/dir.py +++ b/seahub/api2/endpoints/dir.py @@ -10,7 +10,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.http import urlquote +from urllib.parse import quote from seahub.api2.throttling import UserRateThrottle from seahub.api2.authentication import TokenAuthentication @@ -164,7 +164,7 @@ def get_dir_file_info_list(username, request_type, repo_obj, parent_dir, str(thumbnail_size), file_obj_id) if os.path.exists(thumbnail_file_path): src = get_thumbnail_src(repo_id, thumbnail_size, file_path) - file_info['encoded_thumbnail_src'] = urlquote(src) + file_info['encoded_thumbnail_src'] = quote(src) file_info_list.append(file_info) diff --git a/seahub/api2/endpoints/dir_shared_items.py b/seahub/api2/endpoints/dir_shared_items.py index dba1bcfa64..c33e49404c 100644 --- a/seahub/api2/endpoints/dir_shared_items.py +++ b/seahub/api2/endpoints/dir_shared_items.py @@ -9,7 +9,7 @@ from rest_framework.authentication import SessionAuthentication from rest_framework.permissions import IsAuthenticated from rest_framework.views import APIView -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ import seaserv from seaserv import seafile_api, ccnet_api diff --git a/seahub/api2/endpoints/draft_reviewer.py b/seahub/api2/endpoints/draft_reviewer.py index b1edba8674..44ca50e005 100644 --- a/seahub/api2/endpoints/draft_reviewer.py +++ b/seahub/api2/endpoints/draft_reviewer.py @@ -7,7 +7,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api from seahub.api2.authentication import TokenAuthentication diff --git a/seahub/api2/endpoints/file.py b/seahub/api2/endpoints/file.py index 2e3c0e8bfd..03effbfe5b 100644 --- a/seahub/api2/endpoints/file.py +++ b/seahub/api2/endpoints/file.py @@ -12,7 +12,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.api2.throttling import UserRateThrottle from seahub.api2.authentication import TokenAuthentication diff --git a/seahub/api2/endpoints/file_participants.py b/seahub/api2/endpoints/file_participants.py index d59c9cb5e0..ee35070763 100644 --- a/seahub/api2/endpoints/file_participants.py +++ b/seahub/api2/endpoints/file_participants.py @@ -8,7 +8,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView from seaserv import seafile_api -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.api2.authentication import TokenAuthentication from seahub.api2.throttling import UserRateThrottle diff --git a/seahub/api2/endpoints/file_tag.py b/seahub/api2/endpoints/file_tag.py index b9d197fd19..4d0ae311bb 100644 --- a/seahub/api2/endpoints/file_tag.py +++ b/seahub/api2/endpoints/file_tag.py @@ -7,7 +7,7 @@ from rest_framework.authentication import SessionAuthentication from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from seahub.api2.authentication import TokenAuthentication from seahub.api2.throttling import UserRateThrottle diff --git a/seahub/api2/endpoints/group_members.py b/seahub/api2/endpoints/group_members.py index 41a575511e..5c1976f9f6 100644 --- a/seahub/api2/endpoints/group_members.py +++ b/seahub/api2/endpoints/group_members.py @@ -4,7 +4,7 @@ from io import BytesIO from openpyxl import load_workbook from django.http import HttpResponse -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from rest_framework.authentication import SessionAuthentication from rest_framework.permissions import IsAuthenticated diff --git a/seahub/api2/endpoints/group_owned_libraries.py b/seahub/api2/endpoints/group_owned_libraries.py index 5cc3bcf767..dd14efb732 100644 --- a/seahub/api2/endpoints/group_owned_libraries.py +++ b/seahub/api2/endpoints/group_owned_libraries.py @@ -7,7 +7,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api, ccnet_api diff --git a/seahub/api2/endpoints/groups.py b/seahub/api2/endpoints/groups.py index 541e074190..9844f7c923 100644 --- a/seahub/api2/endpoints/groups.py +++ b/seahub/api2/endpoints/groups.py @@ -1,7 +1,7 @@ # Copyright (c) 2012-2016 Seafile Ltd. import logging -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.template.defaultfilters import filesizeformat from rest_framework.authentication import SessionAuthentication diff --git a/seahub/api2/endpoints/invitation.py b/seahub/api2/endpoints/invitation.py index 21754cdb20..708bb45b9b 100644 --- a/seahub/api2/endpoints/invitation.py +++ b/seahub/api2/endpoints/invitation.py @@ -7,7 +7,7 @@ from rest_framework.authentication import SessionAuthentication from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.api2.authentication import TokenAuthentication from seahub.api2.permissions import CanInviteGuest diff --git a/seahub/api2/endpoints/invitations.py b/seahub/api2/endpoints/invitations.py index 6ef63ebad8..9add754b10 100644 --- a/seahub/api2/endpoints/invitations.py +++ b/seahub/api2/endpoints/invitations.py @@ -1,6 +1,6 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from rest_framework import status from rest_framework.authentication import SessionAuthentication from rest_framework.permissions import IsAuthenticated diff --git a/seahub/api2/endpoints/move_folder_merge.py b/seahub/api2/endpoints/move_folder_merge.py index 62561525d0..311a7fd005 100644 --- a/seahub/api2/endpoints/move_folder_merge.py +++ b/seahub/api2/endpoints/move_folder_merge.py @@ -10,7 +10,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.api2.throttling import UserRateThrottle from seahub.api2.authentication import TokenAuthentication diff --git a/seahub/api2/endpoints/multi_share_links.py b/seahub/api2/endpoints/multi_share_links.py index 59bf09e514..2d140bbba2 100644 --- a/seahub/api2/endpoints/multi_share_links.py +++ b/seahub/api2/endpoints/multi_share_links.py @@ -13,7 +13,7 @@ from rest_framework.views import APIView from rest_framework import status from django.utils import timezone from django.utils.timezone import get_current_timezone -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api diff --git a/seahub/api2/endpoints/query_copy_move_progress.py b/seahub/api2/endpoints/query_copy_move_progress.py index 9ea77d66d4..650066a7f8 100644 --- a/seahub/api2/endpoints/query_copy_move_progress.py +++ b/seahub/api2/endpoints/query_copy_move_progress.py @@ -6,7 +6,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.api2.throttling import UserRateThrottle from seahub.api2.authentication import TokenAuthentication diff --git a/seahub/api2/endpoints/repo_api_tokens.py b/seahub/api2/endpoints/repo_api_tokens.py index d0de77b818..d58e5245b3 100644 --- a/seahub/api2/endpoints/repo_api_tokens.py +++ b/seahub/api2/endpoints/repo_api_tokens.py @@ -6,7 +6,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.api2.authentication import TokenAuthentication from seahub.api2.throttling import UserRateThrottle diff --git a/seahub/api2/endpoints/repo_commit_revert.py b/seahub/api2/endpoints/repo_commit_revert.py index e518439568..a73aa281ab 100644 --- a/seahub/api2/endpoints/repo_commit_revert.py +++ b/seahub/api2/endpoints/repo_commit_revert.py @@ -3,7 +3,7 @@ import logging -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from rest_framework.authentication import SessionAuthentication from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response diff --git a/seahub/api2/endpoints/repo_draft_info.py b/seahub/api2/endpoints/repo_draft_info.py index 5a8223481b..2c4bf44f5c 100644 --- a/seahub/api2/endpoints/repo_draft_info.py +++ b/seahub/api2/endpoints/repo_draft_info.py @@ -8,7 +8,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from seaserv import seafile_api -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.api2.authentication import TokenAuthentication from seahub.api2.throttling import UserRateThrottle diff --git a/seahub/api2/endpoints/repo_send_new_password.py b/seahub/api2/endpoints/repo_send_new_password.py index 2388e70694..9724dac11a 100644 --- a/seahub/api2/endpoints/repo_send_new_password.py +++ b/seahub/api2/endpoints/repo_send_new_password.py @@ -6,7 +6,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.utils.crypto import get_random_string from seaserv import seafile_api, ccnet_api diff --git a/seahub/api2/endpoints/repo_set_password.py b/seahub/api2/endpoints/repo_set_password.py index 9e23d6cf20..3985e21390 100644 --- a/seahub/api2/endpoints/repo_set_password.py +++ b/seahub/api2/endpoints/repo_set_password.py @@ -6,7 +6,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api, ccnet_api from pysearpc import SearpcError diff --git a/seahub/api2/endpoints/repo_share_invitations.py b/seahub/api2/endpoints/repo_share_invitations.py index c1310f23f2..dfeaf59488 100644 --- a/seahub/api2/endpoints/repo_share_invitations.py +++ b/seahub/api2/endpoints/repo_share_invitations.py @@ -4,7 +4,7 @@ import logging from datetime import timedelta from django.utils import timezone -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from rest_framework import status from rest_framework.authentication import SessionAuthentication from rest_framework.permissions import IsAuthenticated diff --git a/seahub/api2/endpoints/repo_share_links.py b/seahub/api2/endpoints/repo_share_links.py index 4af71e5442..6fd5e590b5 100644 --- a/seahub/api2/endpoints/repo_share_links.py +++ b/seahub/api2/endpoints/repo_share_links.py @@ -8,7 +8,7 @@ from rest_framework.response import Response from rest_framework.permissions import IsAuthenticated from rest_framework.authentication import SessionAuthentication -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api diff --git a/seahub/api2/endpoints/repos_batch.py b/seahub/api2/endpoints/repos_batch.py index e2e7602756..4d9f37a98c 100644 --- a/seahub/api2/endpoints/repos_batch.py +++ b/seahub/api2/endpoints/repos_batch.py @@ -9,7 +9,7 @@ from rest_framework.authentication import SessionAuthentication from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ import seaserv from seaserv import seafile_api, ccnet_api diff --git a/seahub/api2/endpoints/revision_tag.py b/seahub/api2/endpoints/revision_tag.py index 74a46a58a5..36e9f4986c 100644 --- a/seahub/api2/endpoints/revision_tag.py +++ b/seahub/api2/endpoints/revision_tag.py @@ -7,7 +7,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.api2.throttling import UserRateThrottle from seahub.api2.authentication import TokenAuthentication diff --git a/seahub/api2/endpoints/send_share_link_email.py b/seahub/api2/endpoints/send_share_link_email.py index b9412b15ec..8cfbefcfa4 100644 --- a/seahub/api2/endpoints/send_share_link_email.py +++ b/seahub/api2/endpoints/send_share_link_email.py @@ -7,7 +7,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.api2.authentication import TokenAuthentication from seahub.api2.throttling import UserRateThrottle diff --git a/seahub/api2/endpoints/send_upload_link_email.py b/seahub/api2/endpoints/send_upload_link_email.py index 430e7c0667..d0c63a68c4 100644 --- a/seahub/api2/endpoints/send_upload_link_email.py +++ b/seahub/api2/endpoints/send_upload_link_email.py @@ -6,7 +6,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.api2.authentication import TokenAuthentication from seahub.api2.throttling import UserRateThrottle diff --git a/seahub/api2/endpoints/share_link_zip_task.py b/seahub/api2/endpoints/share_link_zip_task.py index 19cff01011..ed3e71bb3a 100644 --- a/seahub/api2/endpoints/share_link_zip_task.py +++ b/seahub/api2/endpoints/share_link_zip_task.py @@ -10,7 +10,7 @@ from rest_framework.views import APIView from rest_framework import status from django.conf import settings -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.api2.throttling import UserRateThrottle from seahub.api2.utils import api_error diff --git a/seahub/api2/endpoints/share_links.py b/seahub/api2/endpoints/share_links.py index 2bece88538..92aaeea9c4 100644 --- a/seahub/api2/endpoints/share_links.py +++ b/seahub/api2/endpoints/share_links.py @@ -18,8 +18,8 @@ from rest_framework import status from django.utils import timezone from django.utils.timezone import get_current_timezone -from django.utils.translation import ugettext as _ -from django.utils.http import urlquote +from django.utils.translation import gettext as _ +from urllib.parse import quote from seaserv import seafile_api from pysearpc import SearpcError @@ -858,7 +858,7 @@ class ShareLinkDirents(APIView): if os.path.exists(os.path.join(THUMBNAIL_ROOT, str(thumbnail_size), dirent.obj_id)): req_image_path = posixpath.join(request_path, dirent.obj_name) src = get_share_link_thumbnail_src(token, thumbnail_size, req_image_path) - dirent_info['encoded_thumbnail_src'] = urlquote(src) + dirent_info['encoded_thumbnail_src'] = quote(src) # get tag info file_tags = files_tags_in_dir.get(dirent.obj_name, []) diff --git a/seahub/api2/endpoints/starred_items.py b/seahub/api2/endpoints/starred_items.py index 495e74ed74..ba60224a22 100644 --- a/seahub/api2/endpoints/starred_items.py +++ b/seahub/api2/endpoints/starred_items.py @@ -2,7 +2,7 @@ import os import logging -from django.utils.http import urlquote +from urllib.parse import quote from rest_framework.authentication import SessionAuthentication from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response @@ -67,7 +67,7 @@ class StarredItems(APIView): str(thumbnail_size), dirent.obj_id) if os.path.exists(thumbnail_file_path): src = get_thumbnail_src(repo_id, thumbnail_size, path) - item_info['encoded_thumbnail_src'] = urlquote(src) + item_info['encoded_thumbnail_src'] = quote(src) return item_info diff --git a/seahub/api2/endpoints/upload_links.py b/seahub/api2/endpoints/upload_links.py index 5da21cd922..be8f0bb3d9 100644 --- a/seahub/api2/endpoints/upload_links.py +++ b/seahub/api2/endpoints/upload_links.py @@ -14,7 +14,7 @@ from rest_framework import status from django.utils import timezone from django.utils.timezone import get_current_timezone -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api from pysearpc import SearpcError diff --git a/seahub/api2/endpoints/user.py b/seahub/api2/endpoints/user.py index cb4ccb521c..dce13b8541 100644 --- a/seahub/api2/endpoints/user.py +++ b/seahub/api2/endpoints/user.py @@ -6,7 +6,7 @@ from rest_framework.authentication import SessionAuthentication from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.utils import is_valid_email from seahub.api2.authentication import TokenAuthentication diff --git a/seahub/api2/endpoints/user_avatar.py b/seahub/api2/endpoints/user_avatar.py index 86bd89ae0f..799d5e6e43 100644 --- a/seahub/api2/endpoints/user_avatar.py +++ b/seahub/api2/endpoints/user_avatar.py @@ -8,7 +8,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.template.defaultfilters import filesizeformat from seahub.api2.authentication import TokenAuthentication diff --git a/seahub/api2/endpoints/via_repo_token.py b/seahub/api2/endpoints/via_repo_token.py index a18d486ffd..55e5089dfd 100644 --- a/seahub/api2/endpoints/via_repo_token.py +++ b/seahub/api2/endpoints/via_repo_token.py @@ -4,7 +4,7 @@ import json import logging import posixpath from django.http import HttpResponse -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from rest_framework import status from rest_framework.authentication import SessionAuthentication from rest_framework.permissions import IsAuthenticated diff --git a/seahub/api2/endpoints/webdav_secret.py b/seahub/api2/endpoints/webdav_secret.py index 51cc36fc09..dacfeff580 100644 --- a/seahub/api2/endpoints/webdav_secret.py +++ b/seahub/api2/endpoints/webdav_secret.py @@ -7,7 +7,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.api2.authentication import TokenAuthentication from seahub.api2.throttling import UserRateThrottle diff --git a/seahub/api2/endpoints/wiki_pages.py b/seahub/api2/endpoints/wiki_pages.py index 0ff765866c..565e3978f7 100644 --- a/seahub/api2/endpoints/wiki_pages.py +++ b/seahub/api2/endpoints/wiki_pages.py @@ -13,7 +13,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from seaserv import seafile_api, get_file_id_by_path from pysearpc import SearpcError -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.views import check_folder_permission from seahub.views.file import send_file_access_msg diff --git a/seahub/api2/endpoints/wikis.py b/seahub/api2/endpoints/wikis.py index 7ebd7a0f35..7b39cc45ce 100644 --- a/seahub/api2/endpoints/wikis.py +++ b/seahub/api2/endpoints/wikis.py @@ -12,7 +12,7 @@ from pysearpc import SearpcError from django.db import IntegrityError from django.db.models import Count from django.http import HttpResponse -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.api2.authentication import TokenAuthentication from seahub.api2.throttling import UserRateThrottle diff --git a/seahub/api2/endpoints/zip_task.py b/seahub/api2/endpoints/zip_task.py index f301e0fe23..3a1a74e237 100644 --- a/seahub/api2/endpoints/zip_task.py +++ b/seahub/api2/endpoints/zip_task.py @@ -10,7 +10,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status from django.conf import settings -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.api2.throttling import UserRateThrottle from seahub.api2.authentication import TokenAuthentication diff --git a/seahub/api2/serializers.py b/seahub/api2/serializers.py index 0c40adbbfa..098f0bb296 100644 --- a/seahub/api2/serializers.py +++ b/seahub/api2/serializers.py @@ -118,11 +118,11 @@ class AuthTokenSerializer(serializers.Serializer): if not has_two_factor_auth() or not two_factor_auth_enabled(user): return - if is_device_remembered(request.META.get('HTTP_X_SEAFILE_S2FA', ''), + if is_device_remembered(request.headers.get('x-seafile-s2fa', ''), user): return - token = request.META.get('HTTP_X_SEAFILE_OTP', '') + token = request.headers.get('x-seafile-otp', '') if not token: # Generate challenge(send sms/call/...) if token is not provided. default_device(user).generate_challenge() diff --git a/seahub/api2/throttling.py b/seahub/api2/throttling.py index 4c8c9d5ed5..a74b56a8a9 100644 --- a/seahub/api2/throttling.py +++ b/seahub/api2/throttling.py @@ -28,7 +28,7 @@ class BaseThrottle(object): if present and number of proxies is > 0. If not use all of HTTP_X_FORWARDED_FOR if it is available, if not use REMOTE_ADDR. """ - xff = request.META.get('HTTP_X_FORWARDED_FOR') + xff = request.headers.get('x-forwarded-for') remote_addr = request.META.get('REMOTE_ADDR') num_proxies = api_settings.NUM_PROXIES diff --git a/seahub/api2/urls.py b/seahub/api2/urls.py index 4cf63a4a0e..a5c9c2d91e 100644 --- a/seahub/api2/urls.py +++ b/seahub/api2/urls.py @@ -1,5 +1,5 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url, include +from django.urls import include, path, re_path from .views import * from .views_misc import ServerInfoView @@ -17,102 +17,102 @@ from .endpoints.send_share_link_email import SendShareLinkView from .endpoints.send_upload_link_email import SendUploadLinkView urlpatterns = [ - url(r'^ping/$', Ping.as_view()), - url(r'^auth/ping/$', AuthPing.as_view()), - url(r'^auth-token/', ObtainAuthToken.as_view()), - url(r'^server-info/$', ServerInfoView.as_view()), - url(r'^logout-device/$', LogoutDeviceView.as_view()), - url(r'^client-login/$', ClientLoginTokenView.as_view()), - url(r'^two-factor-auth/(?P\S+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/$', TwoFactorAuthView.as_view(), name="two-factor-auth-view"), - url(r'^device-wiped/$', RemoteWipeReportView.as_view()), - url(r'^wopi/', include('seahub.wopi.urls')), + path('ping/', Ping.as_view()), + path('auth/ping/', AuthPing.as_view()), + re_path(r'^auth-token/', ObtainAuthToken.as_view()), + path('server-info/', ServerInfoView.as_view()), + path('logout-device/', LogoutDeviceView.as_view()), + path('client-login/', ClientLoginTokenView.as_view()), + re_path(r'^two-factor-auth/(?P\S+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/$', TwoFactorAuthView.as_view(), name="two-factor-auth-view"), + path('device-wiped/', RemoteWipeReportView.as_view()), + path('wopi/', include('seahub.wopi.urls')), # RESTful API - url(r'^accounts/$', Accounts.as_view(), name="accounts"), - url(r'^accounts/(?P\S+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/$', Account.as_view(), name="api2-account"), - url(r'^account/info/$', AccountInfo.as_view()), - url(r'^regdevice/$', RegDevice.as_view(), name="regdevice"), - url(r'^search/$', Search.as_view(), name='api_search'), - url(r'^search-user/$', SearchUser.as_view(), name='search-user'), - url(r'^repos/$', Repos.as_view(), name="api2-repos"), - url(r'^repos/public/$', PubRepos.as_view(), name="api2-pub-repos"), - url(r'^repos/(?P[-0-9a-f]{36})/$', Repo.as_view(), name="api2-repo"), - url(r'^repos/(?P[-0-9a-f]{36})/history/$', RepoHistory.as_view()), - url(r'^repos/(?P[-0-9a-f]{36})/user-folder-perm/$', RepoUserFolderPerm.as_view(), name="api2-repo-user-folder-perm"), - url(r'^repos/(?P[-0-9a-f]{36})/group-folder-perm/$', RepoGroupFolderPerm.as_view(), name="api2-repo-group-folder-perm"), - url(r'^repos/(?P[-0-9a-f]{36})/history-limit/$', RepoHistoryLimit.as_view(), name="api2-repo-history-limit"), - url(r'^repos/(?P[-0-9a-f]{36})/download-info/$', DownloadRepo.as_view()), - url(r'^repos/(?P[-0-9a-f]{36})/owner/$', RepoOwner.as_view(), name="api2-repo-owner"), - url(r'^repos/(?P[-0-9a-f]{36})/download-shared-links/$', RepoDownloadSharedLinks.as_view(), name="api2-repo-download-shared-links"), - url(r'^repos/(?P[-0-9a-f]{36})/download-shared-links/(?P[a-f0-9]+)/$', RepoDownloadSharedLink.as_view(), name="api2-repo-download-shared-link"), - url(r'^repos/(?P[-0-9a-f]{36})/upload-shared-links/$', RepoUploadSharedLinks.as_view(), name="api2-repo-upload-shared-links"), - url(r'^repos/(?P[-0-9a-f]{36})/upload-shared-links/(?P[a-f0-9]+)/$', RepoUploadSharedLink.as_view(), name="api2-repo-upload-shared-link"), - url(r'^repos/(?P[-0-9a-f]{36})/upload-link/$', UploadLinkView.as_view()), - url(r'^repos/(?P[-0-9a-f]{36})/update-link/$', UpdateLinkView.as_view()), - url(r'^repos/(?P[-0-9a-f]{36})/upload-blks-link/$', UploadBlksLinkView.as_view()), - url(r'^repos/(?P[-0-9a-f]{36})/update-blks-link/$', UpdateBlksLinkView.as_view()), - url(r'^repos/(?P[-0-9-a-f]{36})/owa-file/$', OwaFileView.as_view(), name='api2-owa-file-view'), - url(r'^repos/(?P[-0-9-a-f]{36})/file/$', FileView.as_view(), name='FileView'), - url(r'^repos/(?P[-0-9-a-f]{36})/file/metadata/$', FileMetaDataView.as_view(), name='FileMetaDataView'), - url(r'^repos/(?P[-0-9a-f]{36})/files/(?P[0-9a-f]{40})/blks/(?P[0-9a-f]{40})/download-link/$', FileBlockDownloadLinkView.as_view()), - url(r'^repos/(?P[-0-9-a-f]{36})/file/comments/$', FileCommentsView.as_view(), name='api2-file-comments'), - url(r'^repos/(?P[-0-9-a-f]{36})/file/comments/counts/$', FileCommentsCounts.as_view(), name='api2-file-comments-counts'), - url(r'^repos/(?P[-0-9-a-f]{36})/file/comments/(?P\d+)/$', FileCommentView.as_view(), name='api2-file-comment'), - url(r'^repos/(?P[-0-9-a-f]{36})/file/detail/$', FileDetailView.as_view()), - url(r'^repos/(?P[-0-9-a-f]{36})/file/history/$', FileHistory.as_view()), - url(r'^repos/(?P[-0-9-a-f]{36})/file/revision/$', FileRevision.as_view()), - url(r'^repos/(?P[-0-9-a-f]{36})/file/revert/$', FileRevert.as_view(), name='api2-file-revert'), - url(r'^repos/(?P[-0-9-a-f]{36})/file/shared-link/$', FileSharedLinkView.as_view()), - url(r'^repos/(?P[-0-9-a-f]{36})/dir/$', DirView.as_view(), name='DirView'), - url(r'^repos/(?P[-0-9-a-f]{36})/dir/metadata/$', DirMetaDataView.as_view(), name='DirMetaDataView'), - url(r'^repos/(?P[-0-9-a-f]{36})/dir/sub_repo/$', DirSubRepoView.as_view(), name="api2-dir-sub-repo"), - url(r'^repos/(?P[-0-9-a-f]{36})/dir/shared_items/$', DirSharedItemsEndpoint.as_view(), name="api2-dir-shared-items"), - url(r'^repos/(?P[-0-9-a-f]{36})/dir/revert/$', DirRevert.as_view(), name='api2-dir-revert'), - url(r'^repos/(?P[-0-9-a-f]{36})/thumbnail/$', ThumbnailView.as_view(), name='api2-thumbnail'), - url(r'^starredfiles/', StarredFileView.as_view(), name='starredfiles'), - url(r'^devices/', DevicesView.as_view(), name='api2-devices'), - url(r'^shared-repos/$', SharedRepos.as_view(), name='sharedrepos'), - url(r'^shared-repos/(?P[-0-9-a-f]{36})/$', SharedRepo.as_view(), name='sharedrepo'), - url(r'^beshared-repos/$', BeSharedRepos.as_view(), name='beshared-repos'), - url(r'^beshared-repos/(?P[-0-9-a-f]{36})/$', BeSharedRepo.as_view(), name='beshared-repo'), - url(r'^default-repo/$', DefaultRepoView.as_view(), name='api2-defaultrepo'), - url(r'^send-share-link/$', SendShareLinkView.as_view(), name='api2-send-share-link'), - url(r'^send-upload-link/$', SendUploadLinkView.as_view(), name='api2-send-upload-link'), - url(r'^shared-links/$', SharedLinksView.as_view()), - url(r'^shared-upload-links/$', SharedUploadLinksView.as_view()), - url(r'^repo-tokens/$', RepoTokensView.as_view(), name='api2-repo-tokens'), + path('accounts/', Accounts.as_view(), name="accounts"), + re_path(r'^accounts/(?P\S+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/$', Account.as_view(), name="api2-account"), + path('account/info/', AccountInfo.as_view()), + path('regdevice/', RegDevice.as_view(), name="regdevice"), + path('search/', Search.as_view(), name='api_search'), + path('search-user/', SearchUser.as_view(), name='search-user'), + path('repos/', Repos.as_view(), name="api2-repos"), + path('repos/public/', PubRepos.as_view(), name="api2-pub-repos"), + re_path(r'^repos/(?P[-0-9a-f]{36})/$', Repo.as_view(), name="api2-repo"), + re_path(r'^repos/(?P[-0-9a-f]{36})/history/$', RepoHistory.as_view()), + re_path(r'^repos/(?P[-0-9a-f]{36})/user-folder-perm/$', RepoUserFolderPerm.as_view(), name="api2-repo-user-folder-perm"), + re_path(r'^repos/(?P[-0-9a-f]{36})/group-folder-perm/$', RepoGroupFolderPerm.as_view(), name="api2-repo-group-folder-perm"), + re_path(r'^repos/(?P[-0-9a-f]{36})/history-limit/$', RepoHistoryLimit.as_view(), name="api2-repo-history-limit"), + re_path(r'^repos/(?P[-0-9a-f]{36})/download-info/$', DownloadRepo.as_view()), + re_path(r'^repos/(?P[-0-9a-f]{36})/owner/$', RepoOwner.as_view(), name="api2-repo-owner"), + re_path(r'^repos/(?P[-0-9a-f]{36})/download-shared-links/$', RepoDownloadSharedLinks.as_view(), name="api2-repo-download-shared-links"), + re_path(r'^repos/(?P[-0-9a-f]{36})/download-shared-links/(?P[a-f0-9]+)/$', RepoDownloadSharedLink.as_view(), name="api2-repo-download-shared-link"), + re_path(r'^repos/(?P[-0-9a-f]{36})/upload-shared-links/$', RepoUploadSharedLinks.as_view(), name="api2-repo-upload-shared-links"), + re_path(r'^repos/(?P[-0-9a-f]{36})/upload-shared-links/(?P[a-f0-9]+)/$', RepoUploadSharedLink.as_view(), name="api2-repo-upload-shared-link"), + re_path(r'^repos/(?P[-0-9a-f]{36})/upload-link/$', UploadLinkView.as_view()), + re_path(r'^repos/(?P[-0-9a-f]{36})/update-link/$', UpdateLinkView.as_view()), + re_path(r'^repos/(?P[-0-9a-f]{36})/upload-blks-link/$', UploadBlksLinkView.as_view()), + re_path(r'^repos/(?P[-0-9a-f]{36})/update-blks-link/$', UpdateBlksLinkView.as_view()), + re_path(r'^repos/(?P[-0-9-a-f]{36})/owa-file/$', OwaFileView.as_view(), name='api2-owa-file-view'), + re_path(r'^repos/(?P[-0-9-a-f]{36})/file/$', FileView.as_view(), name='FileView'), + re_path(r'^repos/(?P[-0-9-a-f]{36})/file/metadata/$', FileMetaDataView.as_view(), name='FileMetaDataView'), + re_path(r'^repos/(?P[-0-9a-f]{36})/files/(?P[0-9a-f]{40})/blks/(?P[0-9a-f]{40})/download-link/$', FileBlockDownloadLinkView.as_view()), + re_path(r'^repos/(?P[-0-9-a-f]{36})/file/comments/$', FileCommentsView.as_view(), name='api2-file-comments'), + re_path(r'^repos/(?P[-0-9-a-f]{36})/file/comments/counts/$', FileCommentsCounts.as_view(), name='api2-file-comments-counts'), + re_path(r'^repos/(?P[-0-9-a-f]{36})/file/comments/(?P\d+)/$', FileCommentView.as_view(), name='api2-file-comment'), + re_path(r'^repos/(?P[-0-9-a-f]{36})/file/detail/$', FileDetailView.as_view()), + re_path(r'^repos/(?P[-0-9-a-f]{36})/file/history/$', FileHistory.as_view()), + re_path(r'^repos/(?P[-0-9-a-f]{36})/file/revision/$', FileRevision.as_view()), + re_path(r'^repos/(?P[-0-9-a-f]{36})/file/revert/$', FileRevert.as_view(), name='api2-file-revert'), + re_path(r'^repos/(?P[-0-9-a-f]{36})/file/shared-link/$', FileSharedLinkView.as_view()), + re_path(r'^repos/(?P[-0-9-a-f]{36})/dir/$', DirView.as_view(), name='DirView'), + re_path(r'^repos/(?P[-0-9-a-f]{36})/dir/metadata/$', DirMetaDataView.as_view(), name='DirMetaDataView'), + re_path(r'^repos/(?P[-0-9-a-f]{36})/dir/sub_repo/$', DirSubRepoView.as_view(), name="api2-dir-sub-repo"), + re_path(r'^repos/(?P[-0-9-a-f]{36})/dir/shared_items/$', DirSharedItemsEndpoint.as_view(), name="api2-dir-shared-items"), + re_path(r'^repos/(?P[-0-9-a-f]{36})/dir/revert/$', DirRevert.as_view(), name='api2-dir-revert'), + re_path(r'^repos/(?P[-0-9-a-f]{36})/thumbnail/$', ThumbnailView.as_view(), name='api2-thumbnail'), + re_path(r'^starredfiles/', StarredFileView.as_view(), name='starredfiles'), + re_path(r'^devices/', DevicesView.as_view(), name='api2-devices'), + path('shared-repos/', SharedRepos.as_view(), name='sharedrepos'), + re_path(r'^shared-repos/(?P[-0-9-a-f]{36})/$', SharedRepo.as_view(), name='sharedrepo'), + path('beshared-repos/', BeSharedRepos.as_view(), name='beshared-repos'), + re_path(r'^beshared-repos/(?P[-0-9-a-f]{36})/$', BeSharedRepo.as_view(), name='beshared-repo'), + path('default-repo/', DefaultRepoView.as_view(), name='api2-defaultrepo'), + path('send-share-link/', SendShareLinkView.as_view(), name='api2-send-share-link'), + path('send-upload-link/', SendUploadLinkView.as_view(), name='api2-send-upload-link'), + path('shared-links/', SharedLinksView.as_view()), + path('shared-upload-links/', SharedUploadLinksView.as_view()), + path('repo-tokens/', RepoTokensView.as_view(), name='api2-repo-tokens'), - url(r'^organization/$', OrganizationView.as_view(), name='api2-org'), + path('organization/', OrganizationView.as_view(), name='api2-org'), - url(r'^f/(?P[a-f0-9]+)/$', SharedFileView.as_view()), - url(r'^f/(?P[a-f0-9]+)/detail/$', SharedFileDetailView.as_view()), - url(r'^d/(?P[a-f0-9]+)/dir/$', SharedDirView.as_view()), + re_path(r'^f/(?P[a-f0-9]+)/$', SharedFileView.as_view()), + re_path(r'^f/(?P[a-f0-9]+)/detail/$', SharedFileDetailView.as_view()), + re_path(r'^d/(?P[a-f0-9]+)/dir/$', SharedDirView.as_view()), - url(r'^events/$', EventsView.as_view()), - url(r'^repo_history_changes/(?P[-0-9a-f]{36})/$', RepoHistoryChange.as_view()), - url(r'^unseen_messages/$', UnseenMessagesCountView.as_view()), + path('events/', EventsView.as_view()), + re_path(r'^repo_history_changes/(?P[-0-9a-f]{36})/$', RepoHistoryChange.as_view()), + path('unseen_messages/', UnseenMessagesCountView.as_view()), - url(r'^avatars/user/(?P\S+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/resized/(?P[0-9]+)/$', UserAvatarView.as_view()), - url(r'^avatars/group/(?P\d+)/resized/(?P[0-9]+)/$', GroupAvatarView.as_view()), + re_path(r'^avatars/user/(?P\S+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/resized/(?P[0-9]+)/$', UserAvatarView.as_view()), + path('avatars/group//resized//', GroupAvatarView.as_view()), - url(r'^groups/$', Groups.as_view()), - url(r'^groups/(?P\d+)/$', Groups.as_view()), - url(r'^groups/(?P\d+)/members/$', GroupMembers.as_view()), - url(r'^groups/(?P\d+)/repos/$', GroupRepos.as_view(), name="api2-grouprepos"), - url(r'^groups/(?P\d+)/repos/(?P[-0-9a-f]{36})/$', GroupRepo.as_view(), name="api2-grouprepo"), + path('groups/', Groups.as_view()), + path('groups//', Groups.as_view()), + path('groups//members/', GroupMembers.as_view()), + path('groups//repos/', GroupRepos.as_view(), name="api2-grouprepos"), + re_path(r'^groups/(?P\d+)/repos/(?P[-0-9a-f]{36})/$', GroupRepo.as_view(), name="api2-grouprepo"), # Deprecated - url(r'^repos/(?P[-0-9-a-f]{36})/fileops/delete/$', OpDeleteView.as_view(), name="api2-fileops-delete"), - url(r'^repos/(?P[-0-9-a-f]{36})/fileops/copy/$', OpCopyView.as_view(), name="api2-fileops-copy"), - url(r'^repos/(?P[-0-9-a-f]{36})/fileops/move/$', OpMoveView.as_view(), name="api2-fileops-move"), + re_path(r'^repos/(?P[-0-9-a-f]{36})/fileops/delete/$', OpDeleteView.as_view(), name="api2-fileops-delete"), + re_path(r'^repos/(?P[-0-9-a-f]{36})/fileops/copy/$', OpCopyView.as_view(), name="api2-fileops-copy"), + re_path(r'^repos/(?P[-0-9-a-f]{36})/fileops/move/$', OpMoveView.as_view(), name="api2-fileops-move"), ] # serve office converter static files from seahub.utils import HAS_OFFICE_CONVERTER if HAS_OFFICE_CONVERTER: urlpatterns += [ - url(r'^office-convert/status/$', OfficeConvertQueryStatus.as_view()), + path('office-convert/status/', OfficeConvertQueryStatus.as_view()), ] urlpatterns += [ - url(r'^office-convert/generate/repos/(?P[-0-9-a-f]{36})/$', OfficeGenerateView.as_view()), + re_path(r'^office-convert/generate/repos/(?P[-0-9-a-f]{36})/$', OfficeGenerateView.as_view()), ] diff --git a/seahub/api2/utils.py b/seahub/api2/utils.py index e4f197bd28..9bea136070 100644 --- a/seahub/api2/utils.py +++ b/seahub/api2/utils.py @@ -132,7 +132,7 @@ def api_group_check(func): return _decorated def get_client_ip(request): - x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR', '') + x_forwarded_for = request.headers.get('x-forwarded-for', '') if x_forwarded_for: ip = x_forwarded_for.split(',')[0] else: diff --git a/seahub/api2/views.py b/seahub/api2/views.py index 06a6ab71eb..dd2e7dac72 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -27,7 +27,7 @@ from django.db.models import F from django.http import HttpResponse from django.template.defaultfilters import filesizeformat from django.utils import timezone -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from .throttling import ScopedRateThrottle, AnonRateThrottle, UserRateThrottle from .authentication import TokenAuthentication @@ -198,12 +198,12 @@ class ObtainAuthToken(APIView): trust_dev = False try: - trust_dev_header = int(request.META.get('HTTP_X_SEAFILE_2FA_TRUST_DEVICE', '')) + trust_dev_header = int(request.headers.get('x-seafile-2fa-trust-device', '')) trust_dev = True if trust_dev_header == 1 else False except ValueError: trust_dev = False - skip_2fa_header = request.META.get('HTTP_X_SEAFILE_S2FA', None) + skip_2fa_header = request.headers.get('x-seafile-s2fa', None) if skip_2fa_header is None: if trust_dev: # 2fa login with trust device, diff --git a/seahub/auth/decorators.py b/seahub/auth/decorators.py index feaa219b62..f3b04adbd8 100644 --- a/seahub/auth/decorators.py +++ b/seahub/auth/decorators.py @@ -6,9 +6,9 @@ except ImportError: from seahub.auth import REDIRECT_FIELD_NAME from django.http import HttpResponseRedirect, HttpResponse, Http404 -from django.utils.http import urlquote +from urllib.parse import quote import json -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ def user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME): """ @@ -24,7 +24,7 @@ def user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIE def _wrapped_view(request, *args, **kwargs): if test_func(request.user): return view_func(request, *args, **kwargs) - path = urlquote(request.get_full_path()) + path = quote(request.get_full_path()) tup = login_url, redirect_field_name, path return HttpResponseRedirect('%s?%s=%s' % tup) return wraps(view_func)(_wrapped_view) @@ -62,7 +62,7 @@ def login_required_ajax(function=None,redirect_field_name=None): """ def _decorator(view_func): def _wrapped_view(request, *args, **kwargs): - if not request.is_ajax(): + if not request.headers.get('x-requested-with') == 'XMLHttpRequest': raise Http404 if request.user.is_authenticated: diff --git a/seahub/auth/forms.py b/seahub/auth/forms.py index 8ae51b9a28..59ac741118 100644 --- a/seahub/auth/forms.py +++ b/seahub/auth/forms.py @@ -1,7 +1,7 @@ # Copyright (c) 2012-2016 Seafile Ltd. from django.conf import settings from django import forms -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.utils.http import int_to_base36 from collections import OrderedDict diff --git a/seahub/auth/models.py b/seahub/auth/models.py index f0387bed5d..0525ef4ba3 100644 --- a/seahub/auth/models.py +++ b/seahub/auth/models.py @@ -10,7 +10,7 @@ from django.db import models from django.db.models.manager import EmptyManager from django.contrib.contenttypes.models import ContentType from django.utils.encoding import smart_str -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.conf import settings logger = logging.getLogger(__name__) diff --git a/seahub/auth/signals.py b/seahub/auth/signals.py index d7e2d50b3e..c8e456dd76 100644 --- a/seahub/auth/signals.py +++ b/seahub/auth/signals.py @@ -1,5 +1,5 @@ # Copyright (c) 2012-2016 Seafile Ltd. from django.dispatch import Signal -user_logged_in = Signal(providing_args=['request', 'user']) -user_logged_in_failed = Signal(providing_args=['request']) +user_logged_in = Signal() +user_logged_in_failed = Signal() diff --git a/seahub/auth/utils.py b/seahub/auth/utils.py index 17eaf041ca..38ec932bc5 100644 --- a/seahub/auth/utils.py +++ b/seahub/auth/utils.py @@ -1,7 +1,7 @@ # Copyright (c) 2012-2016 Seafile Ltd. from django.core.cache import cache from django.conf import settings -from django.utils.http import urlquote +from urllib.parse import quote from seahub.profile.models import Profile from seahub.utils import normalize_cache_key diff --git a/seahub/auth/views.py b/seahub/auth/views.py index 844396e769..db2d753b36 100644 --- a/seahub/auth/views.py +++ b/seahub/auth/views.py @@ -11,8 +11,9 @@ from django.shortcuts import render from django.contrib.sites.shortcuts import get_current_site from django.http import HttpResponseRedirect, Http404 -from django.utils.http import urlquote, base36_to_int, is_safe_url -from django.utils.translation import ugettext as _ +from urllib.parse import quote +from django.utils.http import base36_to_int, url_has_allowed_host_and_scheme +from django.utils.translation import gettext as _ from django.views.decorators.cache import never_cache from saml2.ident import decode from seaserv import seafile_api, ccnet_api @@ -52,7 +53,7 @@ logger = logging.getLogger(__name__) def log_user_in(request, user, redirect_to): # Ensure the user-originating redirection url is safe. - if not is_safe_url(url=redirect_to, allowed_hosts=request.get_host()): + if not url_has_allowed_host_and_scheme(url=redirect_to, allowed_hosts=request.get_host()): redirect_to = settings.LOGIN_REDIRECT_URL if request.session.test_cookie_worked(): @@ -97,7 +98,7 @@ def login(request, template_name='registration/login.html', redirect_to = request.GET.get(redirect_field_name, '') if request.user.is_authenticated: - if redirect_to and is_safe_url(redirect_to, allowed_hosts=request.get_host()): + if redirect_to and url_has_allowed_host_and_scheme(redirect_to, allowed_hosts=request.get_host()): return HttpResponseRedirect(redirect_to) else: return HttpResponseRedirect(reverse(redirect_if_logged_in)) @@ -239,7 +240,7 @@ def login_simple_check(request): # Ensure the user-originating redirection url is safe. if REDIRECT_FIELD_NAME in request.GET: next_page = request.GET[REDIRECT_FIELD_NAME] - if not is_safe_url(url=next_page, allowed_hosts=request.get_host()): + if not url_has_allowed_host_and_scheme(url=next_page, allowed_hosts=request.get_host()): next_page = settings.LOGIN_REDIRECT_URL else: next_page = settings.SITE_ROOT @@ -294,7 +295,7 @@ def logout(request, next_page=None, if redirect_field_name in request.GET: next_page = request.GET[redirect_field_name] # Security check -- don't allow redirection to a different host. - if not is_safe_url(url=next_page, allowed_hosts=request.get_host()): + if not url_has_allowed_host_and_scheme(url=next_page, allowed_hosts=request.get_host()): next_page = request.path if next_page is None: @@ -304,7 +305,7 @@ def logout(request, next_page=None, else: response = render(request, template_name, { 'title': _('Logged out'), - 'request_from_onlyoffice_desktop_editor': ONLYOFFICE_DESKTOP_EDITOR_HTTP_USER_AGENT in request.META.get('HTTP_USER_AGENT', ''), + 'request_from_onlyoffice_desktop_editor': ONLYOFFICE_DESKTOP_EDITOR_HTTP_USER_AGENT in request.headers.get('user-agent', ''), }) else: # Redirect to this page until the session has been cleared. @@ -323,7 +324,7 @@ def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_N "Redirects the user to the login page, passing the given 'next' page" if not login_url: login_url = settings.LOGIN_URL - return HttpResponseRedirect('%s?%s=%s' % (login_url, urlquote(redirect_field_name), urlquote(next))) + return HttpResponseRedirect('%s?%s=%s' % (login_url, quote(redirect_field_name), quote(next))) # 4 views for password reset: # - password_reset sends the mail @@ -346,7 +347,7 @@ def password_reset(request, is_admin_site=False, template_name='registration/pas opts['use_https'] = request.is_secure() opts['token_generator'] = token_generator if is_admin_site: - opts['domain_override'] = request.META['HTTP_HOST'] + opts['domain_override'] = request.headers['host'] else: opts['email_template_name'] = email_template_name opts['domain_override'] = get_current_site(request).domain diff --git a/seahub/avatar/forms.py b/seahub/avatar/forms.py index f58fabad39..11c9613b96 100644 --- a/seahub/avatar/forms.py +++ b/seahub/avatar/forms.py @@ -4,7 +4,7 @@ import os from django import forms from django.forms import widgets from django.utils.safestring import mark_safe -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from seahub.avatar.models import Avatar from seahub.avatar.settings import (AVATAR_MAX_AVATARS_PER_USER, AVATAR_MAX_SIZE, diff --git a/seahub/avatar/models.py b/seahub/avatar/models.py index 748bbd437b..f08a4c71f9 100644 --- a/seahub/avatar/models.py +++ b/seahub/avatar/models.py @@ -9,7 +9,7 @@ from seahub.base.fields import LowerCaseCharField from django.db import models from django.core.files.base import ContentFile -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.utils.encoding import smart_str from django.db.models import signals diff --git a/seahub/avatar/signals.py b/seahub/avatar/signals.py index 487bf5cb26..863621a01c 100644 --- a/seahub/avatar/signals.py +++ b/seahub/avatar/signals.py @@ -2,4 +2,4 @@ import django.dispatch -avatar_updated = django.dispatch.Signal(providing_args=["user", "avatar"]) \ No newline at end of file +avatar_updated = django.dispatch.Signal() diff --git a/seahub/avatar/urls.py b/seahub/avatar/urls.py index ff0e26b8f5..29164d4e18 100644 --- a/seahub/avatar/urls.py +++ b/seahub/avatar/urls.py @@ -1,9 +1,9 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url +from django.urls import path, re_path from .views import add, render_primary urlpatterns = [ - url('^add/$', add, name='avatar_add'), + path('add/', add, name='avatar_add'), # url('^change/$', 'change', name='avatar_change'), # url('^delete/$', 'delete', name='avatar_delete'), - url('^render_primary/(?P[^/]+)/(?P[\d]+)/$', render_primary, name='avatar_render_primary'), + re_path('^render_primary/(?P[^/]+)/(?P[\d]+)/$', render_primary, name='avatar_render_primary'), ] diff --git a/seahub/avatar/util.py b/seahub/avatar/util.py index d1be67b502..2c55f8c929 100644 --- a/seahub/avatar/util.py +++ b/seahub/avatar/util.py @@ -2,7 +2,7 @@ from django.conf import settings from django.core.cache import cache from django.core.files.storage import default_storage, get_storage_class -from django.utils.http import urlquote +from urllib.parse import quote from seahub.base.accounts import User from seahub.avatar.settings import AVATAR_DEFAULT_URL, AVATAR_CACHE_TIMEOUT,\ @@ -18,7 +18,7 @@ def get_cache_key(user_or_username, size, prefix): """ if isinstance(user_or_username, User): user_or_username = user_or_username.username - return '%s_%s_%s' % (prefix, urlquote(user_or_username), size) + return '%s_%s_%s' % (prefix, quote(user_or_username), size) def get_grp_cache_key(group_id, size): """ diff --git a/seahub/avatar/views.py b/seahub/avatar/views.py index 5388891284..886219f1d8 100644 --- a/seahub/avatar/views.py +++ b/seahub/avatar/views.py @@ -3,7 +3,7 @@ from django.core.cache import cache from django.http import HttpResponseRedirect, Http404 from django.shortcuts import render -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.conf import settings from django.contrib import messages @@ -34,7 +34,7 @@ def _get_next(request): redirect to that previous page. """ next_page = request.POST.get('next', request.GET.get('next', - request.META.get('HTTP_REFERER', None))) + request.headers.get('referer', None))) if not next_page: next_page = request.path return next_page diff --git a/seahub/base/__init__.py b/seahub/base/__init__.py index c8cfde2bce..48277f9ec3 100644 --- a/seahub/base/__init__.py +++ b/seahub/base/__init__.py @@ -1,2 +1 @@ # Copyright (c) 2012-2016 Seafile Ltd. -default_app_config = 'seahub.base.apps.BaseConfig' diff --git a/seahub/base/accounts.py b/seahub/base/accounts.py index 69f30122aa..c878b255e0 100644 --- a/seahub/base/accounts.py +++ b/seahub/base/accounts.py @@ -6,8 +6,8 @@ import logging from django import forms from django.core.mail import send_mail from django.utils import translation -from django.utils.encoding import smart_text -from django.utils.translation import ugettext_lazy as _ +from django.utils.encoding import smart_str +from django.utils.translation import gettext_lazy as _ from django.conf import settings from django.contrib.sites.shortcuts import get_current_site from seaserv import ccnet_threaded_rpc, unset_repo_passwd, \ @@ -295,7 +295,7 @@ class User(object): def name(self): if not hasattr(self, '_cached_nickname'): # convert raw string to unicode obj - self._cached_nickname = smart_text(email2nickname(self.username)) + self._cached_nickname = smart_str(email2nickname(self.username)) return self._cached_nickname diff --git a/seahub/base/context_processors.py b/seahub/base/context_processors.py index ba57204374..32f2e7199a 100644 --- a/seahub/base/context_processors.py +++ b/seahub/base/context_processors.py @@ -83,7 +83,8 @@ def base(request): # filter ajax/api request out avatar_url = '' username = request.user.username - if (not request.is_ajax()) and ("api2/" not in request.path) and \ + + if (not request.headers.get('x-requested-with') == 'XMLHttpRequest') and ("api2/" not in request.path) and \ ("api/v2.1/" not in request.path): # get logo path diff --git a/seahub/base/decorators.py b/seahub/base/decorators.py index f07a7a85bf..6a18ec8f6e 100644 --- a/seahub/base/decorators.py +++ b/seahub/base/decorators.py @@ -3,14 +3,14 @@ from django.urls import reverse from django.http import Http404, HttpResponseRedirect, HttpResponseNotAllowed from django.shortcuts import render -from django.utils.http import urlquote +from urllib.parse import quote from seaserv import get_repo, seafile_api from seahub.options.models import UserOptions, CryptoOptionNotSetError from seahub.base.sudo_mode import sudo_mode_check from seahub.utils import render_error -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.settings import ENABLE_SUDO_MODE def sys_staff_required(func): @@ -22,7 +22,7 @@ def sys_staff_required(func): raise Http404 if ENABLE_SUDO_MODE and not sudo_mode_check(request): return HttpResponseRedirect( - reverse('sys_sudo_mode') + '?next=' + urlquote(request.get_full_path())) + reverse('sys_sudo_mode') + '?next=' + quote(request.get_full_path())) return func(request, *args, **kwargs) return _decorated diff --git a/seahub/base/management/commands/check_user_quota.py b/seahub/base/management/commands/check_user_quota.py index 810eb757b0..6c1f7a3a0f 100644 --- a/seahub/base/management/commands/check_user_quota.py +++ b/seahub/base/management/commands/check_user_quota.py @@ -1,7 +1,7 @@ # Copyright (c) 2012-2016 Seafile Ltd. from django.core.management.base import BaseCommand -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.utils import translation from seaserv import ccnet_api, seafile_api diff --git a/seahub/base/management/commands/createsuperuser.py b/seahub/base/management/commands/createsuperuser.py index 7dba7ac650..b1df75cbc0 100644 --- a/seahub/base/management/commands/createsuperuser.py +++ b/seahub/base/management/commands/createsuperuser.py @@ -10,7 +10,7 @@ import sys from optparse import make_option from django.core import exceptions from django.core.management.base import BaseCommand, CommandError -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.base.accounts import User diff --git a/seahub/base/management/commands/export_file_access_log.py b/seahub/base/management/commands/export_file_access_log.py index cbaa342570..3161f16ad4 100644 --- a/seahub/base/management/commands/export_file_access_log.py +++ b/seahub/base/management/commands/export_file_access_log.py @@ -4,7 +4,7 @@ import logging import posixpath from django.core.management.base import BaseCommand -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api diff --git a/seahub/base/management/commands/export_user_storage_report.py b/seahub/base/management/commands/export_user_storage_report.py index cc4983a32a..32347976cb 100644 --- a/seahub/base/management/commands/export_user_storage_report.py +++ b/seahub/base/management/commands/export_user_storage_report.py @@ -4,7 +4,7 @@ import logging import posixpath from django.core.management.base import BaseCommand -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import ccnet_api diff --git a/seahub/base/management/commands/export_user_traffic_report.py b/seahub/base/management/commands/export_user_traffic_report.py index edd44fa9cf..1dd3ebc915 100644 --- a/seahub/base/management/commands/export_user_traffic_report.py +++ b/seahub/base/management/commands/export_user_traffic_report.py @@ -5,7 +5,7 @@ import datetime import posixpath from django.core.management.base import BaseCommand -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.utils import get_all_users_traffic_by_month from seahub.utils.ms_excel import write_xls diff --git a/seahub/base/management/commands/export_users.py b/seahub/base/management/commands/export_users.py index 05290fbcf4..8d2517a7cd 100644 --- a/seahub/base/management/commands/export_users.py +++ b/seahub/base/management/commands/export_users.py @@ -4,7 +4,7 @@ import logging from django.core.management.base import BaseCommand -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api, ccnet_api diff --git a/seahub/base/middleware.py b/seahub/base/middleware.py index ddda7853ed..92e89a4dd3 100644 --- a/seahub/base/middleware.py +++ b/seahub/base/middleware.py @@ -57,7 +57,7 @@ class InfobarMiddleware(MiddlewareMixin): def process_request(self, request): # filter AJAX request out - if request.is_ajax(): + if request.headers.get('x-requested-with') == 'XMLHttpRequest': return None # filter API request out diff --git a/seahub/base/registration_urls.py b/seahub/base/registration_urls.py index 71e93014eb..9ff73ddaea 100644 --- a/seahub/base/registration_urls.py +++ b/seahub/base/registration_urls.py @@ -1,5 +1,5 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url, include +from django.urls import include, path, re_path from django.views.generic import TemplateView from django.conf import settings @@ -17,18 +17,18 @@ reg_dict = { 'backend': 'seahub.base.accounts.RegistrationBackend', } urlpatterns = [ - url(r'^activate/complete/$', + path('activate/complete/', TemplateView.as_view(template_name='registration/activation_complete.html'), name='registration_activation_complete'), # Activation keys get matched by \w+ instead of the more specific # [a-fA-F0-9]{40} because a bad activation key should still get to the view; # that way it can return a sensible "invalid key" message instead of a # confusing 404. - url(r'^activate/(?P\w+)/$', + re_path(r'^activate/(?P\w+)/$', activate, { 'backend': 'seahub.base.accounts.RegistrationBackend', }, name='registration_activate'), - url(r'', include('registration.auth_urls')), + path('', include('registration.auth_urls')), ] try: @@ -37,10 +37,10 @@ except ImportError: CLOUD_MODE = False urlpatterns += [ - url(r'^register/$', register, + path('register/', register, reg_dict, name='registration_register'), - url(r'^register/complete/$', + path('register/complete/', DirectTemplateView.as_view(template_name='registration/registration_complete.html'), name='registration_complete'), ] diff --git a/seahub/base/templatetags/rest_framework.py b/seahub/base/templatetags/rest_framework.py index 25da7db011..97b218c689 100644 --- a/seahub/base/templatetags/rest_framework.py +++ b/seahub/base/templatetags/rest_framework.py @@ -2,7 +2,7 @@ from django import template from django.urls import reverse from django.http import QueryDict -from django.utils.encoding import force_text +from django.utils.encoding import force_str from django.utils.html import escape from django.utils.safestring import SafeData, mark_safe from urllib.parse import urlsplit, urlunsplit @@ -131,7 +131,7 @@ def urlize_quoted_links(text, trim_url_limit=None, nofollow=True, autoescape=Tru """ trim_url = lambda x, limit=trim_url_limit: limit is not None and (len(x) > limit and ('%s...' % x[:max(0, limit - 3)])) or x safe_input = isinstance(text, SafeData) - words = word_split_re.split(force_text(text)) + words = word_split_re.split(force_str(text)) nofollow_attr = nofollow and ' rel="nofollow"' or '' for i, word in enumerate(words): match = None diff --git a/seahub/base/templatetags/seahub_tags.py b/seahub/base/templatetags/seahub_tags.py index a9de49bac9..d396cd614a 100644 --- a/seahub/base/templatetags/seahub_tags.py +++ b/seahub/base/templatetags/seahub_tags.py @@ -10,8 +10,8 @@ from django.core.cache import cache from django.utils.safestring import mark_safe from django.utils import translation, formats from django.utils.dateformat import DateFormat -from django.utils.translation import ugettext as _ -from django.utils.translation import ugettext, ungettext +from django.utils.translation import gettext as _ +from django.utils.translation import gettext, ngettext from django.utils.timezone import get_current_timezone from django.utils.html import escape @@ -323,27 +323,27 @@ def translate_seahub_time_str(val): if days * 24 * 60 * 60 + seconds > limit: return val.strftime("%Y-%m-%d") elif days > 0: - ret = ungettext( + ret = ngettext( '%(days)d day ago', '%(days)d days ago', days ) % { 'days': days } return ret elif seconds > 60 * 60: hours = seconds / 3600 - ret = ungettext( + ret = ngettext( '%(hours)d hour ago', '%(hours)d hours ago', hours ) % { 'hours': hours } return ret elif seconds > 60: minutes = seconds/60 - ret = ungettext( + ret = ngettext( '%(minutes)d minute ago', '%(minutes)d minutes ago', minutes ) % { 'minutes': minutes } return ret elif seconds > 0: - ret = ungettext( + ret = ngettext( '%(seconds)d second ago', '%(seconds)d seconds ago', seconds ) % { 'seconds': seconds } @@ -494,7 +494,7 @@ def seahub_filesizeformat(bytes): try: bytes = float(bytes) except (TypeError, ValueError, UnicodeDecodeError): - value = ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0} + value = ngettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0} return avoid_wrapping(value) filesize_number_format = lambda value: formats.number_format(round(value, 1), 1) @@ -506,16 +506,16 @@ def seahub_filesizeformat(bytes): PB = get_file_size_unit('PB') if bytes < KB: - value = ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes} + value = ngettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes} elif bytes < MB: - value = ugettext("%s KB") % filesize_number_format(bytes / KB) + value = gettext("%s KB") % filesize_number_format(bytes / KB) elif bytes < GB: - value = ugettext("%s MB") % filesize_number_format(bytes / MB) + value = gettext("%s MB") % filesize_number_format(bytes / MB) elif bytes < TB: - value = ugettext("%s GB") % filesize_number_format(bytes / GB) + value = gettext("%s GB") % filesize_number_format(bytes / GB) elif bytes < PB: - value = ugettext("%s TB") % filesize_number_format(bytes / TB) + value = gettext("%s TB") % filesize_number_format(bytes / TB) else: - value = ugettext("%s PB") % filesize_number_format(bytes / PB) + value = gettext("%s PB") % filesize_number_format(bytes / PB) return avoid_wrapping(value) diff --git a/seahub/base/utils.py b/seahub/base/utils.py index 263b4bbda2..006c89ba3a 100644 --- a/seahub/base/utils.py +++ b/seahub/base/utils.py @@ -3,9 +3,9 @@ import re import string from django.utils.safestring import SafeData, mark_safe -from django.utils.encoding import force_text +from django.utils.encoding import force_str from django.utils.functional import allow_lazy -from django.utils.http import urlquote +from urllib.parse import quote # Configuration for urlize() function. LEADING_PUNCTUATION = ['(', '<', '<'] @@ -21,7 +21,7 @@ def escape(html): """ Returns the given HTML with ampersands, quotes and angle brackets encoded. """ - return mark_safe(force_text(html).replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", ''')) + return mark_safe(force_str(html).replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", ''')) escape = allow_lazy(escape, str) ## modification of django's urlize, add '%' to safe: @@ -47,7 +47,7 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False): """ trim_url = lambda x, limit=trim_url_limit: limit is not None and (len(x) > limit and ('%s...' % x[:max(0, limit - 3)])) or x safe_input = isinstance(text, SafeData) - words = word_split_re.split(force_text(text)) + words = word_split_re.split(force_str(text)) nofollow_attr = nofollow and ' rel="nofollow"' or '' for i, word in enumerate(words): match = None @@ -58,11 +58,11 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False): # Make URL we want to point to. url = None if middle.startswith('http://') or middle.startswith('https://'): - url = urlquote(middle, safe='/&=:;#?+*%') + url = quote(middle, safe='/&=:;#?+*%') elif middle.startswith('www.') or ('@' not in middle and \ middle and middle[0] in string.ascii_letters + string.digits and \ (middle.endswith('.org') or middle.endswith('.net') or middle.endswith('.com'))): - url = urlquote('http://%s' % middle, safe='/&=:;#?+*%') + url = quote('http://%s' % middle, safe='/&=:;#?+*%') # elif '@' in middle and not ':' in middle and simple_email_re.match(middle): # url = 'mailto:%s' % middle # nofollow_attr = '' diff --git a/seahub/cad/urls.py b/seahub/cad/urls.py index 3705e135c4..75d8f4b02a 100644 --- a/seahub/cad/urls.py +++ b/seahub/cad/urls.py @@ -1,9 +1,9 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url +from django.urls import path from .views import CadApiFileContentView urlpatterns = [ # RESTful API - url(r'^api/file-content/$', CadApiFileContentView.as_view(), name='CadApiFileContentView'), + path('api/file-content/', CadApiFileContentView.as_view(), name='CadApiFileContentView'), ] diff --git a/seahub/contacts/models.py b/seahub/contacts/models.py index 0cdeb2259c..a0d31a2884 100644 --- a/seahub/contacts/models.py +++ b/seahub/contacts/models.py @@ -3,7 +3,7 @@ from django import forms from django.db import models from django.forms import ModelForm -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.core.exceptions import MultipleObjectsReturned from seaserv import ccnet_threaded_rpc diff --git a/seahub/contacts/signals.py b/seahub/contacts/signals.py index a88237d53c..53039dc14e 100644 --- a/seahub/contacts/signals.py +++ b/seahub/contacts/signals.py @@ -1,4 +1,4 @@ # Copyright (c) 2012-2016 Seafile Ltd. -import django.dispatch +from django.dispatch import Signal -mail_sended = django.dispatch.Signal(providing_args=["user", "email"]) +mail_sended = Signal() diff --git a/seahub/contacts/urls.py b/seahub/contacts/urls.py index a807819134..eb7a631794 100644 --- a/seahub/contacts/urls.py +++ b/seahub/contacts/urls.py @@ -1,13 +1,13 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url +from django.urls import path from .views import * urlpatterns = [ - url(r'^$', contact_list, name='contacts'), - url(r'^list/$', contact_list, name='contact_list'), - url(r'^add/$', contact_add, name='contact_add'), - url(r'^edit/$', contact_edit, name='contact_edit'), - url(r'^delete/$', contact_delete, name='contact_delete'), + path('', contact_list, name='contacts'), + path('list/', contact_list, name='contact_list'), + path('add/', contact_add, name='contact_add'), + path('edit/', contact_edit, name='contact_edit'), + path('delete/', contact_delete, name='contact_delete'), ] diff --git a/seahub/contacts/views.py b/seahub/contacts/views.py index a9eb98828c..2a0ba02b33 100644 --- a/seahub/contacts/views.py +++ b/seahub/contacts/views.py @@ -10,7 +10,7 @@ from django.urls import reverse from django.core.exceptions import ObjectDoesNotExist from django.forms.models import modelformset_factory from django.contrib import messages -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from .models import Contact, ContactAddForm, ContactEditForm from seahub.auth.decorators import login_required, login_required_ajax diff --git a/seahub/dingtalk/views.py b/seahub/dingtalk/views.py index d397e5b85f..4f4db638b0 100644 --- a/seahub/dingtalk/views.py +++ b/seahub/dingtalk/views.py @@ -12,7 +12,7 @@ from hashlib import sha256 from django.http import HttpResponseRedirect from django.urls import reverse -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.api2.utils import get_api_token from seahub import auth diff --git a/seahub/django_cas_ng/decorators.py b/seahub/django_cas_ng/decorators.py index 503c07cbb7..01983cec07 100644 --- a/seahub/django_cas_ng/decorators.py +++ b/seahub/django_cas_ng/decorators.py @@ -12,7 +12,7 @@ from django.contrib.auth import REDIRECT_FIELD_NAME from django.contrib.auth.decorators import login_required from django.http import HttpResponseRedirect from django.core.exceptions import PermissionDenied -from django.utils.http import urlquote +from urllib.parse import quote import django @@ -43,7 +43,7 @@ def user_passes_test(test_func, login_url=None, raise PermissionDenied else: path = '%s?%s=%s' % (login_url, redirect_field_name, - urlquote(request.get_full_path())) + quote(request.get_full_path())) return HttpResponseRedirect(path) return wrapper return decorator diff --git a/seahub/django_cas_ng/signals.py b/seahub/django_cas_ng/signals.py index 2d7fb4f9a7..568661be00 100644 --- a/seahub/django_cas_ng/signals.py +++ b/seahub/django_cas_ng/signals.py @@ -1,10 +1,8 @@ from django import dispatch -cas_user_authenticated = dispatch.Signal( - providing_args=['user', 'created', 'attributes', 'ticket', 'service', 'request'], +cas_user_authenticated = dispatch.Signal(, ) -cas_user_logout = dispatch.Signal( - providing_args=['user', 'session', 'ticket'], +cas_user_logout = dispatch.Signal(, ) diff --git a/seahub/django_cas_ng/utils.py b/seahub/django_cas_ng/utils.py index ad8c568563..45d9e188b0 100644 --- a/seahub/django_cas_ng/utils.py +++ b/seahub/django_cas_ng/utils.py @@ -26,7 +26,7 @@ def get_redirect_url(request): if django_settings.CAS_IGNORE_REFERER: next_ = redirect_url else: - next_ = request.META.get('HTTP_REFERER', redirect_url) + next_ = request.headers.get('referer', redirect_url) prefix = urllib_parse.urlunparse( (get_protocol(request), request.get_host(), '', '', '', ''), ) @@ -65,7 +65,7 @@ def get_cas_client(service_url=None, request=None): server_url = django_settings.CAS_SERVER_URL if server_url and request and server_url.startswith('/'): scheme = request.META.get("X-Forwarded-Proto", request.scheme) - server_url = scheme + "://" + request.META['HTTP_HOST'] + server_url + server_url = scheme + "://" + request.headers['host'] + server_url # assert server_url.startswith('http'), "settings.CAS_SERVER_URL invalid" return CASClient( diff --git a/seahub/drafts/signals.py b/seahub/drafts/signals.py index e994908835..6704f93cb4 100644 --- a/seahub/drafts/signals.py +++ b/seahub/drafts/signals.py @@ -1,6 +1,6 @@ # Copyright (c) 2012-2018 Seafile Ltd. import django.dispatch -comment_draft_successful = django.dispatch.Signal(providing_args=["draft", "comment", "author"]) -request_reviewer_successful = django.dispatch.Signal(providing_args=["from_user", "to_user", "draft_id"]) -update_review_successful = django.dispatch.Signal(providing_args=["from_user", "to_user", "review_id", "status"]) +comment_draft_successful = django.dispatch.Signal() +request_reviewer_successful = django.dispatch.Signal() +update_review_successful = django.dispatch.Signal() diff --git a/seahub/drafts/urls.py b/seahub/drafts/urls.py index e9c7f20f52..9a067eaf87 100644 --- a/seahub/drafts/urls.py +++ b/seahub/drafts/urls.py @@ -1,9 +1,9 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url +from django.urls import path from .views import draft, drafts urlpatterns = [ - url(r'^$', drafts, name='drafts'), - url(r'^(?P\d+)/$', draft, name='draft'), + path('', drafts, name='drafts'), + path('/', draft, name='draft'), ] diff --git a/seahub/drafts/views.py b/seahub/drafts/views.py index 92afc96493..85b06fe1f5 100644 --- a/seahub/drafts/views.py +++ b/seahub/drafts/views.py @@ -3,7 +3,7 @@ import os import posixpath from django.shortcuts import render, get_object_or_404 -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api from seahub.auth.decorators import login_required diff --git a/seahub/forms.py b/seahub/forms.py index fcad2f9922..bf4115b8f8 100644 --- a/seahub/forms.py +++ b/seahub/forms.py @@ -2,7 +2,7 @@ # encoding: utf-8 from django.conf import settings from django import forms -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pysearpc import SearpcError diff --git a/seahub/group/error_msg.py b/seahub/group/error_msg.py index 155114fc12..70b5d5db77 100644 --- a/seahub/group/error_msg.py +++ b/seahub/group/error_msg.py @@ -2,7 +2,7 @@ """ This file contains error messages from ccnet or seafile that will be translated. """ -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ # create_group rpc msg = _("The group has already created") diff --git a/seahub/group/forms.py b/seahub/group/forms.py index f3ae0f87ad..9dbb175dd5 100644 --- a/seahub/group/forms.py +++ b/seahub/group/forms.py @@ -2,7 +2,7 @@ # encoding: utf-8 from django import forms from django.conf import settings -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from seahub.utils import is_valid_dirent_name from seahub.group.utils import validate_group_name diff --git a/seahub/group/signals.py b/seahub/group/signals.py index 08a59a373e..e5b09a750f 100644 --- a/seahub/group/signals.py +++ b/seahub/group/signals.py @@ -1,5 +1,5 @@ # Copyright (c) 2012-2016 Seafile Ltd. -import django.dispatch +from django.dispatch import Signal -group_join_request = django.dispatch.Signal(providing_args=["staffs", "username", "group", "join_reqeust_msg"]) -add_user_to_group = django.dispatch.Signal(providing_args=["group_staff", "group_id", "added_user"]) +group_join_request = Signal() +add_user_to_group = Signal() diff --git a/seahub/group/urls.py b/seahub/group/urls.py index 13115d2473..249558dfbe 100644 --- a/seahub/group/urls.py +++ b/seahub/group/urls.py @@ -1,8 +1,8 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url +from django.urls import path from .views import group_remove urlpatterns = [ - url(r'^(?P\d+)/remove/$', group_remove, name='group_remove'), + path('/remove/', group_remove, name='group_remove'), ] diff --git a/seahub/group/views.py b/seahub/group/views.py index 4462b86e46..f644bb259d 100644 --- a/seahub/group/views.py +++ b/seahub/group/views.py @@ -7,8 +7,8 @@ from django.urls import reverse from django.http import HttpResponseRedirect from django.shortcuts import render -from django.utils.http import urlquote -from django.utils.translation import ugettext as _ +from urllib.parse import quote +from django.utils.translation import gettext as _ from seahub.auth.decorators import login_required import seaserv @@ -84,7 +84,7 @@ def group_check(func): if not request.user.is_authenticated: if not group.is_pub: login_url = settings.LOGIN_URL - path = urlquote(request.get_full_path()) + path = quote(request.get_full_path()) tup = login_url, REDIRECT_FIELD_NAME, path return HttpResponseRedirect('%s?%s=%s' % tup) else: @@ -117,7 +117,7 @@ def group_remove(request, group_id): operation. """ # Request header may missing HTTP_REFERER, we need to handle that case. - next_page = request.META.get('HTTP_REFERER', SITE_ROOT) + next_page = request.headers.get('referer', SITE_ROOT) try: group_id_int = int(group_id) diff --git a/seahub/help/urls.py b/seahub/help/urls.py index c8916ccf42..c10819f47e 100644 --- a/seahub/help/urls.py +++ b/seahub/help/urls.py @@ -1,40 +1,40 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url, include +from django.urls import path, re_path from django.views.generic import TemplateView urlpatterns = [ - url(r'^$', TemplateView.as_view(template_name="help/introduction.html")), - url(r'^introduction/$', TemplateView.as_view(template_name="help/introduction.html")), + path('', TemplateView.as_view(template_name="help/introduction.html")), + path('introduction/', TemplateView.as_view(template_name="help/introduction.html")), - url(r'^libraries_managing/$', TemplateView.as_view(template_name="help/libraries_managing.html")), - url(r'^restoring_deleted_files/$', TemplateView.as_view(template_name="help/restoring_deleted_files.html")), - url(r'^finding_older_version_files/$', TemplateView.as_view(template_name="help/finding_older_version_files.html")), - url(r'^library_history_and_snapshots/$', TemplateView.as_view(template_name="help/library_history_and_snapshots.html")), - url(r'^setting_library_history/$', TemplateView.as_view(template_name="help/setting_library_history.html")), - url(r'^deleting_a_library/$', TemplateView.as_view(template_name="help/deleting_a_library.html")), - url(r'^viewing_files_within_web_app/$', TemplateView.as_view(template_name="help/viewing_files_within_web_app.html")), - url(r'^full_text_file_search/$', TemplateView.as_view(template_name="help/full_text_file_search.html")), + path('libraries_managing/', TemplateView.as_view(template_name="help/libraries_managing.html")), + path('restoring_deleted_files/', TemplateView.as_view(template_name="help/restoring_deleted_files.html")), + path('finding_older_version_files/', TemplateView.as_view(template_name="help/finding_older_version_files.html")), + path('library_history_and_snapshots/', TemplateView.as_view(template_name="help/library_history_and_snapshots.html")), + path('setting_library_history/', TemplateView.as_view(template_name="help/setting_library_history.html")), + path('deleting_a_library/', TemplateView.as_view(template_name="help/deleting_a_library.html")), + path('viewing_files_within_web_app/', TemplateView.as_view(template_name="help/viewing_files_within_web_app.html")), + path('full_text_file_search/', TemplateView.as_view(template_name="help/full_text_file_search.html")), - url(r'^sharing_files_and_folders/$', TemplateView.as_view(template_name="help/sharing_files_and_folders.html")), - url(r'^groups_managing/$', TemplateView.as_view(template_name="help/groups_managing.html")), - url(r'^file_locking/$', TemplateView.as_view(template_name="help/file_locking.html")), - url(r'^folder_permission/$', TemplateView.as_view(template_name="help/folder_permission.html")), - url(r'^departments/$', TemplateView.as_view(template_name="help/departments.html")), + path('sharing_files_and_folders/', TemplateView.as_view(template_name="help/sharing_files_and_folders.html")), + path('groups_managing/', TemplateView.as_view(template_name="help/groups_managing.html")), + path('file_locking/', TemplateView.as_view(template_name="help/file_locking.html")), + path('folder_permission/', TemplateView.as_view(template_name="help/folder_permission.html")), + path('departments/', TemplateView.as_view(template_name="help/departments.html")), - url(r'^manage_library_as_wiki/$', TemplateView.as_view(template_name="help/manage_library_as_wiki.html") ), + path('manage_library_as_wiki/', TemplateView.as_view(template_name="help/manage_library_as_wiki.html") ), - url(r'^install_sync/$', TemplateView.as_view(template_name="help/install_sync.html") ), - url(r'^syncing_existing_folders/$', TemplateView.as_view(template_name="help/syncing_existing_folders.html") ), - url(r'^selective_sync/$', TemplateView.as_view(template_name="help/selective_sync.html") ), - url(r'^read-only_syncing/$', TemplateView.as_view(template_name="help/read-only_syncing.html") ), - url(r'^unsync_resync/$', TemplateView.as_view(template_name="help/unsync_resync.html") ), - url(r'^sync_interval/$', TemplateView.as_view(template_name="help/sync_interval.html") ), - url(r'^desktop_proxy/$', TemplateView.as_view(template_name="help/desktop_proxy.html") ), - url(r'^conflicts/$', TemplateView.as_view(template_name="help/conflicts.html") ), - url(r'^ignore/$', TemplateView.as_view(template_name="help/ignore.html") ), + path('install_sync/', TemplateView.as_view(template_name="help/install_sync.html") ), + path('syncing_existing_folders/', TemplateView.as_view(template_name="help/syncing_existing_folders.html") ), + path('selective_sync/', TemplateView.as_view(template_name="help/selective_sync.html") ), + path('read-only_syncing/', TemplateView.as_view(template_name="help/read-only_syncing.html") ), + path('unsync_resync/', TemplateView.as_view(template_name="help/unsync_resync.html") ), + path('sync_interval/', TemplateView.as_view(template_name="help/sync_interval.html") ), + path('desktop_proxy/', TemplateView.as_view(template_name="help/desktop_proxy.html") ), + path('conflicts/', TemplateView.as_view(template_name="help/conflicts.html") ), + path('ignore/', TemplateView.as_view(template_name="help/ignore.html") ), - url(r'^using_drive_client/$', TemplateView.as_view(template_name="help/using_drive_client.html") ), - url(r'^drive_client_2.0_for_windows_10/$', TemplateView.as_view(template_name="help/drive_client_2.0_for_windows_10.html") ), + path('using_drive_client/', TemplateView.as_view(template_name="help/using_drive_client.html") ), + re_path(r'^drive_client_2.0_for_windows_10/$', TemplateView.as_view(template_name="help/drive_client_2.0_for_windows_10.html") ), - url(r'^encrypted_libraries/$', TemplateView.as_view(template_name="help/encrypted_libraries.html") ), + path('encrypted_libraries/', TemplateView.as_view(template_name="help/encrypted_libraries.html") ), ] diff --git a/seahub/institutions/urls.py b/seahub/institutions/urls.py index 0f7072ed11..7c295dd0bc 100644 --- a/seahub/institutions/urls.py +++ b/seahub/institutions/urls.py @@ -1,15 +1,15 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url +from django.urls import path from .views import (info, useradmin, user_info, user_remove, useradmin_search, user_toggle_status, user_set_quota) urlpatterns = [ - url('^info/$', info, name="info"), - url('^useradmin/$', useradmin, name="useradmin"), - url(r'^useradmin/info/(?P[^/]+)/$', user_info, name='user_info'), - url(r'^useradmin/remove/(?P[^/]+)/$', user_remove, name='user_remove'), - url('^useradmin/search/$', useradmin_search, name="useradmin_search"), - url(r'^useradmin/set_quota/(?P[^/]+)/$', user_set_quota, name='user_set_quota'), - url(r'^useradmin/toggle_status/(?P[^/]+)/$', user_toggle_status, name='user_toggle_status'), + path('info/', info, name="info"), + path('useradmin/', useradmin, name="useradmin"), + path('useradmin/info//', user_info, name='user_info'), + path('useradmin/remove//', user_remove, name='user_remove'), + path('useradmin/search/', useradmin_search, name="useradmin_search"), + path('useradmin/set_quota//', user_set_quota, name='user_set_quota'), + path('useradmin/toggle_status//', user_toggle_status, name='user_toggle_status'), ] diff --git a/seahub/institutions/views.py b/seahub/institutions/views.py index 36d8775739..7389215b0e 100644 --- a/seahub/institutions/views.py +++ b/seahub/institutions/views.py @@ -7,7 +7,7 @@ from django.contrib import messages from django.http import HttpResponseRedirect, HttpResponse from django.shortcuts import render -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ import seaserv from seaserv import seafile_api, ccnet_api from pysearpc import SearpcError @@ -200,7 +200,7 @@ def user_info(request, email): def user_remove(request, email): """Remove a institution user. """ - referer = request.META.get('HTTP_REFERER', None) + referer = request.headers.get('referer', None) next_page = reverse('institutions:useradmin') if referer is None else referer try: diff --git a/seahub/invitations/models.py b/seahub/invitations/models.py index 0783d247b5..7d5c295ab3 100644 --- a/seahub/invitations/models.py +++ b/seahub/invitations/models.py @@ -3,7 +3,7 @@ from datetime import timedelta from django.db import models from django.utils import timezone -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.base.fields import LowerCaseCharField from seahub.invitations.settings import INVITATIONS_TOKEN_AGE diff --git a/seahub/invitations/signals.py b/seahub/invitations/signals.py index 5060493ca6..04161eac1b 100644 --- a/seahub/invitations/signals.py +++ b/seahub/invitations/signals.py @@ -1,5 +1,4 @@ # Copyright (c) 2012-2016 Seafile Ltd. import django.dispatch -accept_guest_invitation_successful = django.dispatch.Signal( - providing_args=["invitation_obj"]) +accept_guest_invitation_successful = django.dispatch.Signal() diff --git a/seahub/invitations/urls.py b/seahub/invitations/urls.py index c023a3c9b3..bf52f1229b 100644 --- a/seahub/invitations/urls.py +++ b/seahub/invitations/urls.py @@ -1,8 +1,8 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url +from django.urls import re_path from .views import token_view urlpatterns = [ - url(r'^token/(?P[a-f0-9]{32})/$', token_view, name='token_view') + re_path(r'^token/(?P[a-f0-9]{32})/$', token_view, name='token_view') ] diff --git a/seahub/invitations/views.py b/seahub/invitations/views.py index 91f1389298..ae487f7ab2 100644 --- a/seahub/invitations/views.py +++ b/seahub/invitations/views.py @@ -5,7 +5,7 @@ from django.contrib import messages from django.http import HttpResponseRedirect, Http404 from django.shortcuts import get_object_or_404, render -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api from seahub.auth import login as auth_login, authenticate @@ -43,7 +43,7 @@ def token_view(request, token): if request.method == 'POST': passwd = request.POST.get('password', '') if not passwd: - return HttpResponseRedirect(request.META.get('HTTP_REFERER')) + return HttpResponseRedirect(request.headers.get('referer')) try: user = User.objects.get(email=i.accepter) diff --git a/seahub/notifications/management/commands/notify_admins_on_virus.py b/seahub/notifications/management/commands/notify_admins_on_virus.py index 8602347860..2de33f208c 100644 --- a/seahub/notifications/management/commands/notify_admins_on_virus.py +++ b/seahub/notifications/management/commands/notify_admins_on_virus.py @@ -7,7 +7,7 @@ from django.conf import settings as dj_settings from django.core.management.base import BaseCommand from django.urls import reverse from django.utils import translation -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ import seaserv from seaserv import seafile_api diff --git a/seahub/notifications/management/commands/send_dingtalk_notifications.py b/seahub/notifications/management/commands/send_dingtalk_notifications.py index b230d3e466..1ad5f8b79b 100644 --- a/seahub/notifications/management/commands/send_dingtalk_notifications.py +++ b/seahub/notifications/management/commands/send_dingtalk_notifications.py @@ -9,7 +9,7 @@ import json from django.core.management.base import BaseCommand from django.urls import reverse from django.utils import translation -from django.utils.translation import ungettext +from django.utils.translation import ngettext from seahub.base.models import CommandsLastCheck from seahub.notifications.models import UserNotification @@ -173,7 +173,7 @@ class Command(BaseCommand, CommandLogMixin): if count == 0: continue - title = ungettext( + title = ngettext( "\n" "You've got 1 new notice on %(site_name)s:\n", "\n" diff --git a/seahub/notifications/management/commands/send_file_updates.py b/seahub/notifications/management/commands/send_file_updates.py index 2e24789532..d13171afef 100644 --- a/seahub/notifications/management/commands/send_file_updates.py +++ b/seahub/notifications/management/commands/send_file_updates.py @@ -9,7 +9,7 @@ from django.core.management.base import BaseCommand from django.urls import reverse from django.utils.html import escape as e from django.utils import translation -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.avatar.templatetags.avatar_tags import avatar from seahub.avatar.util import get_default_avatar_url diff --git a/seahub/notifications/management/commands/send_notices.py b/seahub/notifications/management/commands/send_notices.py index 919e79c9d9..6478aacd6c 100644 --- a/seahub/notifications/management/commands/send_notices.py +++ b/seahub/notifications/management/commands/send_notices.py @@ -10,7 +10,7 @@ from django.core.management.base import BaseCommand from django.urls import reverse from django.utils.html import escape from django.utils import translation -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api, ccnet_api from seahub.notifications.models import UserNotification diff --git a/seahub/notifications/management/commands/send_notices_to_social_account.py b/seahub/notifications/management/commands/send_notices_to_social_account.py index 9f013d3977..cf12897fb9 100644 --- a/seahub/notifications/management/commands/send_notices_to_social_account.py +++ b/seahub/notifications/management/commands/send_notices_to_social_account.py @@ -9,7 +9,7 @@ import requests from django.core.management.base import BaseCommand from django.urls import reverse from django.utils import translation -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.base.models import CommandsLastCheck from seahub.notifications.models import UserNotification diff --git a/seahub/notifications/models.py b/seahub/notifications/models.py index 5cc0f826ce..5c57279071 100644 --- a/seahub/notifications/models.py +++ b/seahub/notifications/models.py @@ -10,7 +10,7 @@ from django.db import models from django.conf import settings from django.forms import ModelForm, Textarea from django.utils.html import escape -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.core.cache import cache from django.template.loader import render_to_string diff --git a/seahub/notifications/urls.py b/seahub/notifications/urls.py index a120def7d5..d477962722 100644 --- a/seahub/notifications/urls.py +++ b/seahub/notifications/urls.py @@ -1,8 +1,8 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url +from django.urls import path from .views import * urlpatterns = [ ########## user notifications - url(r'^list/$', user_notification_list, name='user_notification_list'), + path('list/', user_notification_list, name='user_notification_list'), ] diff --git a/seahub/notifications/views.py b/seahub/notifications/views.py index d1b3a4a485..1b841db2e2 100644 --- a/seahub/notifications/views.py +++ b/seahub/notifications/views.py @@ -8,7 +8,7 @@ from django.contrib import messages from django.http import HttpResponseRedirect, Http404, HttpResponse from django.shortcuts import render from django.template.loader import render_to_string -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.auth.decorators import login_required, login_required_ajax from seahub.notifications.models import Notification, NotificationForm, \ diff --git a/seahub/oauth/urls.py b/seahub/oauth/urls.py index 4db9bde360..89a701d17c 100644 --- a/seahub/oauth/urls.py +++ b/seahub/oauth/urls.py @@ -1,9 +1,9 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url +from django.urls import path from seahub.oauth.views import oauth_login, oauth_callback urlpatterns = [ - url(r'login/$', oauth_login, name='oauth_login'), - url(r'callback/$', oauth_callback, name='oauth_callback'), + path('login/', oauth_login, name='oauth_login'), + path('callback/', oauth_callback, name='oauth_callback'), ] diff --git a/seahub/oauth/views.py b/seahub/oauth/views.py index fb1f59d02a..37fa72a3c7 100644 --- a/seahub/oauth/views.py +++ b/seahub/oauth/views.py @@ -4,7 +4,7 @@ import os import sys import logging from django.http import HttpResponseRedirect -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api, ccnet_api diff --git a/seahub/onlyoffice/utils.py b/seahub/onlyoffice/utils.py index e934df1c30..0137257191 100644 --- a/seahub/onlyoffice/utils.py +++ b/seahub/onlyoffice/utils.py @@ -156,7 +156,7 @@ def get_onlyoffice_dict(request, username, repo_id, file_path, file_id='', 'username': username, 'onlyoffice_force_save': ONLYOFFICE_FORCE_SAVE, 'enable_watermark': ENABLE_WATERMARK, - 'request_from_onlyoffice_desktop_editor': ONLYOFFICE_DESKTOP_EDITOR_HTTP_USER_AGENT in request.META.get('HTTP_USER_AGENT', ''), + 'request_from_onlyoffice_desktop_editor': ONLYOFFICE_DESKTOP_EDITOR_HTTP_USER_AGENT in request.headers.get('user-agent', ''), } if ONLYOFFICE_JWT_SECRET: diff --git a/seahub/options/urls.py b/seahub/options/urls.py index ca4a395fbe..bcdc6a30b2 100644 --- a/seahub/options/urls.py +++ b/seahub/options/urls.py @@ -1,9 +1,9 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url +from django.urls import path from .views import * urlpatterns = [ - url(r'^save/$', save_options, name='options_save'), - url(r'^enable_sub_lib/$', sub_lib_enable_set, name='sub_lib_enable_set'), + path('save/', save_options, name='options_save'), + path('enable_sub_lib/', sub_lib_enable_set, name='sub_lib_enable_set'), ] diff --git a/seahub/options/views.py b/seahub/options/views.py index d6fe18f74a..4835056aff 100644 --- a/seahub/options/views.py +++ b/seahub/options/views.py @@ -4,7 +4,7 @@ from django.http import HttpResponse, HttpResponseBadRequest, \ HttpResponseRedirect, Http404 from django.views.decorators.http import require_POST from django.contrib import messages -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.auth.decorators import login_required from seahub.options.models import UserOptions @@ -25,7 +25,7 @@ def save_options(request): else: UserOptions.objects.disable_server_crypto(username) - next_page = request.META.get('HTTP_REFERER', None) + next_page = request.headers.get('referer', None) if next_page is None: next_page = SITE_ROOT @@ -47,7 +47,7 @@ def sub_lib_enable_set(request): else: UserOptions.objects.disable_sub_lib(username) - next_page = request.META.get('HTTP_REFERER', None) + next_page = request.headers.get('referer', None) if next_page is None: next_page = SITE_ROOT diff --git a/seahub/organizations/api/admin/info.py b/seahub/organizations/api/admin/info.py index ee378adfd7..90b59b224b 100644 --- a/seahub/organizations/api/admin/info.py +++ b/seahub/organizations/api/admin/info.py @@ -6,7 +6,7 @@ from rest_framework.views import APIView from rest_framework.response import Response from rest_framework.authentication import SessionAuthentication -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import ccnet_api, seafile_api diff --git a/seahub/organizations/api/admin/logo.py b/seahub/organizations/api/admin/logo.py index 752500d4ca..5ba52c2a5f 100644 --- a/seahub/organizations/api/admin/logo.py +++ b/seahub/organizations/api/admin/logo.py @@ -6,7 +6,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.template.defaultfilters import filesizeformat from seahub.api2.permissions import IsProVersion, IsOrgAdminUser diff --git a/seahub/organizations/api/admin/statistics.py b/seahub/organizations/api/admin/statistics.py index ff8c14c1ac..7afea34d84 100644 --- a/seahub/organizations/api/admin/statistics.py +++ b/seahub/organizations/api/admin/statistics.py @@ -8,7 +8,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status from django.utils import timezone -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.http import HttpResponse from seaserv import ccnet_api diff --git a/seahub/organizations/api/admin/user_repos.py b/seahub/organizations/api/admin/user_repos.py index 133b7e4e62..4d66a87c98 100644 --- a/seahub/organizations/api/admin/user_repos.py +++ b/seahub/organizations/api/admin/user_repos.py @@ -5,7 +5,7 @@ from rest_framework import status from rest_framework.views import APIView from rest_framework.response import Response from rest_framework.authentication import SessionAuthentication -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import ccnet_api, seafile_api diff --git a/seahub/organizations/api/admin/users.py b/seahub/organizations/api/admin/users.py index ec872864da..c08efd1e34 100644 --- a/seahub/organizations/api/admin/users.py +++ b/seahub/organizations/api/admin/users.py @@ -7,7 +7,7 @@ from rest_framework import status from rest_framework.views import APIView from rest_framework.response import Response from rest_framework.authentication import SessionAuthentication -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import ccnet_api, seafile_api diff --git a/seahub/organizations/api_urls.py b/seahub/organizations/api_urls.py index 909ec765cd..ab2e802af5 100644 --- a/seahub/organizations/api_urls.py +++ b/seahub/organizations/api_urls.py @@ -1,5 +1,5 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url +from django.urls import path, re_path from .api.address_book.groups import ( AdminAddressBookGroups, AdminAddressBookGroup @@ -31,70 +31,70 @@ from .api.admin.saml_config import OrgUploadIdPCertificateView, OrgSAMLConfigVie urlpatterns = [ - url(r'^(?P\d+)/admin/statistics/file-operations/$', + path('/admin/statistics/file-operations/', OrgFileOperationsView.as_view(), name='api-v2.1-org-admin-statistics-file-operations'), - url(r'^(?P\d+)/admin/statistics/total-storage/$', + path('/admin/statistics/total-storage/', OrgTotalStorageView.as_view(), name='api-v2.1-org-admin-statistics-total-storage'), - url(r'^(?P\d+)/admin/statistics/active-users/$', + path('/admin/statistics/active-users/', OrgActiveUsersView.as_view(), name='api-v2.1-org-admin-statistics-active-users'), - url(r'^(?P\d+)/admin/statistics/system-traffic/$', + path('/admin/statistics/system-traffic/', OrgSystemTrafficView.as_view(), name='api-v2.1-org-admin-statistics-system-traffic'), - url(r'^(?P\d+)/admin/statistics/user-traffic/$', + path('/admin/statistics/user-traffic/', OrgUserTrafficView.as_view(), name='api-v2.1-org-admin-statistics-user-traffic'), - url(r'^(?P\d+)/admin/statistics/user-traffic/excel/$', + path('/admin/statistics/user-traffic/excel/', OrgUserTrafficExcelView.as_view(), name='api-v2.1-org-admin-statistics-user-traffic-excel'), - url(r'^(?P\d+)/admin/statistics/user-storage/excel/$', + path('/admin/statistics/user-storage/excel/', OrgUserStorageExcelView.as_view(), name='api-v2.1-org-admin-statistics-user-storage-excel'), - url(r'^(?P\d+)/admin/saml-idp-certificate/$', + path('/admin/saml-idp-certificate/', OrgUploadIdPCertificateView.as_view(), name='api-v2.1-org-admin-saml-idp-certificate'), - url(r'^(?P\d+)/admin/saml-config/$', + path('/admin/saml-config/', OrgSAMLConfigView.as_view(), name='api-v2.1-org-admin-saml-config'), - url(r'^(?P\d+)/admin/url-prefix/$', + path('/admin/url-prefix/', OrgUrlPrefixView.as_view(), name='api-v2.1-org-admin-url-prefix'), - url(r'^(?P\d+)/admin/logo/$', OrgAdminLogo.as_view(), name='api-v2.1-org-admin-logo'), - url(r'^(?P\d+)/admin/devices/$', OrgAdminDevices.as_view(), name='api-v2.1-org-admin-devices'), - url(r'^(?P\d+)/admin/devices-errors/$', OrgAdminDevicesErrors.as_view(), name='api-v2.1-org-admin-devices-errors'), + path('/admin/logo/', OrgAdminLogo.as_view(), name='api-v2.1-org-admin-logo'), + path('/admin/devices/', OrgAdminDevices.as_view(), name='api-v2.1-org-admin-devices'), + path('/admin/devices-errors/', OrgAdminDevicesErrors.as_view(), name='api-v2.1-org-admin-devices-errors'), - url(r'^(?P\d+)/admin/address-book/groups/$', AdminAddressBookGroups.as_view(), name='api-admin-address-book-groups'), - url(r'^(?P\d+)/admin/address-book/groups/(?P\d+)/$', AdminAddressBookGroup.as_view(), name='api-admin-address-book-group'), + path('/admin/address-book/groups/', AdminAddressBookGroups.as_view(), name='api-admin-address-book-groups'), + path('/admin/address-book/groups//', AdminAddressBookGroup.as_view(), name='api-admin-address-book-group'), - url(r'^(?P\d+)/admin/groups/$', OrgAdminGroups.as_view(), name='api-v2.1-org-admin-groups'), - url(r'^(?P\d+)/admin/search-group/$', OrgAdminSearchGroup.as_view(), name='api-v2.1-org-admin-search-group'), - url(r'^(?P\d+)/admin/groups/(?P\d+)/$', OrgAdminGroup.as_view(), name='api-admin-group'), - url(r'^(?P\d+)/admin/groups/(?P\d+)/libraries/$', AdminGroupLibraries.as_view(), name='api-admin-group-libraries'), - url(r'^(?P\d+)/admin/groups/(?P\d+)/libraries/(?P[-0-9a-f]{36})/$', AdminGroupLibrary.as_view(), name='api-admin-group-library'), + path('/admin/groups/', OrgAdminGroups.as_view(), name='api-v2.1-org-admin-groups'), + path('/admin/search-group/', OrgAdminSearchGroup.as_view(), name='api-v2.1-org-admin-search-group'), + path('/admin/groups//', OrgAdminGroup.as_view(), name='api-admin-group'), + path('/admin/groups//libraries/', AdminGroupLibraries.as_view(), name='api-admin-group-libraries'), + re_path(r'^(?P\d+)/admin/groups/(?P\d+)/libraries/(?P[-0-9a-f]{36})/$', AdminGroupLibrary.as_view(), name='api-admin-group-library'), - url(r'^(?P\d+)/admin/groups/(?P\d+)/group-owned-libraries/$', AdminGroupOwnedLibraries.as_view(), name='api-admin-group-owned-libraries'), - url(r'^(?P\d+)/admin/groups/(?P\d+)/group-owned-libraries/(?P[-0-9a-f]{36})/$', AdminGroupOwnedLibrary.as_view(), name='api-admin-group-owned-library'), + path('/admin/groups//group-owned-libraries/', AdminGroupOwnedLibraries.as_view(), name='api-admin-group-owned-libraries'), + re_path(r'^(?P\d+)/admin/groups/(?P\d+)/group-owned-libraries/(?P[-0-9a-f]{36})/$', AdminGroupOwnedLibrary.as_view(), name='api-admin-group-owned-library'), - url(r'^(?P\d+)/admin/groups/(?P\d+)/members/$', AdminGroupMembers.as_view(), name='api-admin-group-members'), - url(r'^(?P\d+)/admin/groups/(?P\d+)/members/(?P[^/]+)/$', AdminGroupMember.as_view(), name='api-admin-group-member'), - url(r'^(?P\d+)/admin/users/$', OrgAdminUsers.as_view(), name='api-v2.1-org-admin-users'), - url(r'^(?P\d+)/admin/import-users/$', OrgAdminImportUsers.as_view(), name='api-v2.1-org-admin-import-users'), - url(r'^(?P\d+)/admin/search-user/$', OrgAdminSearchUser.as_view(), name='api-v2.1-org-admin-search-user'), - url(r'^(?P\d+)/admin/users/(?P[^/]+)/$', OrgAdminUser.as_view(), name='api-v2.1-org-admin-user'), - url(r'^(?P\d+)/admin/users/(?P[^/]+)/set-password/', OrgAdminUserSetPassword.as_view(), name='api-v2.1-org-admin-user-reset-password'), - url(r'^(?P\d+)/admin/users/(?P[^/]+)/repos/$', OrgAdminUserRepos.as_view(), name='api-v2.1-org-admin-user-repos'), - url(r'^(?P\d+)/admin/users/(?P[^/]+)/beshared-repos/$', OrgAdminUserBesharedRepos.as_view(), name='api-v2.1-org-admin-user-beshared-repos'), - url(r'^(?P\d+)/admin/repos/$', OrgAdminRepos.as_view(), name='api-v2.1-org-admin-repos'), - url(r'^(?P\d+)/admin/repos/(?P[-0-9a-f]{36})/$', OrgAdminRepo.as_view(), name='api-v2.1-org-admin-repo'), - url(r'^(?P\d+)/admin/web-settings/$', OrgAdminWebSettings.as_view(), name='api-v2.1-org-admin-web-settings'), - url(r'^admin/info/$', OrgAdminInfo.as_view(), name='api-v2.1-org-admin-info'), - url(r'^admin/links/$', OrgAdminLinks.as_view(), name='api-v2.1-org-admin-links'), - url(r'^admin/links/(?P[a-f0-9]+)/$', OrgAdminLink.as_view(), name='api-v2.1-org-admin-link'), - url(r'^admin/logs/file-access/$', OrgAdminLogsFileAccess.as_view(), name='api-v2.1-org-admin-logs-file-access'), - url(r'^admin/logs/file-update/$', OrgAdminLogsFileUpdate.as_view(), name='api-v2.1-org-admin-logs-file-update'), - url(r'^admin/logs/repo-permission/$', OrgAdminLogsPermAudit.as_view(), name='api-v2.1-org-admin-logs-repo-permission'), + path('/admin/groups//members/', AdminGroupMembers.as_view(), name='api-admin-group-members'), + path('/admin/groups//members//', AdminGroupMember.as_view(), name='api-admin-group-member'), + path('/admin/users/', OrgAdminUsers.as_view(), name='api-v2.1-org-admin-users'), + path('/admin/import-users/', OrgAdminImportUsers.as_view(), name='api-v2.1-org-admin-import-users'), + path('/admin/search-user/', OrgAdminSearchUser.as_view(), name='api-v2.1-org-admin-search-user'), + path('/admin/users//', OrgAdminUser.as_view(), name='api-v2.1-org-admin-user'), + re_path(r'^(?P\d+)/admin/users/(?P[^/]+)/set-password/', OrgAdminUserSetPassword.as_view(), name='api-v2.1-org-admin-user-reset-password'), + path('/admin/users//repos/', OrgAdminUserRepos.as_view(), name='api-v2.1-org-admin-user-repos'), + path('/admin/users//beshared-repos/', OrgAdminUserBesharedRepos.as_view(), name='api-v2.1-org-admin-user-beshared-repos'), + path('/admin/repos/', OrgAdminRepos.as_view(), name='api-v2.1-org-admin-repos'), + re_path(r'^(?P\d+)/admin/repos/(?P[-0-9a-f]{36})/$', OrgAdminRepo.as_view(), name='api-v2.1-org-admin-repo'), + path('/admin/web-settings/', OrgAdminWebSettings.as_view(), name='api-v2.1-org-admin-web-settings'), + path('admin/info/', OrgAdminInfo.as_view(), name='api-v2.1-org-admin-info'), + path('admin/links/', OrgAdminLinks.as_view(), name='api-v2.1-org-admin-links'), + re_path(r'^admin/links/(?P[a-f0-9]+)/$', OrgAdminLink.as_view(), name='api-v2.1-org-admin-link'), + path('admin/logs/file-access/', OrgAdminLogsFileAccess.as_view(), name='api-v2.1-org-admin-logs-file-access'), + path('admin/logs/file-update/', OrgAdminLogsFileUpdate.as_view(), name='api-v2.1-org-admin-logs-file-update'), + path('admin/logs/repo-permission/', OrgAdminLogsPermAudit.as_view(), name='api-v2.1-org-admin-logs-repo-permission'), ] diff --git a/seahub/organizations/forms.py b/seahub/organizations/forms.py index 2f5f2b664b..319bc1b556 100644 --- a/seahub/organizations/forms.py +++ b/seahub/organizations/forms.py @@ -6,7 +6,7 @@ Forms and validation code for organization user registration. import re from django import forms -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ import seaserv from seahub.base.accounts import User diff --git a/seahub/organizations/middleware.py b/seahub/organizations/middleware.py index 45a115b4fa..6611f20b54 100644 --- a/seahub/organizations/middleware.py +++ b/seahub/organizations/middleware.py @@ -38,7 +38,7 @@ class RedirectMiddleware(MiddlewareMixin): return None path = request.get_full_path() - domain = request.META.get('HTTP_HOST') or request.META.get('SERVER_NAME') + domain = request.headers.get('host') or request.META.get('SERVER_NAME') if request.user.is_anonymous: return None diff --git a/seahub/organizations/signals.py b/seahub/organizations/signals.py index 2192bbed20..e07618bbfa 100644 --- a/seahub/organizations/signals.py +++ b/seahub/organizations/signals.py @@ -2,4 +2,4 @@ from django.dispatch import Signal # A new org is created -org_created = Signal(providing_args=['org']) +org_created = Signal() diff --git a/seahub/organizations/urls.py b/seahub/organizations/urls.py index 1aed46dc07..c663626022 100644 --- a/seahub/organizations/urls.py +++ b/seahub/organizations/urls.py @@ -1,45 +1,45 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url +from django.urls import path, re_path from .views import * urlpatterns = [ - url(r'^add/$', org_add, name='org_add'), - url(r'^register/$', org_register, name='org_register'), + path('add/', org_add, name='org_add'), + path('register/', org_register, name='org_register'), - url(r'^statistics-admin/file/$', react_fake_view, name='org_statistics_admin_file'), - url(r'^statistics-admin/total-storage/$', react_fake_view, name='org_statistics_admin_total_storage'), - url(r'^statistics-admin/active-users/$', react_fake_view, name='org_statistics_admin_active_users'), - url(r'^statistics-admin/traffic/$', react_fake_view, name='org_statistics_admin_traffic'), + path('statistics-admin/file/', react_fake_view, name='org_statistics_admin_file'), + path('statistics-admin/total-storage/', react_fake_view, name='org_statistics_admin_total_storage'), + path('statistics-admin/active-users/', react_fake_view, name='org_statistics_admin_active_users'), + path('statistics-admin/traffic/', react_fake_view, name='org_statistics_admin_traffic'), - url(r'^deviceadmin/desktop-devices/$', react_fake_view, name='org_device_admin'), - url(r'^deviceadmin/mobile-devices/$', react_fake_view, name='org_device_admin_mobile_devices'), - url(r'^deviceadmin/devices-errors/$', react_fake_view, name='org_device_admin_devices_errors'), + path('deviceadmin/desktop-devices/', react_fake_view, name='org_device_admin'), + path('deviceadmin/mobile-devices/', react_fake_view, name='org_device_admin_mobile_devices'), + path('deviceadmin/devices-errors/', react_fake_view, name='org_device_admin_devices_errors'), - url(r'^web-settings/$', react_fake_view, name='org_web_settings'), - url(r'^useradmin/$', react_fake_view, name='org_user_admin'), - url(r'^useradmin/search-users/$', react_fake_view, name='org_user_admin_search_users'), - url(r'^useradmin/admins/$', react_fake_view, name='org_useradmin_admins'), - url(r'^useradmin/info/(?P[^/]+)/$', react_fake_view, name='org_user_info'), - url(r'^useradmin/info/(?P[^/]+)/repos/$', react_fake_view, name='org_user_repos'), - url(r'^useradmin/info/(?P[^/]+)/shared-repos/$', react_fake_view, name='org_user_shared_repos'), - url(r'^repoadmin/$', react_fake_view, name='org_repo_admin'), + path('web-settings/', react_fake_view, name='org_web_settings'), + path('useradmin/', react_fake_view, name='org_user_admin'), + path('useradmin/search-users/', react_fake_view, name='org_user_admin_search_users'), + path('useradmin/admins/', react_fake_view, name='org_useradmin_admins'), + path('useradmin/info//', react_fake_view, name='org_user_info'), + path('useradmin/info//repos/', react_fake_view, name='org_user_repos'), + path('useradmin/info//shared-repos/', react_fake_view, name='org_user_shared_repos'), + path('repoadmin/', react_fake_view, name='org_repo_admin'), - url(r'^groupadmin/$', react_fake_view, name='org_group_admin'), - url(r'^groupadmin/search-groups/$', react_fake_view, name='org_group_admin_search_groups'), - url(r'^groupadmin/(?P\d+)/$', react_fake_view, name='org_admin_group_info'), - url(r'^groupadmin/(?P\d+)/repos/$', react_fake_view, name='org_admin_group_repos'), - url(r'^groupadmin/(?P\d+)/members/$', react_fake_view, name='org_admin_group_members'), - url(r'^publinkadmin/$', react_fake_view, name='org_publink_admin'), - url(r'^logadmin/$', react_fake_view, name='org_log_file_audit'), - url(r'^logadmin/file-update/$', react_fake_view, name='org_log_file_update'), - url(r'^logadmin/perm-audit/$', react_fake_view, name='org_log_perm_audit'), + path('groupadmin/', react_fake_view, name='org_group_admin'), + path('groupadmin/search-groups/', react_fake_view, name='org_group_admin_search_groups'), + path('groupadmin//', react_fake_view, name='org_admin_group_info'), + path('groupadmin//repos/', react_fake_view, name='org_admin_group_repos'), + path('groupadmin//members/', react_fake_view, name='org_admin_group_members'), + path('publinkadmin/', react_fake_view, name='org_publink_admin'), + path('logadmin/', react_fake_view, name='org_log_file_audit'), + path('logadmin/file-update/', react_fake_view, name='org_log_file_update'), + path('logadmin/perm-audit/', react_fake_view, name='org_log_perm_audit'), - url(r'^info/$', react_fake_view, name='org_info'), - url(r'^settings/$', react_fake_view, name='org_settings'), - url(r'^departmentadmin/$', react_fake_view, name='org_department_admin'), - url(r'^departmentadmin/groups/(?P\d+)/', react_fake_view, name='org_department_admin'), - url(r'^associate/(?P.+)/$', org_associate, name='org_associate'), + path('info/', react_fake_view, name='org_info'), + path('settings/', react_fake_view, name='org_settings'), + path('departmentadmin/', react_fake_view, name='org_department_admin'), + re_path(r'^departmentadmin/groups/(?P\d+)/', react_fake_view, name='org_department_admin'), + path('associate//', org_associate, name='org_associate'), - url(r'^samlconfig/$', react_fake_view, name='saml_config'), + path('samlconfig/', react_fake_view, name='saml_config'), ] diff --git a/seahub/organizations/views.py b/seahub/organizations/views.py index ec67b93b55..3b3d93daa1 100644 --- a/seahub/organizations/views.py +++ b/seahub/organizations/views.py @@ -9,7 +9,7 @@ from django.conf import settings from django.contrib import messages from django.urls import reverse from django.core.cache import cache -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.http import HttpResponse, Http404, HttpResponseRedirect from django.shortcuts import render diff --git a/seahub/profile/forms.py b/seahub/profile/forms.py index ba44c5e066..a05bf90475 100644 --- a/seahub/profile/forms.py +++ b/seahub/profile/forms.py @@ -1,7 +1,7 @@ # Copyright (c) 2012-2016 Seafile Ltd. # encoding: utf-8 from django import forms -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from seahub.profile.models import Profile, DetailedProfile from seahub.settings import ENABLE_UPDATE_USER_INFO diff --git a/seahub/profile/urls.py b/seahub/profile/urls.py index faf950a011..08c4ea0cbf 100644 --- a/seahub/profile/urls.py +++ b/seahub/profile/urls.py @@ -1,17 +1,17 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url, include +from django.urls import include, path, re_path from .views import * urlpatterns = [ # url(r'^list_user/$', 'list_userids', name="list_userids"), - url(r'^$', edit_profile, name="edit_profile"), - url(r'^(?P[^/]+)/get/$', get_user_profile, name="get_user_profile"), - url(r'^delete/$', delete_user_account, name="delete_user_account"), - url(r'^default-repo/$', default_repo, name="default_repo"), - url(r'^two_factor_authentication/', include(('seahub.two_factor.urls', 'two_factor'), namespace='two_factor')), + path('', edit_profile, name="edit_profile"), + path('/get/', get_user_profile, name="get_user_profile"), + path('delete/', delete_user_account, name="delete_user_account"), + path('default-repo/', default_repo, name="default_repo"), + path('two_factor_authentication/', include(('seahub.two_factor.urls', 'two_factor'), namespace='two_factor')), ] # Move the catch-all pattern to the end. urlpatterns += [ - url(r'^(?P[^/]*)/$', user_profile, name="user_profile"), + re_path(r'^(?P[^/]*)/$', user_profile, name="user_profile"), ] diff --git a/seahub/profile/views.py b/seahub/profile/views.py index 77cfadf641..422cfddf20 100644 --- a/seahub/profile/views.py +++ b/seahub/profile/views.py @@ -6,7 +6,7 @@ from django.urls import reverse from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.shortcuts import render from django.contrib import messages -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ import seaserv from seaserv import seafile_api @@ -225,7 +225,7 @@ def get_user_profile(request, user): def delete_user_account(request): if not ENABLE_DELETE_ACCOUNT: messages.error(request, _('Permission denied.')) - next_page = request.META.get('HTTP_REFERER', settings.SITE_ROOT) + next_page = request.headers.get('referer', settings.SITE_ROOT) return HttpResponseRedirect(next_page) if request.method != 'POST': @@ -235,7 +235,7 @@ def delete_user_account(request): if username == 'demo@seafile.com': messages.error(request, _('Demo account can not be deleted.')) - next_page = request.META.get('HTTP_REFERER', settings.SITE_ROOT) + next_page = request.headers.get('referer', settings.SITE_ROOT) return HttpResponseRedirect(next_page) user = User.objects.get(email=username) @@ -256,7 +256,7 @@ def default_repo(request): raise Http404 repo_id = request.POST.get('dst_repo', '') - referer = request.META.get('HTTP_REFERER', None) + referer = request.headers.get('referer', None) next_page = settings.SITE_ROOT if referer is None else referer repo = seafile_api.get_repo(repo_id) diff --git a/seahub/repo_api_tokens/utils.py b/seahub/repo_api_tokens/utils.py index 613b67f825..09cffc543d 100644 --- a/seahub/repo_api_tokens/utils.py +++ b/seahub/repo_api_tokens/utils.py @@ -3,7 +3,7 @@ import os import logging import posixpath import stat -from django.utils.http import urlquote +from urllib.parse import quote from seaserv import seafile_api from seahub.base.models import UserStarredFiles @@ -214,7 +214,7 @@ def get_dir_file_info_list(username, request_type, repo_obj, parent_dir, str(thumbnail_size), file_obj_id) if os.path.exists(thumbnail_file_path): src = get_thumbnail_src(repo_id, thumbnail_size, file_path) - file_info['encoded_thumbnail_src'] = urlquote(src) + file_info['encoded_thumbnail_src'] = quote(src) file_info_list.append(file_info) diff --git a/seahub/seadoc/apis.py b/seahub/seadoc/apis.py index 87b28ddfe5..53776aa510 100644 --- a/seahub/seadoc/apis.py +++ b/seahub/seadoc/apis.py @@ -8,7 +8,7 @@ from rest_framework.views import APIView from rest_framework import status from rest_framework.authentication import SessionAuthentication from rest_framework.permissions import IsAuthenticated -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.http import HttpResponseRedirect, HttpResponse from seaserv import seafile_api, check_quota @@ -90,7 +90,7 @@ class SeadocUploadFile(APIView): def post(self, request, file_uuid): # jwt permission check - auth = request.META.get('HTTP_AUTHORIZATION', '').split() + auth = request.headers.get('authorization', '').split() if not is_valid_seadoc_access_token(auth, file_uuid): error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) @@ -140,7 +140,7 @@ class SeadocUploadLink(APIView): def get(self, request, file_uuid): # jwt permission check - auth = request.META.get('HTTP_AUTHORIZATION', '').split() + auth = request.headers.get('authorization', '').split() if not is_valid_seadoc_access_token(auth, file_uuid): error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) @@ -180,7 +180,7 @@ class SeadocDownloadLink(APIView): def get(self, request, file_uuid): # jwt permission check - auth = request.META.get('HTTP_AUTHORIZATION', '').split() + auth = request.headers.get('authorization', '').split() if not is_valid_seadoc_access_token(auth, file_uuid): error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) @@ -213,7 +213,7 @@ class SeadocUploadImage(APIView): """image path: /images/sdoc/${sdocUuid}/${filename} """ # jwt permission check - auth = request.META.get('HTTP_AUTHORIZATION', '').split() + auth = request.headers.get('authorization', '').split() is_valid, payload = is_valid_seadoc_access_token(auth, file_uuid, return_payload=True) if not is_valid: error_msg = 'Permission denied.' diff --git a/seahub/seadoc/urls.py b/seahub/seadoc/urls.py index 92ad2a052e..52cb416489 100644 --- a/seahub/seadoc/urls.py +++ b/seahub/seadoc/urls.py @@ -1,12 +1,12 @@ -from django.conf.urls import url +from django.urls import re_path from .apis import SeadocAccessToken, SeadocUploadLink, SeadocDownloadLink, SeadocUploadFile, \ SeadocUploadImage, SeadocDownloadImage urlpatterns = [ - url(r'^access-token/(?P[-0-9a-f]{36})/$', SeadocAccessToken.as_view(), name='seadoc_access_token'), - url(r'^upload-file/(?P[-0-9a-f]{36})/$', SeadocUploadFile.as_view(), name='seadoc_upload_file'), - url(r'^upload-link/(?P[-0-9a-f]{36})/$', SeadocUploadLink.as_view(), name='seadoc_upload_link'), - url(r'^download-link/(?P[-0-9a-f]{36})/$', SeadocDownloadLink.as_view(), name='seadoc_download_link'), - url(r'^upload-image/(?P[-0-9a-f]{36})/$', SeadocUploadImage.as_view(), name='seadoc_upload_image'), - url(r'^download-image/(?P[-0-9a-f]{36})/(?P.*)$', SeadocDownloadImage.as_view(), name='seadoc_download_image'), + re_path(r'^access-token/(?P[-0-9a-f]{36})/$', SeadocAccessToken.as_view(), name='seadoc_access_token'), + re_path(r'^upload-file/(?P[-0-9a-f]{36})/$', SeadocUploadFile.as_view(), name='seadoc_upload_file'), + re_path(r'^upload-link/(?P[-0-9a-f]{36})/$', SeadocUploadLink.as_view(), name='seadoc_upload_link'), + re_path(r'^download-link/(?P[-0-9a-f]{36})/$', SeadocDownloadLink.as_view(), name='seadoc_download_link'), + re_path(r'^upload-image/(?P[-0-9a-f]{36})/$', SeadocUploadImage.as_view(), name='seadoc_upload_image'), + re_path(r'^download-image/(?P[-0-9a-f]{36})/(?P.*)$', SeadocDownloadImage.as_view(), name='seadoc_download_image'), ] diff --git a/seahub/search/views.py b/seahub/search/views.py index a530ecac70..75338de19f 100644 --- a/seahub/search/views.py +++ b/seahub/search/views.py @@ -6,7 +6,7 @@ from django.urls import reverse from django.http import HttpResponseRedirect, Http404 from django.shortcuts import render -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seaserv import seafile_api, ccnet_api diff --git a/seahub/settings.py b/seahub/settings.py index 66a238af55..f646abcbd6 100644 --- a/seahub/settings.py +++ b/seahub/settings.py @@ -59,7 +59,6 @@ USE_I18N = True # If you set this to False, Django will not format dates, numbers and # calendars according to the current locale. -USE_L10N = True # If you set this to False, Django will not use timezone-aware datetimes. USE_TZ = False @@ -99,7 +98,12 @@ WEBPACK_LOADER = { } } -STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage' +DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage' +# STORAGES = { +# "staticfiles": { +# "BACKEND": 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage', +# }, +# } # StaticI18N config STATICI18N_ROOT = '%s/static/scripts' % PROJECT_ROOT @@ -980,3 +984,7 @@ if ENABLE_ADFS_LOGIN or ENABLE_MULTI_ADFS: # 'link': 'http://127.0.0.1:8000/shared-libs/', # }, # ] + +# settings.py + + diff --git a/seahub/share/decorators.py b/seahub/share/decorators.py index 38969f7e2b..08bec3542d 100644 --- a/seahub/share/decorators.py +++ b/seahub/share/decorators.py @@ -2,7 +2,7 @@ from django.core.cache import cache from django.conf import settings from django.shortcuts import render -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from seahub.share.models import FileShare, UploadLinkShare from seahub.utils import render_error diff --git a/seahub/share/forms.py b/seahub/share/forms.py index 53708ce7c7..2d39f811e4 100644 --- a/seahub/share/forms.py +++ b/seahub/share/forms.py @@ -1,6 +1,6 @@ # Copyright (c) 2012-2016 Seafile Ltd. from django import forms -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class RepoShareForm(forms.Form): """ diff --git a/seahub/share/models.py b/seahub/share/models.py index ce4af9a03a..1b65b5276c 100644 --- a/seahub/share/models.py +++ b/seahub/share/models.py @@ -11,7 +11,7 @@ from django.db import models from django.db.models import Q from django.dispatch import receiver from django.utils import timezone -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.contrib.auth.hashers import check_password from seahub.signals import repo_deleted diff --git a/seahub/share/signals.py b/seahub/share/signals.py index 02d424f09b..6aa9a3644e 100644 --- a/seahub/share/signals.py +++ b/seahub/share/signals.py @@ -1,5 +1,5 @@ # Copyright (c) 2012-2016 Seafile Ltd. -import django.dispatch +from django.dispatch import Signal -share_repo_to_user_successful = django.dispatch.Signal(providing_args=["from_user", "to_user", "repo", "path", "org_id"]) -share_repo_to_group_successful = django.dispatch.Signal(providing_args=["from_user", "group_id", "repo", "path", "org_id"]) +share_repo_to_user_successful = Signal() +share_repo_to_group_successful = Signal() diff --git a/seahub/share/urls.py b/seahub/share/urls.py index 6019a38a37..f06a2ce5ea 100644 --- a/seahub/share/urls.py +++ b/seahub/share/urls.py @@ -1,13 +1,13 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url +from django.urls import path from .views import * urlpatterns = [ - url(r'^link/send/$', send_shared_link, name='send_shared_link'), - url(r'^link/save/$', save_shared_link, name='save_shared_link'), - url(r'^link/export-excel/$', export_shared_link, name='export_shared_link'), - url(r'^upload_link/send/$', send_shared_upload_link, name='send_shared_upload_link'), - url(r'^ajax/private-share-dir/$', ajax_private_share_dir, name='ajax_private_share_dir'), - url(r'^ajax/get-link-audit-code/$', ajax_get_link_audit_code, name='ajax_get_link_audit_code'), + path('link/send/', send_shared_link, name='send_shared_link'), + path('link/save/', save_shared_link, name='save_shared_link'), + path('link/export-excel/', export_shared_link, name='export_shared_link'), + path('upload_link/send/', send_shared_upload_link, name='send_shared_upload_link'), + path('ajax/private-share-dir/', ajax_private_share_dir, name='ajax_private_share_dir'), + path('ajax/get-link-audit-code/', ajax_get_link_audit_code, name='ajax_get_link_audit_code'), ] diff --git a/seahub/share/views.py b/seahub/share/views.py index 82cad75e04..921d2ea0fa 100644 --- a/seahub/share/views.py +++ b/seahub/share/views.py @@ -7,7 +7,7 @@ import logging from django.core.cache import cache from django.http import HttpResponse, HttpResponseRedirect, Http404, \ HttpResponseBadRequest -from django.utils.translation import ugettext as _, activate +from django.utils.translation import gettext as _, activate from django.contrib import messages from django.utils.html import escape @@ -221,7 +221,7 @@ def save_shared_link(request): dst_repo_id = request.POST.get('dst_repo', '') dst_path = request.POST.get('dst_path', '') - next_page = request.META.get('HTTP_REFERER', None) + next_page = request.headers.get('referer', None) if not next_page: next_page = SITE_ROOT diff --git a/seahub/signals.py b/seahub/signals.py index 3a14f18f9f..318f831735 100644 --- a/seahub/signals.py +++ b/seahub/signals.py @@ -1,12 +1,12 @@ # Copyright (c) 2012-2016 Seafile Ltd. -import django.dispatch +from django.dispatch import Signal # Use org_id = -1 if it's not an org repo -repo_created = django.dispatch.Signal(providing_args=["org_id", "creator", "repo_id", "repo_name", "library_template"]) -repo_deleted = django.dispatch.Signal(providing_args=["org_id", "operator", "repo_owner", "repo_id", "repo_name"]) -repo_transfer = django.dispatch.Signal(providing_args=["org_id", "repo_owner", "to_user", "repo_id", "repo_name"]) -clean_up_repo_trash = django.dispatch.Signal(providing_args=["org_id", "operator", "repo_id", "repo_name", "repo_owner", "days"]) -repo_restored = django.dispatch.Signal(providing_args=["repo_id", "operator"]) -upload_file_successful = django.dispatch.Signal(providing_args=["repo_id", "file_path", "owner"]) -comment_file_successful = django.dispatch.Signal(providing_args=["repo", "file_path", "comment", "author", "notify_users"]) -institution_deleted = django.dispatch.Signal(providing_args=["inst_name"]) +repo_created = Signal() +repo_deleted = Signal() +repo_transfer = Signal() +clean_up_repo_trash = Signal() +repo_restored = Signal() +upload_file_successful = Signal() +comment_file_successful = Signal() +institution_deleted = Signal() diff --git a/seahub/sysadmin_extra/views.py b/seahub/sysadmin_extra/views.py index 5f45fc85e2..00e0c86a99 100644 --- a/seahub/sysadmin_extra/views.py +++ b/seahub/sysadmin_extra/views.py @@ -4,7 +4,7 @@ import logging from django.shortcuts import render -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.contrib import messages from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.core.exceptions import ValidationError @@ -31,7 +31,7 @@ logger = logging.getLogger(__name__) def sys_login_admin_export_excel(request): """ Export user login logs to excel. """ - next_page = request.META.get('HTTP_REFERER', None) + next_page = request.headers.get('referer', None) if not next_page: next_page = SITE_ROOT @@ -77,7 +77,7 @@ def sys_login_admin_export_excel(request): def sys_log_file_audit_export_excel(request): """ Export file access logs to excel. """ - next_page = request.META.get('HTTP_REFERER', None) + next_page = request.headers.get('referer', None) if not next_page: next_page = SITE_ROOT @@ -134,7 +134,7 @@ def sys_log_file_audit_export_excel(request): def sys_log_file_update_export_excel(request): """ Export file update logs to excel. """ - next_page = request.META.get('HTTP_REFERER', None) + next_page = request.headers.get('referer', None) if not next_page: next_page = SITE_ROOT @@ -189,7 +189,7 @@ def sys_log_file_update_export_excel(request): def sys_log_perm_audit_export_excel(request): """ Export permission audit logs to excel. """ - next_page = request.META.get('HTTP_REFERER', None) + next_page = request.headers.get('referer', None) if not next_page: next_page = SITE_ROOT @@ -249,7 +249,7 @@ def sys_log_perm_audit_export_excel(request): wb = write_xls('perm-audit-logs', head, data_list) if not wb: - next_page = request.META.get('HTTP_REFERER', None) + next_page = request.headers.get('referer', None) if not next_page: next_page = SITE_ROOT diff --git a/seahub/test_settings.py b/seahub/test_settings.py index 9f234bcde3..c37bf24deb 100644 --- a/seahub/test_settings.py +++ b/seahub/test_settings.py @@ -18,8 +18,6 @@ REST_FRAMEWORK = { # Use static file storage instead of cached, since the cached need to run collect # command first. -STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' - # admin roles for test ENABLED_ADMIN_ROLE_PERMISSIONS = { 'cannot_view_system_info': { @@ -122,3 +120,4 @@ ENABLED_ADMIN_ROLE_PERMISSIONS = { 'other_permission': False, }, } +DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage' diff --git a/seahub/thirdparty_editor/urls.py b/seahub/thirdparty_editor/urls.py index ed71f69ed2..d93791acb1 100644 --- a/seahub/thirdparty_editor/urls.py +++ b/seahub/thirdparty_editor/urls.py @@ -1,10 +1,10 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url +from django.urls import path from .views import ThirdpartyEditorFileInfoView, ThirdpartyEditorFileContentView urlpatterns = [ # RESTful API - url(r'^file-info/$', ThirdpartyEditorFileInfoView.as_view(), name='ThirdpartyEditorFileInfoView'), - url(r'^file-content/$', ThirdpartyEditorFileContentView.as_view(), name='ThirdpartyEditorFileContentView'), + path('file-info/', ThirdpartyEditorFileInfoView.as_view(), name='ThirdpartyEditorFileInfoView'), + path('file-content/', ThirdpartyEditorFileContentView.as_view(), name='ThirdpartyEditorFileContentView'), ] diff --git a/seahub/thumbnail/urls.py b/seahub/thumbnail/urls.py index f6353e3d51..072cba8515 100644 --- a/seahub/thumbnail/urls.py +++ b/seahub/thumbnail/urls.py @@ -1,12 +1,12 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url, include +from django.urls import re_path from .views import thumbnail_create, thumbnail_get, share_link_thumbnail_get, \ share_link_thumbnail_create urlpatterns = [ - url(r'^(?P[-0-9a-f]{36})/create/$', thumbnail_create, name='thumbnail_create'), - url(r'^(?P[-0-9a-f]{36})/(?P[0-9]+)/(?P.*)$', thumbnail_get, name='thumbnail_get'), - url(r'^(?P[a-f0-9]+)/create/$', share_link_thumbnail_create, name='share_link_thumbnail_create'), - url(r'^(?P[a-f0-9]+)/(?P[0-9]+)/(?P.*)$', share_link_thumbnail_get, name='share_link_thumbnail_get'), + re_path(r'^(?P[-0-9a-f]{36})/create/$', thumbnail_create, name='thumbnail_create'), + re_path(r'^(?P[-0-9a-f]{36})/(?P[0-9]+)/(?P.*)$', thumbnail_get, name='thumbnail_get'), + re_path(r'^(?P[a-f0-9]+)/create/$', share_link_thumbnail_create, name='share_link_thumbnail_create'), + re_path(r'^(?P[a-f0-9]+)/(?P[0-9]+)/(?P.*)$', share_link_thumbnail_get, name='share_link_thumbnail_get'), ] diff --git a/seahub/thumbnail/views.py b/seahub/thumbnail/views.py index 932a5f0669..fd5b55880f 100644 --- a/seahub/thumbnail/views.py +++ b/seahub/thumbnail/views.py @@ -5,8 +5,8 @@ import logging import posixpath import datetime -from django.utils.translation import ugettext as _ -from django.utils.http import urlquote +from django.utils.translation import gettext as _ +from urllib.parse import quote from django.http import HttpResponse from django.views.decorators.http import condition from django.shortcuts import render @@ -56,7 +56,7 @@ def thumbnail_create(request, repo_id): success, status_code = generate_thumbnail(request, repo_id, size, path) if success: src = get_thumbnail_src(repo_id, size, path) - result['encoded_thumbnail_src'] = urlquote(src) + result['encoded_thumbnail_src'] = quote(src) return HttpResponse(json.dumps(result), content_type=content_type) else: err_msg = _('Failed to create thumbnail.') @@ -179,7 +179,7 @@ def share_link_thumbnail_create(request, token): success, status_code = generate_thumbnail(request, repo_id, size, real_path) if success: src = get_share_link_thumbnail_src(token, size, req_path) - result['encoded_thumbnail_src'] = urlquote(src) + result['encoded_thumbnail_src'] = quote(src) return HttpResponse(json.dumps(result), content_type=content_type) else: err_msg = _('Failed to create thumbnail.') diff --git a/seahub/two_factor/forms.py b/seahub/two_factor/forms.py index f967a30582..113e5ed444 100644 --- a/seahub/two_factor/forms.py +++ b/seahub/two_factor/forms.py @@ -4,7 +4,7 @@ from time import time from django import forms from django.forms import ModelForm, Form -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from seahub.two_factor.oath import totp from seahub.two_factor.models import (Device, TOTPDevice, StaticDevice, diff --git a/seahub/two_factor/gateways/twilio/gateway.py b/seahub/two_factor/gateways/twilio/gateway.py index a17c6d4ae3..eaf32267ad 100644 --- a/seahub/two_factor/gateways/twilio/gateway.py +++ b/seahub/two_factor/gateways/twilio/gateway.py @@ -9,7 +9,7 @@ except ImportError: from django.conf import settings from django.urls import reverse from django.utils import translation -from django.utils.translation import ugettext, pgettext +from django.utils.translation import gettext, pgettext from twilio.rest import TwilioRestClient from .middleware import get_current_request @@ -58,7 +58,7 @@ class Twilio(object): url=uri, method='GET', if_machine='Hangup', timeout=15) def send_sms(self, device, token): - body = ugettext('Your authentication token is %s') % token + body = gettext('Your authentication token is %s') % token self.client.sms.messages.create( to=device.number, from_=getattr(settings, 'TWILIO_CALLER_ID'), diff --git a/seahub/two_factor/gateways/twilio/views.py b/seahub/two_factor/gateways/twilio/views.py index 18bbe7ffa5..2de2d5a870 100644 --- a/seahub/two_factor/gateways/twilio/views.py +++ b/seahub/two_factor/gateways/twilio/views.py @@ -3,7 +3,7 @@ from django.conf import settings from django.contrib.sites.shortcuts import get_current_site from django.http import HttpResponse from django.utils import translation -from django.utils.translation import (ugettext_lazy as _, pgettext, +from django.utils.translation import (gettext_lazy as _, pgettext, check_for_language) from django.views.decorators.cache import never_cache from django.views.decorators.csrf import csrf_exempt diff --git a/seahub/two_factor/models/base.py b/seahub/two_factor/models/base.py index 716f6ce4d9..33f18fe1ca 100644 --- a/seahub/two_factor/models/base.py +++ b/seahub/two_factor/models/base.py @@ -4,7 +4,7 @@ import logging from django.conf import settings from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from seahub.base.fields import LowerCaseCharField from seahub.two_factor.utils import hex_validator diff --git a/seahub/two_factor/models/phone.py b/seahub/two_factor/models/phone.py index e8b7bcf9fb..0d6f397042 100644 --- a/seahub/two_factor/models/phone.py +++ b/seahub/two_factor/models/phone.py @@ -5,7 +5,7 @@ from binascii import unhexlify import logging from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from .base import Device, key_validator from seahub.two_factor.gateways import make_call, send_sms diff --git a/seahub/two_factor/urls.py b/seahub/two_factor/urls.py index 35e9a164c4..5ecd720a2c 100644 --- a/seahub/two_factor/urls.py +++ b/seahub/two_factor/urls.py @@ -1,29 +1,17 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url +from django.urls import path from seahub.two_factor.views import (BackupTokensView, SetupCompleteView, ProfileView, SetupView, QRGeneratorView, TwoFactorVerifyView, DisableView) urlpatterns = [ - # url(regex=r'^$', + # path(regex=r'^$', # view=ProfileView.as_view(), # name='profile', ), - url(regex=r'^setup/$', - view=SetupView.as_view(), - name='setup', ), - url(regex=r'^qrcode$', - view=QRGeneratorView.as_view(), - name='qr', ), - url(regex=r'^setup/complete/$', - view=SetupCompleteView.as_view(), - name='setup_complete', ), - url(regex=r'^backup/tokens/$', - view=BackupTokensView.as_view(), - name='backup_tokens', ), - url(regex=r'^disable/$', - view=DisableView.as_view(), - name='disable', ), - url(regex=r'verify/^$', - view=TwoFactorVerifyView.as_view(), - name='verify', ), + path('setup/', view=SetupView.as_view(), name='setup', ), + path('qrcode/', view=QRGeneratorView.as_view(), name='qr', ), + path('setup/complete/', view=SetupCompleteView.as_view(), name='setup_complete', ), + path('backup/tokens/', view=BackupTokensView.as_view(), name='backup_tokens', ), + path('disable/', view=DisableView.as_view(), name='disable', ), + path('verify/', view=TwoFactorVerifyView.as_view(), name='verify', ), ] diff --git a/seahub/two_factor/views/core.py b/seahub/two_factor/views/core.py index 2be8384f9c..1967b20d69 100644 --- a/seahub/two_factor/views/core.py +++ b/seahub/two_factor/views/core.py @@ -10,7 +10,7 @@ from django.urls import reverse from django.forms import Form from django.http import HttpResponse, Http404, HttpResponseRedirect from django.shortcuts import redirect -from django.utils.http import is_safe_url +from django.utils.http import url_has_allowed_host_and_scheme from django.utils.module_loading import import_string from django.views.decorators.cache import never_cache from django.views.decorators.debug import sensitive_post_parameters diff --git a/seahub/two_factor/views/login.py b/seahub/two_factor/views/login.py index f22f78e347..7e0a847144 100644 --- a/seahub/two_factor/views/login.py +++ b/seahub/two_factor/views/login.py @@ -10,11 +10,11 @@ from constance import config from django.conf import settings from django.urls import reverse from django.http import HttpResponseRedirect, Http404 -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.views.decorators.cache import never_cache from django.contrib.sites.shortcuts import get_current_site from django.shortcuts import redirect -from django.utils.http import is_safe_url +from django.utils.http import url_has_allowed_host_and_scheme from django.views.decorators.debug import sensitive_post_parameters from formtools.wizard.views import SessionWizardView @@ -106,7 +106,7 @@ class TwoFactorVerifyView(SessionWizardView): self.reset_two_factor_session() - if not is_safe_url(url=redirect_to, allowed_hosts=self.request.get_host()): + if not url_has_allowed_host_and_scheme(url=redirect_to, allowed_hosts=self.request.get_host()): redirect_to = str(settings.LOGIN_REDIRECT_URL) res = HttpResponseRedirect(redirect_to) diff --git a/seahub/two_factor/views/utils.py b/seahub/two_factor/views/utils.py index dd0304b88f..5c2ecfa3bf 100644 --- a/seahub/two_factor/views/utils.py +++ b/seahub/two_factor/views/utils.py @@ -4,7 +4,7 @@ import logging from constance import config from django.core.exceptions import ValidationError from django.utils.decorators import method_decorator -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.urls import reverse from django.http import HttpResponseRedirect diff --git a/seahub/urls.py b/seahub/urls.py index ba77aaf85b..baf30736bc 100644 --- a/seahub/urls.py +++ b/seahub/urls.py @@ -1,5 +1,5 @@ # Copyright (c) 2012-2016 Seafile Ltd. -from django.conf.urls import url, include +from django.urls import include, path, re_path from django.views.generic import TemplateView from seahub.auth.views import multi_adfs_sso @@ -198,609 +198,609 @@ from seahub.api2.endpoints.repo_auto_delete import RepoAutoDeleteView from seahub.ocm.settings import OCM_ENDPOINT urlpatterns = [ - url(r'^accounts/', include('seahub.base.registration_urls')), + path('accounts/', include('seahub.base.registration_urls')), - url(r'^sso/$', sso, name='sso'), - url(r'^multi_adfs_sso/$', multi_adfs_sso, name='multi_adfs_sso'), - url(r'^jwt-sso/$', jwt_sso, name='jwt_sso'), - url(r'^shib-login/', shib_login, name="shib_login"), - url(r'^oauth/', include('seahub.oauth.urls')), - url(r'^thirdparty-editor/', include('seahub.thirdparty_editor.urls')), - url(r'^ocm-via-webdav/', include('seahub.ocm_via_webdav.urls')), - url(r'^cad/', include('seahub.cad.urls')), + path('sso/', sso, name='sso'), + path('multi_adfs_sso/', multi_adfs_sso, name='multi_adfs_sso'), + path('jwt-sso/', jwt_sso, name='jwt_sso'), + re_path(r'^shib-login/', shib_login, name="shib_login"), + path('oauth/', include('seahub.oauth.urls')), + path('thirdparty-editor/', include('seahub.thirdparty_editor.urls')), + path('ocm-via-webdav/', include('seahub.ocm_via_webdav.urls')), + path('cad/', include('seahub.cad.urls')), - url(r'^sso-to-thirdpart/$', sso_to_thirdpart, name='sso-to-thirdpart'), + path('sso-to-thirdpart/', sso_to_thirdpart, name='sso-to-thirdpart'), - url(r'^$', react_fake_view, name='libraries'), - url(r'^robots\.txt$', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')), + path('', react_fake_view, name='libraries'), + re_path(r'^robots\.txt$', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')), # revert repo - url(r'^repo/history/revert/(?P[-0-9a-f]{36})/$', repo_revert_history, name='repo_revert_history'), + re_path(r'^repo/history/revert/(?P[-0-9a-f]{36})/$', repo_revert_history, name='repo_revert_history'), - url(r'^repo/upload_check/$', validate_filename), - url(r'^repo/download_dir/(?P[-0-9a-f]{36})/$', repo_download_dir, name='repo_download_dir'), - url(r'^repo/file_revisions/(?P[-0-9a-f]{36})/$', file_revisions, name='file_revisions'), - url(r'^repo/file-access/(?P[-0-9a-f]{36})/$', file_access, name='file_access'), - url(r'^repo/text_diff/(?P[-0-9a-f]{36})/$', text_diff, name='text_diff'), - url(r'^repo/history/(?P[-0-9a-f]{36})/$', repo_history, name='repo_history'), - url(r'^repo/history/view/(?P[-0-9a-f]{36})/$', repo_history_view, name='repo_history_view'), - url(r'^repo/(?P[-0-9a-f]{36})/snapshot/$', repo_snapshot, name="repo_snapshot"), - url(r'^repo/recycle/(?P[-0-9a-f]{36})/$', repo_recycle_view, name='repo_recycle_view'), - url(r'^dir/recycle/(?P[-0-9a-f]{36})/$', dir_recycle_view, name='dir_recycle_view'), - url(r'^repo/(?P[-0-9a-f]{36})/trash/$', repo_folder_trash, name="repo_folder_trash"), - url(r'^repo/(?P[-0-9a-f]{36})/raw/(?P.*)$', view_raw_file, name="view_raw_file"), - url(r'^repo/(?P[-0-9a-f]{36})/history/files/$', view_history_file, name="view_history_file"), - url(r'^repo/(?P[-0-9a-f]{36})/trash/files/$', view_trash_file, name="view_trash_file"), - url(r'^repo/(?P[-0-9a-f]{36})/snapshot/files/$', view_snapshot_file, name="view_snapshot_file"), - url(r'^repo/(?P[-0-9a-f]{36})/(?P[0-9a-f]{40})/download/$', download_file, name='download_file'), + path('repo/upload_check/', validate_filename), + re_path(r'^repo/download_dir/(?P[-0-9a-f]{36})/$', repo_download_dir, name='repo_download_dir'), + re_path(r'^repo/file_revisions/(?P[-0-9a-f]{36})/$', file_revisions, name='file_revisions'), + re_path(r'^repo/file-access/(?P[-0-9a-f]{36})/$', file_access, name='file_access'), + re_path(r'^repo/text_diff/(?P[-0-9a-f]{36})/$', text_diff, name='text_diff'), + re_path(r'^repo/history/(?P[-0-9a-f]{36})/$', repo_history, name='repo_history'), + re_path(r'^repo/history/view/(?P[-0-9a-f]{36})/$', repo_history_view, name='repo_history_view'), + re_path(r'^repo/(?P[-0-9a-f]{36})/snapshot/$', repo_snapshot, name="repo_snapshot"), + re_path(r'^repo/recycle/(?P[-0-9a-f]{36})/$', repo_recycle_view, name='repo_recycle_view'), + re_path(r'^dir/recycle/(?P[-0-9a-f]{36})/$', dir_recycle_view, name='dir_recycle_view'), + re_path(r'^repo/(?P[-0-9a-f]{36})/trash/$', repo_folder_trash, name="repo_folder_trash"), + re_path(r'^repo/(?P[-0-9a-f]{36})/raw/(?P.*)$', view_raw_file, name="view_raw_file"), + re_path(r'^repo/(?P[-0-9a-f]{36})/history/files/$', view_history_file, name="view_history_file"), + re_path(r'^repo/(?P[-0-9a-f]{36})/trash/files/$', view_trash_file, name="view_trash_file"), + re_path(r'^repo/(?P[-0-9a-f]{36})/snapshot/files/$', view_snapshot_file, name="view_snapshot_file"), + re_path(r'^repo/(?P[-0-9a-f]{36})/(?P[0-9a-f]{40})/download/$', download_file, name='download_file'), ### lib (replace the old `repo` urls) ### # url(r'^lib/(?P[-0-9a-f]{36})/dir/(?P.*)$', view_lib_dir, name='view_lib_dir'), - url(r'^lib/(?P[-0-9a-f]{36})/file(?P.*)$', view_lib_file, name='view_lib_file'), - url(r'^wiki/lib/(?P[-0-9a-f]{36})/(?P.*)$', view_lib_as_wiki, name='view_lib_as_wiki'), - url(r'^smart-link/(?P[-0-9a-f]{36})/(?P.*)$', view_lib_file_via_smart_link, name="view_lib_file_via_smart_link"), + re_path(r'^lib/(?P[-0-9a-f]{36})/file(?P.*)$', view_lib_file, name='view_lib_file'), + re_path(r'^wiki/lib/(?P[-0-9a-f]{36})/(?P.*)$', view_lib_as_wiki, name='view_lib_as_wiki'), + re_path(r'^smart-link/(?P[-0-9a-f]{36})/(?P.*)$', view_lib_file_via_smart_link, name="view_lib_file_via_smart_link"), ### share/upload link ### - url(r'^f/(?P[a-f0-9]+)/$', view_shared_file, name='view_shared_file'), - url(r'^d/(?P[a-f0-9]+)/$', view_shared_dir, name='view_shared_dir'), - url(r'^d/(?P[a-f0-9]+)/files/$', view_file_via_shared_dir, name='view_file_via_shared_dir'), - url(r'^u/d/(?P[a-f0-9]+)/$', view_shared_upload_link, name='view_shared_upload_link'), - url(r'^view-image-via-share-link/$', view_media_file_via_share_link, name='view_media_file_via_share_link'), + re_path(r'^f/(?P[a-f0-9]+)/$', view_shared_file, name='view_shared_file'), + re_path(r'^d/(?P[a-f0-9]+)/$', view_shared_dir, name='view_shared_dir'), + re_path(r'^d/(?P[a-f0-9]+)/files/$', view_file_via_shared_dir, name='view_file_via_shared_dir'), + re_path(r'^u/d/(?P[a-f0-9]+)/$', view_shared_upload_link, name='view_shared_upload_link'), + path('view-image-via-share-link/', view_media_file_via_share_link, name='view_media_file_via_share_link'), # dingtalk - url(r'dingtalk/login/$', dingtalk_login, name='dingtalk_login'), - url(r'dingtalk/callback/$', dingtalk_callback, name='dingtalk_callback'), - url(r'dingtalk/connect/$', dingtalk_connect, name='dingtalk_connect'), - url(r'dingtalk/connect-callback/$', dingtalk_connect_callback, name='dingtalk_connect_callback'), - url(r'dingtalk/disconnect/$', dingtalk_disconnect, name='dingtalk_disconnect'), + path('dingtalk/login/', dingtalk_login, name='dingtalk_login'), + path('dingtalk/callback/', dingtalk_callback, name='dingtalk_callback'), + path('dingtalk/connect/', dingtalk_connect, name='dingtalk_connect'), + path('dingtalk/connect-callback/', dingtalk_connect_callback, name='dingtalk_connect_callback'), + path('dingtalk/disconnect/', dingtalk_disconnect, name='dingtalk_disconnect'), ### Misc ### - url(r'^image-view/(?P.*)$', image_view, name='image_view'), - url(r'^custom-css/$', custom_css_view, name='custom_css'), - url(r'^i18n/$', i18n, name='i18n'), - url(r'^convert_cmmt_desc_link/$', convert_cmmt_desc_link, name='convert_cmmt_desc_link'), - url(r'^download_client_program/$', TemplateView.as_view(template_name="download.html"), name="download_client"), - url(r'^choose_register/$', choose_register, name="choose_register"), + re_path(r'^image-view/(?P.*)$', image_view, name='image_view'), + path('custom-css/', custom_css_view, name='custom_css'), + path('i18n/', i18n, name='i18n'), + path('convert_cmmt_desc_link/', convert_cmmt_desc_link, name='convert_cmmt_desc_link'), + path('download_client_program/', TemplateView.as_view(template_name="download.html"), name="download_client"), + path('choose_register/', choose_register, name="choose_register"), ### React ### - url(r'^dashboard/$', react_fake_view, name="dashboard"), - url(r'^starred/$', react_fake_view, name="starred"), - url(r'^linked-devices/$', react_fake_view, name="linked_devices"), - url(r'^share-admin-libs/$', react_fake_view, name="share_admin_libs"), - url(r'^share-admin-folders/$', react_fake_view, name="share_admin_folders"), - url(r'^share-admin-share-links/$', react_fake_view, name="share_admin_share_links"), - url(r'^share-admin-upload-links/$', react_fake_view, name="share_admin_upload_links"), - url(r'^shared-libs/$', react_fake_view, name="shared_libs"), - url(r'^shared-with-ocm/$', react_fake_view, name="shared_with_ocm"), - url(r'^my-libs/$', react_fake_view, name="my_libs"), - url(r'^groups/$', react_fake_view, name="groups"), - url(r'^group/(?P\d+)/$', react_fake_view, name="group"), - url(r'^library/(?P[-0-9a-f]{36})/$', react_fake_view, name="library_view"), - url(r'^library/(?P[-0-9a-f]{36})/(?P[^/]+)/(?P.*)$', react_fake_view, name="lib_view"), - url(r'^remote-library/(?P[-0-9a-f]{36})/(?P[-0-9a-f]{36})/(?P[^/]+)/(?P.*)$', react_fake_view, name="remote_lib_view"), - url(r'^my-libs/deleted/$', react_fake_view, name="my_libs_deleted"), - url(r'^org/$', react_fake_view, name="org"), - url(r'^invitations/$', react_fake_view, name="invitations"), + path('dashboard/', react_fake_view, name="dashboard"), + path('starred/', react_fake_view, name="starred"), + path('linked-devices/', react_fake_view, name="linked_devices"), + path('share-admin-libs/', react_fake_view, name="share_admin_libs"), + path('share-admin-folders/', react_fake_view, name="share_admin_folders"), + path('share-admin-share-links/', react_fake_view, name="share_admin_share_links"), + path('share-admin-upload-links/', react_fake_view, name="share_admin_upload_links"), + path('shared-libs/', react_fake_view, name="shared_libs"), + path('shared-with-ocm/', react_fake_view, name="shared_with_ocm"), + path('my-libs/', react_fake_view, name="my_libs"), + path('groups/', react_fake_view, name="groups"), + path('group//', react_fake_view, name="group"), + re_path(r'^library/(?P[-0-9a-f]{36})/$', react_fake_view, name="library_view"), + re_path(r'^library/(?P[-0-9a-f]{36})/(?P[^/]+)/(?P.*)$', react_fake_view, name="lib_view"), + re_path(r'^remote-library/(?P[-0-9a-f]{36})/(?P[-0-9a-f]{36})/(?P[^/]+)/(?P.*)$', react_fake_view, name="remote_lib_view"), + path('my-libs/deleted/', react_fake_view, name="my_libs_deleted"), + path('org/', react_fake_view, name="org"), + path('invitations/', react_fake_view, name="invitations"), - url(r'^ajax/repo/(?P[-0-9a-f]{36})/history/changes/$', repo_history_changes, name='repo_history_changes'), - url(r'^ajax/u/d/(?P[-0-9a-f]+)/upload/$', get_file_upload_url_ul, name='get_file_upload_url_ul'), - url(r'^ajax/upload-file-done/$', upload_file_done, name='upload_file_done'), + re_path(r'^ajax/repo/(?P[-0-9a-f]{36})/history/changes/$', repo_history_changes, name='repo_history_changes'), + re_path(r'^ajax/u/d/(?P[-0-9a-f]+)/upload/$', get_file_upload_url_ul, name='get_file_upload_url_ul'), + path('ajax/upload-file-done/', upload_file_done, name='upload_file_done'), - url(r'^_templates/(?P