irongit

Enhanced time synchronization for drf views.

changed name of check_get to should_get

huncholanehuncholaneauthored
parent 4c831facommit 6c4a40ef51d04d07b5244652815de8658201cbe4Browse files

3 files changed, +4 -3

+1-1README.md
@@ -69,7 +69,7 @@ TimeCheck(request, ...) has the following arguments:
6969
7070 ### TimeCheck Methods
7171
72-- `check_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.
72+- `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.
7373 - `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.
7474
7575 ---
+1-1example_app/views.py
@@ -9,7 +9,7 @@ class View(APIView):
99 def get(self, request):
1010 instance = Post.objects.all().first()
1111 if instance:
12- TimeCheck(request, instance).check_get()
12+ TimeCheck(request, instance).should_get()
1313 return Response(
1414 {
1515 "CONTENT_LENGTH": request.META.get("CONTENT_LENGTH"),
+2-1timecheck/timecheck.py
@@ -75,7 +75,7 @@ class TimeCheckPrivate:
7575 except Exception:
7676 raise InvalidClientDatetimeField(self._body_field, body_str)
7777
78- def check_get(self):
78+ def should_get(self):
7979 """Raises a drf exception `NoUpdate` which provides details that there is no need to give data back to the user."""
8080 logger.debug(
8181 f"Checking get: client={self.client_timestamp}, server={self.server_timestamp}"
@@ -109,3 +109,4 @@ class TimeCheckPrivate:
109109 raise NoUpdate(self.request.method, self._noupdate_code)
110110 else:
111111 return False
112+ return True