Skip to content

Commit

Permalink
feat: added list user documents view
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-lymar committed Jun 22, 2024
1 parent 9df925a commit 780d066
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
UserCreateView,
UserUpdatePasswordView,
UserUpdateView,
ListUserFilesAPIView
)

urlpatterns = [
Expand All @@ -17,6 +18,7 @@
path("logout/", LogoutView.as_view(), name="logout"),
path("edit/", UserUpdateView.as_view(), name="edit"),
path("edit_password/", UserUpdatePasswordView.as_view(), name="edit_password"),
path("listuserfiles/", ListUserFilesAPIView.as_view(), name="list_user_files"),
path("departments/", DepartmentListView.as_view(), name="departments"),
path("positions/", PositionListView.as_view(), name="positions"),
path("registration/", UserCreateView.as_view(), name="registration"),
Expand Down
26 changes: 26 additions & 0 deletions users/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os.path

from django.dispatch import receiver
from django_rest_passwordreset.signals import reset_password_token_created
from rest_framework import generics, status
Expand Down Expand Up @@ -70,6 +72,30 @@ class UserUpdatePasswordView(UserRelatedView):
serializer_class = UserUpdatePasswordSerializer


# Отображение списка документов пользователя
class ListUserFilesAPIView(APIView):
permission_classes = (IsAuthenticated,)

def get(self, request, *args, **kwargs):
user_folder = os.path.join("makedoc", "tempdoc", str(request.user.id))

if not os.path.exists(user_folder):
return Response({"error": "User folder not found"}, status=status.HTTP_404_NOT_FOUND)

try:
files = os.listdir(user_folder)
except OSError as e:
return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)

files_list = []
for file_name in files:
file_path = os.path.join(user_folder, file_name)
if os.path.isfile(file_path):
files_list.append(file_name)

return Response({"files": files_list}, status=status.HTTP_200_OK)


# Сброс пароля
@receiver(reset_password_token_created)
def password_reset_token_created(sender, instance, reset_password_token, *args, **kwargs):
Expand Down

0 comments on commit 780d066

Please sign in to comment.