Skip to content

Commit 105960b

Browse files
Black
1 parent d29f4bf commit 105960b

6 files changed

Lines changed: 166 additions & 44 deletions

File tree

backend/langpro_annotator/proxy_frontend.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
from django.views.decorators.csrf import ensure_csrf_cookie
33

44
from revproxy.views import ProxyView
5+
56
view = ProxyView.as_view(upstream=settings.PROXY_FRONTEND)
67

8+
79
@ensure_csrf_cookie
810
def proxy_frontend(*args, **kwargs):
9-
""" Wrapper for calls to the SPA ensuring the precense of a CSRF cookie."""
11+
"""Wrapper for calls to the SPA ensuring the presence of a CSRF cookie."""
1012
global view
1113
return view(*args, **kwargs)

backend/langpro_annotator/urls.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
1. Import the include() function: from django.conf.urls import include, path
1414
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1515
"""
16+
1617
from django.conf import settings
1718
from django.urls import path, re_path, include
1819
from django.contrib import admin
@@ -28,21 +29,24 @@
2829

2930

3031
if settings.PROXY_FRONTEND:
31-
spa_url = re_path(r'^(?P<path>.*)$', proxy_frontend)
32+
spa_url = re_path(r"^(?P<path>.*)$", proxy_frontend)
3233
else:
33-
spa_url = re_path(r'', index)
34+
spa_url = re_path(r"", index)
3435

3536
urlpatterns = [
36-
path('admin', RedirectView.as_view(url='/admin/', permanent=True)),
37-
path('api', RedirectView.as_view(url='/api/', permanent=True)),
38-
path('api-auth', RedirectView.as_view(url='/api-auth/', permanent=True)),
39-
path('admin/', admin.site.urls),
40-
path('api/', include(api_router.urls)),
41-
path('api-auth/', include(
42-
'rest_framework.urls',
43-
namespace='rest_framework',
44-
)),
45-
path('api/i18n/', i18n),path("users/", include("user.urls")),
46-
37+
path("admin", RedirectView.as_view(url="/admin/", permanent=True)),
38+
path("api", RedirectView.as_view(url="/api/", permanent=True)),
39+
path("api-auth", RedirectView.as_view(url="/api-auth/", permanent=True)),
40+
path("admin/", admin.site.urls),
41+
path("api/", include(api_router.urls)),
42+
path(
43+
"api-auth/",
44+
include(
45+
"rest_framework.urls",
46+
namespace="rest_framework",
47+
),
48+
),
49+
path("api/i18n/", i18n),
50+
path("users/", include("user.urls")),
4751
spa_url, # catch-all; unknown paths to be handled by a SPA
4852
]

backend/problem/apps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class ProblemConfig(AppConfig):
5-
default_auto_field = 'django.db.models.BigAutoField'
6-
name = 'problem'
5+
default_auto_field = "django.db.models.BigAutoField"
6+
name = "problem"

backend/problem/management/commands/import_fracas.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ def annotate_section_subsections(self, tree: ET.ElementTree) -> None:
3636
element.tag == "comment" and element.attrib.get("class") == "subsection"
3737
):
3838
current_subsection = element.text.strip()
39-
elif element.tag == "comment" and element.attrib.get("class") == "subsubsection":
39+
elif (
40+
element.tag == "comment"
41+
and element.attrib.get("class") == "subsubsection"
42+
):
4043
current_subsubsection = element.text.strip()
4144
elif element.tag == "problem":
4245
if current_section:

backend/problem/migrations/0001_initial.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,46 @@ class Migration(migrations.Migration):
88

99
initial = True
1010

11-
dependencies = [
12-
]
11+
dependencies = []
1312

1413
operations = [
1514
migrations.CreateModel(
16-
name='SickProblem',
15+
name="SickProblem",
1716
fields=[
18-
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19-
('pair_id', models.IntegerField(unique=True)),
20-
('sentence_one', models.CharField(max_length=255)),
21-
('sentence_two', models.CharField(max_length=255)),
22-
('entailment_label', models.CharField(choices=[('neutral', 'Neutral'), ('contradiction', 'Contradiction'), ('entailment', 'Entailment')], max_length=20)),
23-
('relatedness_score', models.DecimalField(decimal_places=3, max_digits=4, validators=[django.core.validators.MinValueValidator(1), django.core.validators.MinValueValidator(5)])),
17+
(
18+
"id",
19+
models.BigAutoField(
20+
auto_created=True,
21+
primary_key=True,
22+
serialize=False,
23+
verbose_name="ID",
24+
),
25+
),
26+
("pair_id", models.IntegerField(unique=True)),
27+
("sentence_one", models.CharField(max_length=255)),
28+
("sentence_two", models.CharField(max_length=255)),
29+
(
30+
"entailment_label",
31+
models.CharField(
32+
choices=[
33+
("neutral", "Neutral"),
34+
("contradiction", "Contradiction"),
35+
("entailment", "Entailment"),
36+
],
37+
max_length=20,
38+
),
39+
),
40+
(
41+
"relatedness_score",
42+
models.DecimalField(
43+
decimal_places=3,
44+
max_digits=4,
45+
validators=[
46+
django.core.validators.MinValueValidator(1),
47+
django.core.validators.MinValueValidator(5),
48+
],
49+
),
50+
),
2451
],
2552
),
2653
]

backend/problem/migrations/0002_fracasproblem_fracaspremise.py

Lines changed: 104 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,121 @@
77
class Migration(migrations.Migration):
88

99
dependencies = [
10-
('problem', '0001_initial'),
10+
("problem", "0001_initial"),
1111
]
1212

1313
operations = [
1414
migrations.CreateModel(
15-
name='FracasProblem',
15+
name="FracasProblem",
1616
fields=[
17-
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18-
('fracas_id', models.IntegerField(unique=True)),
19-
('question', models.CharField(help_text='The question from the original FraCaS problem. 4 problems do not have a question.', max_length=255)),
20-
('hypothesis', models.CharField(help_text='The answer formulated as a hypothesis by McCartney.', max_length=255)),
21-
('answer', models.CharField(help_text='The answer from the original FraCaS problem. Most are "Yes", "No", or "Don\'t know", but not always.', max_length=255)),
22-
('fracas_answer', models.CharField(choices=[('yes', 'Yes'), ('no', 'No'), ('unknown', 'Unknown'), ('undef', 'Undef')], help_text='The answer constrained to one of a fixed set of values by McCartney.', max_length=20)),
23-
('fracas_non_standard', models.BooleanField(help_text='Indicates whether the answer in the origianl FraCaS problem is non-standard (i.e. not "Yes", "No", or "Don\'t know")')),
24-
('note', models.TextField(help_text='Note given by McCartney to explain issues arising during translation to XML.')),
25-
('section_name', models.CharField(help_text='The section name from the original FraCaS problem.', max_length=255)),
26-
('subsection_name', models.CharField(help_text='The subsection name from the original FraCaS problem.', max_length=255)),
17+
(
18+
"id",
19+
models.BigAutoField(
20+
auto_created=True,
21+
primary_key=True,
22+
serialize=False,
23+
verbose_name="ID",
24+
),
25+
),
26+
("fracas_id", models.IntegerField(unique=True)),
27+
(
28+
"question",
29+
models.CharField(
30+
help_text="The question from the original FraCaS problem. 4 problems do not have a question.",
31+
max_length=255,
32+
),
33+
),
34+
(
35+
"hypothesis",
36+
models.CharField(
37+
help_text="The answer formulated as a hypothesis by McCartney.",
38+
max_length=255,
39+
),
40+
),
41+
(
42+
"answer",
43+
models.CharField(
44+
help_text='The answer from the original FraCaS problem. Most are "Yes", "No", or "Don\'t know", but not always.',
45+
max_length=255,
46+
),
47+
),
48+
(
49+
"fracas_answer",
50+
models.CharField(
51+
choices=[
52+
("yes", "Yes"),
53+
("no", "No"),
54+
("unknown", "Unknown"),
55+
("undef", "Undef"),
56+
],
57+
help_text="The answer constrained to one of a fixed set of values by McCartney.",
58+
max_length=20,
59+
),
60+
),
61+
(
62+
"fracas_non_standard",
63+
models.BooleanField(
64+
help_text='Indicates whether the answer in the origianl FraCaS problem is non-standard (i.e. not "Yes", "No", or "Don\'t know")'
65+
),
66+
),
67+
(
68+
"note",
69+
models.TextField(
70+
help_text="Note given by McCartney to explain issues arising during translation to XML."
71+
),
72+
),
73+
(
74+
"section_name",
75+
models.CharField(
76+
help_text="The section name from the original FraCaS problem.",
77+
max_length=255,
78+
),
79+
),
80+
(
81+
"subsection_name",
82+
models.CharField(
83+
help_text="The subsection name from the original FraCaS problem.",
84+
max_length=255,
85+
),
86+
),
2787
],
2888
),
2989
migrations.CreateModel(
30-
name='FracasPremise',
90+
name="FracasPremise",
3191
fields=[
32-
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
33-
('premise_index', models.IntegerField(help_text='The index of the premise in the original FraCaS problem.')),
34-
('premise', models.CharField(help_text='The premise from the original FraCaS problem.', max_length=255)),
35-
('fracas_problem', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='premises', to='problem.fracasproblem')),
92+
(
93+
"id",
94+
models.BigAutoField(
95+
auto_created=True,
96+
primary_key=True,
97+
serialize=False,
98+
verbose_name="ID",
99+
),
100+
),
101+
(
102+
"premise_index",
103+
models.IntegerField(
104+
help_text="The index of the premise in the original FraCaS problem."
105+
),
106+
),
107+
(
108+
"premise",
109+
models.CharField(
110+
help_text="The premise from the original FraCaS problem.",
111+
max_length=255,
112+
),
113+
),
114+
(
115+
"fracas_problem",
116+
models.ForeignKey(
117+
on_delete=django.db.models.deletion.CASCADE,
118+
related_name="premises",
119+
to="problem.fracasproblem",
120+
),
121+
),
36122
],
37123
options={
38-
'unique_together': {('fracas_problem', 'premise_index')},
124+
"unique_together": {("fracas_problem", "premise_index")},
39125
},
40126
),
41127
]

0 commit comments

Comments
 (0)