Enhanced time synchronization for drf views.
changed check_update to should_update
3 files changed, +4 -4
+2-2README.md
| @@ -42,7 +42,7 @@ class MyView(APIView): | ||
| 42 | 42 | |
| 43 | 43 | def put(request: Request, pk:int): |
| 44 | 44 | 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 | |
| 46 | 46 | ... |
| 47 | 47 | return Response(data) |
| 48 | 48 | ``` |
| @@ -70,7 +70,7 @@ TimeCheck(request, ...) has the following arguments: | ||
| 70 | 70 | ### TimeCheck Methods |
| 71 | 71 | |
| 72 | 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 | -- `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. | |
| 74 | 74 | |
| 75 | 75 | --- |
| 76 | 76 |
+1-1example_app/views.py
| @@ -20,5 +20,5 @@ class View(APIView): | ||
| 20 | 20 | def put(self, request): |
| 21 | 21 | instance = Post.objects.all().first() |
| 22 | 22 | if instance: |
| 23 | - TimeCheck(request, instance).check_update() | |
| 23 | + TimeCheck(request, instance).should_update() | |
| 24 | 24 | return Response({"port": request.META.get("SERVER_PORT")}) |
+1-1timecheck/timecheck.py
| @@ -93,7 +93,7 @@ class TimeCheckPrivate: | ||
| 93 | 93 | return False |
| 94 | 94 | return True |
| 95 | 95 | |
| 96 | - def check_update(self): | |
| 96 | + def should_update(self): | |
| 97 | 97 | """Raises a drf exception `NoUpdate` which provides details that there is no need to update the server.""" |
| 98 | 98 | logger.debug( |
| 99 | 99 | f"Checking update: client={self.client_timestamp}, server={self.server_timestamp}" |