/updates/fetch
This commit is contained in:
parent
0e1a6a5af1
commit
62c8456675
3 changed files with 25 additions and 16 deletions
|
@ -13,7 +13,7 @@ from c3nav.mapdata.api import (AccessRestrictionGroupViewSet, AccessRestrictionV
|
|||
LeaveDescriptionViewSet, LevelViewSet, LineObstacleViewSet, LocationBySlugViewSet,
|
||||
LocationGroupCategoryViewSet, LocationGroupViewSet, LocationViewSet, MapViewSet,
|
||||
ObstacleViewSet, POIViewSet, RampViewSet, SourceViewSet, SpaceViewSet, StairViewSet,
|
||||
UserViewSet)
|
||||
UpdatesViewSet)
|
||||
from c3nav.routing.api import RoutingViewSet
|
||||
|
||||
router = SimpleRouter()
|
||||
|
@ -41,7 +41,7 @@ router.register(r'locations/by_slug', LocationBySlugViewSet, base_name='location
|
|||
router.register(r'locationgroupcategories', LocationGroupCategoryViewSet)
|
||||
router.register(r'locationgroups', LocationGroupViewSet)
|
||||
|
||||
router.register(r'users', UserViewSet, base_name='users')
|
||||
router.register(r'updates', UpdatesViewSet, base_name='updates')
|
||||
|
||||
router.register(r'routing', RoutingViewSet, base_name='routing')
|
||||
|
||||
|
|
|
@ -404,18 +404,24 @@ class AccessRestrictionGroupViewSet(MapdataViewSet):
|
|||
queryset = AccessRestrictionGroup.objects.all()
|
||||
|
||||
|
||||
class UserViewSet(GenericViewSet):
|
||||
class UpdatesViewSet(GenericViewSet):
|
||||
"""
|
||||
Get display information about the current user. This endpoint also sets the tile access cookie.
|
||||
Get information about recent updates.
|
||||
Get display information about the current user.
|
||||
Set the tile access cookie.
|
||||
The tile access cookie is only valid for 1 minute, so if you are displaying a map, call this endpoint repeatedly.
|
||||
"""
|
||||
@list_route(methods=['get'])
|
||||
def current(self, request, key=None):
|
||||
def fetch(self, request, key=None):
|
||||
try:
|
||||
cache.incr('api_user_current_requests')
|
||||
cache.incr('api_updates_fetch_requests')
|
||||
except ValueError:
|
||||
cache.set('api_user_current_requests', 0, None)
|
||||
cache.set('api_updates_fetch_requests', 0, None)
|
||||
|
||||
response = Response({
|
||||
'last_map_update': MapUpdate.current_processed_cache_key(),
|
||||
'user': get_user_data(request),
|
||||
})
|
||||
|
||||
response = Response(get_user_data(request))
|
||||
set_tile_access_cookie(request, response)
|
||||
return response
|
||||
|
|
|
@ -922,7 +922,7 @@ c3nav = {
|
|||
},
|
||||
_modal_loaded: function(data) {
|
||||
if (data.startsWith('{')) {
|
||||
c3nav._set_user_data(JSON.parse(data));
|
||||
c3nav._fetch_updates_callback(JSON.parse(data));
|
||||
history.back();
|
||||
return;
|
||||
}
|
||||
|
@ -1018,7 +1018,7 @@ c3nav = {
|
|||
|
||||
c3nav.map.on('click', c3nav._click_anywhere);
|
||||
|
||||
c3nav.schedule_refresh_tile_access();
|
||||
c3nav.schedule_fetch_updates();
|
||||
|
||||
},
|
||||
_click_anywhere_popup: null,
|
||||
|
@ -1158,16 +1158,19 @@ c3nav = {
|
|||
}
|
||||
},
|
||||
|
||||
schedule_refresh_tile_access: function (timeout) {
|
||||
window.setTimeout(c3nav.refresh_tile_access, timeout || 16000);
|
||||
schedule_fetch_updates: function (timeout) {
|
||||
window.setTimeout(c3nav.fetch_updates, timeout || 16000);
|
||||
},
|
||||
refresh_tile_access: function () {
|
||||
$.get('/api/users/current/', c3nav._set_user_data).fail(function() {
|
||||
c3nav.schedule_refresh_tile_access(1000);
|
||||
fetch_updates: function () {
|
||||
$.get('/api/updates/fetch/', c3nav._fetch_updates_callback).fail(function() {
|
||||
c3nav.schedule_fetch_updates(1000);
|
||||
});
|
||||
},
|
||||
_fetch_updates_callback: function (data) {
|
||||
c3nav.schedule_fetch_updates();
|
||||
c3nav._set_user_data(data.user);
|
||||
},
|
||||
_set_user_data: function (data) {
|
||||
c3nav.schedule_refresh_tile_access();
|
||||
var $user = $('header #user');
|
||||
$user.find('span').text(data.title);
|
||||
$user.find('small').text(data.subtitle || '');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue