def get(self, request, *args, **kwargs):
_page = get_object_or_404(Page, pk=request.GET.get('page_id'))
# release page for all users which did not update during the last timeframe
PageIndicator.objects.filter(edited_on__lte=self.time_past, page=_page).delete()
page_indicators = PageIndicator.objects.filter(edited_on__gte=self.time_past, page=_page)\
.exclude(editor=request.user)
response = {}
if page_indicators.exists():
response['conflict'] = True
editing_user = page_indicators.first()
response['concurrent_user'] = [editing_user.editor.username]
# default behavior for concurrent users is blocking
response['block_editing'] = getattr(settings, 'CONCURRENT_BLOCK_EDITING', BLOCK_EDITING_DEFAULT)
response['message'] = _(u'Unfortunately you cannot edit this page at the moment: '
u'user {user} is blocking it since {time}').format(
user=editing_user.editor,
time=_date(editing_user.started_editing, 'D, d. b, H:i'))
else:
response['conflict'] = False
return JsonResponse(json.dumps(response), safe=False)
评论列表
文章目录