Enhanced time synchronization for drf views.
changed name of check_get to should_get
3 files changed, +4 -3
+1-1README.md
| @@ -69,7 +69,7 @@ TimeCheck(request, ...) has the following arguments: | ||
| 69 | 69 | |
| 70 | 70 | ### TimeCheck Methods |
| 71 | 71 | |
| 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. | |
| 73 | 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. |
| 74 | 74 | |
| 75 | 75 | --- |
+1-1example_app/views.py
| @@ -9,7 +9,7 @@ class View(APIView): | ||
| 9 | 9 | def get(self, request): |
| 10 | 10 | instance = Post.objects.all().first() |
| 11 | 11 | if instance: |
| 12 | - TimeCheck(request, instance).check_get() | |
| 12 | + TimeCheck(request, instance).should_get() | |
| 13 | 13 | return Response( |
| 14 | 14 | { |
| 15 | 15 | "CONTENT_LENGTH": request.META.get("CONTENT_LENGTH"), |
+2-1timecheck/timecheck.py
| @@ -75,7 +75,7 @@ class TimeCheckPrivate: | ||
| 75 | 75 | except Exception: |
| 76 | 76 | raise InvalidClientDatetimeField(self._body_field, body_str) |
| 77 | 77 | |
| 78 | - def check_get(self): | |
| 78 | + def should_get(self): | |
| 79 | 79 | """Raises a drf exception `NoUpdate` which provides details that there is no need to give data back to the user.""" |
| 80 | 80 | logger.debug( |
| 81 | 81 | f"Checking get: client={self.client_timestamp}, server={self.server_timestamp}" |
| @@ -109,3 +109,4 @@ class TimeCheckPrivate: | ||
| 109 | 109 | raise NoUpdate(self.request.method, self._noupdate_code) |
| 110 | 110 | else: |
| 111 | 111 | return False |
| 112 | + return True |