Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions config/api_router.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.conf import settings
from rest_framework.routers import DefaultRouter, SimpleRouter

from reference.api.v1.views import ReferenceViewSet
from markup_doc.api.v1.views import ArticleViewSet
from reference.api.v1.views import ReferenceViewSet
from rest_framework.routers import DefaultRouter, SimpleRouter

if settings.DEBUG:
router = DefaultRouter()
Expand All @@ -12,4 +11,4 @@
router.register("reference", ReferenceViewSet, basename="reference")
router.register("first_block", ArticleViewSet, basename="first_block")

urlpatterns = router.urls
urlpatterns = router.urls
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
]

THIRD_PARTY_APPS = [
"rest_framework",
"compressor",
"wagtailautocomplete",
]
Expand Down
26 changes: 11 additions & 15 deletions markup_doc/api/v1/views.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
from django.shortcuts import render
import json

from django.http import JsonResponse
from rest_framework.mixins import CreateModelMixin
from rest_framework.permissions import IsAuthenticated
from rest_framework.viewsets import GenericViewSet
from rest_framework.mixins import CreateModelMixin
from rest_framework.response import Response

from markup_doc.api.v1.serializers import ArticleDocxSerializer
from markup_doc.marker import mark_article

import json

# Create your views here.

class ArticleViewSet(
GenericViewSet, # generic view functionality
CreateModelMixin, # handles POSTs
GenericViewSet,
CreateModelMixin
):
serializer_class = ArticleDocxSerializer
permission_classes = [IsAuthenticated]
Expand All @@ -27,17 +25,15 @@ def create(self, request, *args, **kwargs):
def api_article(self, request):
try:
data = json.loads(request.body)
post_text = data.get('text') # Obtiene el parámetro
post_metadata = data.get('metadata') # Obtiene el parámetro
post_text = data.get("text")
post_metadata = data.get("metadata")

resp_data = mark_article(post_text, post_metadata)

response_data = {
'message': resp_data,
"message": resp_data,
}
except json.JSONDecodeError:
response_data = {
'error': 'Error processing'
}
response_data = {"error": "Error processing"}

return JsonResponse(response_data)
return JsonResponse(response_data)
35 changes: 14 additions & 21 deletions reference/api/v1/views.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
from django.shortcuts import render
import json

from django.http import JsonResponse
from rest_framework.mixins import CreateModelMixin
from rest_framework.permissions import IsAuthenticated
from rest_framework.viewsets import GenericViewSet
from rest_framework.mixins import CreateModelMixin
from rest_framework.response import Response

from reference.api.v1.serializers import ReferenceSerializer
from reference.marker import mark_references
from reference.data_utils import get_reference
from reference.models import Reference, ReferenceStatus

import json

from reference.models import Reference, ElementCitation, ReferenceStatus

# Create your views here.

class ReferenceViewSet(
GenericViewSet, # generic view functionality
CreateModelMixin, # handles POSTs
GenericViewSet,
CreateModelMixin
):
serializer_class = ReferenceSerializer
permission_classes = [IsAuthenticated]
Expand All @@ -25,14 +21,13 @@ class ReferenceViewSet(
]

def create(self, request, *args, **kwargs):
# Redirigir a la función api_reference()
return self.api_reference(request)

def api_reference(self, request):
try:
data = json.loads(request.body)
post_reference = data.get('reference') # Obtiene el parámetro
post_type = data.get('type') # Obtiene el parámetro
post_reference = data.get("reference")
post_type = data.get("type")

try:
reference = Reference.objects.get(mixed_citation=post_reference)
Expand All @@ -46,18 +41,16 @@ def api_reference(self, request):

get_reference(new_reference.id)
reference = Reference.objects.get(mixed_citation=post_reference)
if post_type == 'xml':

if post_type == "xml":
reference_data = reference.element_citation.first().marked_xml
else:
reference_data = reference.element_citation.first().marked

response_data = {
'message': f'reference: {reference_data}',
"message": f"reference: {reference_data}",
}
except json.JSONDecodeError:
response_data = {
'error': 'Error processing'
}
response_data = {"error": "Error processing"}

return JsonResponse(response_data)
return JsonResponse(response_data)
8 changes: 4 additions & 4 deletions reference/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ReferenceStatus(models.IntegerChoices):
class Reference(CommonControlField, ClusterableModel):
mixed_citation = models.TextField(_("Mixed Citation"), null=False, blank=True)

estatus = models.IntegerField(
status = models.IntegerField(
_("Reference status"),
choices=ReferenceStatus.choices,
blank=True,
Expand All @@ -47,11 +47,11 @@ class ElementCitation(Orderable):
marked_xml = models.TextField(_("Marked XML"), blank=True)

score = models.IntegerField(
null=True,
null=True,
blank=True,
validators=[
MinValueValidator(1), # Mínimo 1
MaxValueValidator(10) # Máximo 10
MinValueValidator(1),
MaxValueValidator(10)
],
help_text=_("Rating from 1 to 10")
)
Expand Down
Loading