irongit

Enhanced time synchronization for drf views.

changed check_update to should_update

huncholanehuncholaneauthored
parent 6c4a40ecommit a6d7be6dc70fda9ea5f35a86425e141d1dd413f4Browse files

3 files changed, +4 -4

+2-2README.md
@@ -42,7 +42,7 @@ class MyView(APIView):
4242
4343 def put(request: Request, pk:int):
4444 instance = MyModel.objects.get(pk=pk)
45- TimeCheck(request,instance).check_update() # throws rest framework exception
45+ TimeCheck(request,instance).should_update() # throws rest framework exception
4646 ...
4747 return Response(data)
4848 ```
@@ -70,7 +70,7 @@ TimeCheck(request, ...) has the following arguments:
7070 ### TimeCheck Methods
7171
7272 - `should_get` Raises a `NoUpdate` exception when the client timestamp is newer than or equal to the server timestamp. Returns a True if the client should receive data.
73-- `check_update` Raises a `NoUpdate` exception when the client timestamp is older than or equal to the server timestamp. Returns a True if the update should continue.
73+- `should_update` Raises a `NoUpdate` exception when the client timestamp is older than or equal to the server timestamp. Returns a True if the update should continue.
7474
7575 ---
7676
+1-1example_app/views.py
@@ -20,5 +20,5 @@ class View(APIView):
2020 def put(self, request):
2121 instance = Post.objects.all().first()
2222 if instance:
23- TimeCheck(request, instance).check_update()
23+ TimeCheck(request, instance).should_update()
2424 return Response({"port": request.META.get("SERVER_PORT")})
+1-1timecheck/timecheck.py
@@ -93,7 +93,7 @@ class TimeCheckPrivate:
9393 return False
9494 return True
9595
96- def check_update(self):
96+ def should_update(self):
9797 """Raises a drf exception `NoUpdate` which provides details that there is no need to update the server."""
9898 logger.debug(
9999 f"Checking update: client={self.client_timestamp}, server={self.server_timestamp}"