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
4 changes: 2 additions & 2 deletions config/api_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from rest_framework.routers import DefaultRouter, SimpleRouter

from reference.api.v1.views import ReferenceViewSet

app_name = "reference"
from markup_doc.api.v1.views import ArticleViewSet

if settings.DEBUG:
router = DefaultRouter()
else:
router = SimpleRouter()

router.register("reference", ReferenceViewSet, basename="reference")
router.register("first_block", ArticleViewSet, basename="first_block")

urlpatterns = router.urls
2 changes: 2 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
"reference",
"xml_manager",
"model_ai",
"markup_doc",
"markuplib",
]

INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS + WAGTAIL
Expand Down
Binary file added fixtures/Artigo 5.docx
Binary file not shown.
Binary file added fixtures/e14790.docx
Binary file not shown.
Binary file added fixtures/e740.docx
Binary file not shown.
Empty file added markup_doc/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions markup_doc/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
Empty file added markup_doc/api/__init__.py
Empty file.
Empty file added markup_doc/api/v1/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions markup_doc/api/v1/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from rest_framework import serializers
from markup_doc.models import ArticleDocx

class ArticleDocxSerializer(serializers.ModelSerializer):
class Meta:
model = ArticleDocx
fields = "__all__"
43 changes: 43 additions & 0 deletions markup_doc/api/v1/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from django.shortcuts import render
from django.http import JsonResponse
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
):
serializer_class = ArticleDocxSerializer
permission_classes = [IsAuthenticated]
http_method_names = [
"post",
]

def create(self, request, *args, **kwargs):
return self.api_article(request)

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

resp_data = mark_article(post_text, post_metadata)

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

return JsonResponse(response_data)
6 changes: 6 additions & 0 deletions markup_doc/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class MarkupDocConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "markup_doc"
121 changes: 121 additions & 0 deletions markup_doc/choices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
front_labels = [
('<abstract>', '<abstract>'),
('<abstract-title>', '<abstract-title>'),
('<aff>', '<aff>'),
('<article-id>', '<article-id>'),
('<article-title>', '<article-title>'),
('<author-notes>', '<author-notes>'),
('<contrib>', '<contrib>'),
('<date-accepted>', '<date-accepted>'),
('<date-received>', '<date-received>'),
('<fig>', '<fig>'),
('<fig-attrib>', '<fig-attrib>'),
('<history>', '<history>'),
('<kwd-title>', '<kwd-title>'),
('<kwd-group>', '<kwd-group>'),
('<list>', '<list>'),
('<p>', '<p>'),
('<sec>', '<sec>'),
('<sub-sec>', '<sub-sec>'),
('<subject>', '<subject>'),
('<table>', '<table>'),
('<table-foot>', '<table-foot>'),
('<title>', '<title>'),
('<trans-abstract>', '<trans-abstract>'),
('<trans-title>', '<trans-title>'),
('<translate-front>', '<translate-front>'),
('<translate-body>', '<translate-body>'),
('<disp-formula>', '<disp-formula>'),
('<inline-formula>', '<inline-formula>'),
('<formula>', '<formula>'),

]

order_labels = {
'<article-id>':{
'pos' : 1,
'next' : '<subject>'
},
'<subject>':{
'pos' : 2,
'next' : '<article-title>'
},
'<article-title>':{
'pos' : 3,
'next' : '<trans-title>',
'lan' : True
},
'<trans-title>':{
'size' : 14,
'bold' : True,
'lan' : True,
'next' : '<contrib>'
},
'<contrib>':{
'reset' : True,
'size' : 12,
'next' : '<aff>'
},
'<aff>':{
'reset' : True,
'size' : 12,
},
'<abstract>':{
'size' : 12,
'bold' : True,
'lan' : True,
'next' : '<p>'
},
'<p>':{
'size' : 12,
'next' : '<p>',
'repeat' : True
},
'<trans-abstract>':{
'size' : 12,
'bold' : True,
'lan' : True,
'next' : '<p>'
},
'<kwd-group>':{
'size' : 12,
'regex' : r'(?i)(palabra.*clave.*:|keyword.*:)',
},
'<history>':{
'size' : 12,
'regex' : r'\d{2}/\d{2}/\d{4}',
},
'<corresp>':{
'size' : 12,
'regex' : r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}'
},
'<sec>':{
'size' : 16,
'bold' : True,
'next' : None
},
'<sub-sec>':{
'size' : 12,
'italic' : True,
'next' : None
},
'<sub-sec-2>':{
'size' : 14,
'bold' : True,
'next' : None
},
}

order_labels_body = {
'<sec>':{
'size' : 16,
'bold' : True,
},
'<sub-sec>':{
'size' : 12,
'italic' : True,
},
'<p>':{
'size' : 12,
},
}
1 change: 1 addition & 0 deletions markup_doc/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from wagtail.admin.forms.models import WagtailAdminModelForm
Loading
Loading