def page(request, word): if request.method == 'GET': tempResult = Website_word.objects.get(word=word) tempSerializer = KeywordSerializer(tempResult, many=False) result = Website_page.objects.get(id_website_page=tempSerializer.data['id_website_page']) serializer = PageSerializer(result, many=False) return Response(serializer.data)
def toggle_correct(self, request, pk): instance = Page.objects.get(pk=pk) if (instance.is_correct != 1): instance.is_correct = 1 else: instance.is_correct = -1 instance.save() serializer = PageSerializer(instance) return Response(serializer.data)
def results(request): word = request.GET.get('q') nb = int(request.GET.get('nb') if not None else 10) p = int(request.GET.get('p') if not None else 0) offset = (p - 1) * nb pages = [] nbwords = int(Website_word.objects.filter(word__contains=word).count()) nbp = ceil(nbwords/nb) words = Website_word.objects.filter(word__contains=word).order_by('-weight')[offset:nb+offset] for wd in words: pid = wd.id_website_page.id_website_page result = Website_page.objects.get(id_website_page=pid) ps = PageSerializer(result) pages.append(ps.data) search_results = { 'nb': nbwords, 'nbp': nbp, 'curp': p, 'results': pages } if not request.GET.get('history') is None and p == 1: search_history = Search_history(user=request.user, word=word, nb_results=nbwords) search_history.save() return Response(search_results)
def get(self, request, slug): question = get_object_or_404(Page, slug=slug) data = PageSerializer(question).data return Response(data)
def get(self, request): questions = Page.objects.all().order_by('-created') data = PageSerializer(questions, many=True).data return Response(data)
def get(self, request, pk): pages = get_object_or_404(Page, pk=pk) data = PageSerializer(pages).data return Response(data)
def get(self, request): pages = Page.objects.all()[:20] data = PageSerializer(pages, many=True).data return Response(data)
def mark_is_correct(self, request, pk=None): instance = Page.objects.get(pk=pk) instance.is_correct = request.data['is_correct'] instance.save() serializer = PageSerializer(instance) return Response(serializer.data)
def get(self, request, pk): page = get_object_or_404(Page, slug=slug) data = PageSerializer(page).data return Response(data)