Skip to content

Commit

Permalink
feat: user timezones (#2009)
Browse files Browse the repository at this point in the history
* dev: user timezones

* feat: user timezones
  • Loading branch information
pablohashescobar committed Aug 30, 2023
1 parent 23f5d5d commit 426f658
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
27 changes: 22 additions & 5 deletions apiserver/plane/api/views/base.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
# Python imports
import zoneinfo

# Django imports
from django.urls import resolve
from django.conf import settings

from django.utils import timezone
# Third part imports

from rest_framework import status
from rest_framework.viewsets import ModelViewSet
from rest_framework.exceptions import APIException
from rest_framework.views import APIView
from rest_framework.filters import SearchFilter
from rest_framework.permissions import IsAuthenticated
from rest_framework.exceptions import NotFound
from sentry_sdk import capture_exception
from django_filters.rest_framework import DjangoFilterBackend

# Module imports
from plane.db.models import Workspace, Project
from plane.utils.paginator import BasePaginator


class BaseViewSet(ModelViewSet, BasePaginator):
class TimezoneMixin:
"""
This enables timezone conversion according
to the user set timezone
"""
def initial(self, request, *args, **kwargs):
super().initial(request, *args, **kwargs)
if request.user.is_authenticated:
timezone.activate(zoneinfo.ZoneInfo(request.user.user_timezone))
else:
timezone.deactivate()




class BaseViewSet(TimezoneMixin, ModelViewSet, BasePaginator):

model = None

Expand Down Expand Up @@ -67,7 +84,7 @@ def project_id(self):
return self.kwargs.get("pk", None)


class BaseAPIView(APIView, BasePaginator):
class BaseAPIView(TimezoneMixin, APIView, BasePaginator):

permission_classes = [
IsAuthenticated,
Expand Down
Loading

0 comments on commit 426f658

Please sign in to comment.