def initial(self, request): """ Before dispatching to put(), delete()... 1) Checks current user authentication to prevent remote DB manipulation 2) Prepares self.list_objects from params """ if not request.user.is_authenticated(): raise Http404() # can't use return in initial() (although 401 maybe better than 404) # can't use @requires_auth because of positional 'self' within class # get validated params self.params = get_parameters(request) (self.base_list, self.change_list) = ListChange._validate(self.params) if not len(self.change_list.items): payload_ngrams = request.data['ngrams'] # print("no change_list in params but we got:", payload_ngrams) # change_list can be in payload too change_ngram_ids = [int(n) for n in payload_ngrams.split(',')] if (not len(change_ngram_ids)): raise ValidationException( 'The "ngrams" parameter requires one or more ngram_ids separated by comma' ) else: self.change_list = UnweightedList(change_ngram_ids)
def initial(self, request): """ Before dispatching to post() or delete() Checks current user authentication to prevent remote DB manipulation """ if not request.user.is_authenticated(): raise Http404()
def get(self, request, node_id): if not request.user.is_authenticated(): # can't use @requires_auth because of positional 'self' within class return HttpResponse('Unauthorized', status=401) parameters, query, count = _query_nodes(request, node_id) if not len(query): raise Http404() node = query[0] return JsonHttpResponse(_filter_node_fields(node, parameters))
def delete(self, request, node_id): if not request.user.is_authenticated(): # can't use @requires_auth because of positional 'self' within class return HttpResponse('Unauthorized', status=401) parameters, query, count = _query_nodes(request, node_id) if not len(query): raise Http404() result = session.execute(delete(Node).where(Node.id == node_id)) session.commit() return JsonHttpResponse({'deleted': result.rowcount})