Skip to content

Commit

Permalink
adds new field KeyWord.linked_to_cases
Browse files Browse the repository at this point in the history
  • Loading branch information
csae8092 committed Jul 8, 2024
1 parent fc73657 commit 891aabd
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 1 deletion.
1 change: 1 addition & 0 deletions archiv/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ class Meta:
"id",
"name",
"part_of",
"linked_to_cases",
]


Expand Down
3 changes: 2 additions & 1 deletion archiv/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def __init__(self, *args, **kwargs):
"id",
"name",
"part_of",
"linked_to_cases",
css_id="more",
)
)
Expand All @@ -207,7 +208,7 @@ def __init__(self, *args, **kwargs):
class KeyWordForm(forms.ModelForm):
class Meta:
model = KeyWord
fields = ["id", "name", "part_of", "introduction", "see_also"]
fields = ["id", "name", "part_of", "introduction", "see_also", "linked_to_cases"]

widgets = {
"see_also": autocomplete.ModelSelect2Multiple(
Expand Down
31 changes: 31 additions & 0 deletions archiv/migrations/0020_keyword_linked_to_cases_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 5.0 on 2024-07-08 05:58

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("archiv", "0019_alter_yearbook_options_remove_court_legacy_id_and_more"),
]

operations = [
migrations.AddField(
model_name="keyword",
name="linked_to_cases",
field=models.BooleanField(
default=True,
help_text="can be linked to cases",
verbose_name="can be linked to cases",
),
),
migrations.AlterField(
model_name="courtdecission",
name="file_number",
field=models.CharField(
blank=True,
help_text="Case number (file number/reference as cited in the given legal system, e.g. '[2010] UKSC 33' for a UK Supreme Court decision or 'VI ZR 548/12' for a German BGH decision)",
max_length=250,
verbose_name="Case number",
),
),
]
5 changes: 5 additions & 0 deletions archiv/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,11 @@ class KeyWord(models.Model):
verbose_name="Related to",
help_text="Related keyword(s)",
)
linked_to_cases = models.BooleanField(
default=True,
verbose_name="can be linked to cases",
help_text="can be linked to cases"
)

class Meta:
ordering = [
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
133 changes: 133 additions & 0 deletions notebooks/xissue_85__populate_linked_to_cases.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "5f8bcf70",
"metadata": {},
"outputs": [],
"source": [
"items = KeyWord.objects.filter(rvn_courtdecission_keyword_keyword=None)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ca0c2a1b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"55"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"items.count()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d860cbdb",
"metadata": {},
"outputs": [],
"source": [
"for x in items:\n",
" x.linked_to_cases = False\n",
" x.save()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9697abd3",
"metadata": {},
"outputs": [],
"source": [
"data = {}\n",
"for gr, ndf in df.groupby('legal_system__name'):\n",
" data[gr] = ndf.to_dict('records')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "779ed74b",
"metadata": {},
"outputs": [],
"source": [
"for key, value in data.items():\n",
" print(key)\n",
" for x in value:\n",
" print(x[\"name\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f5d743b9",
"metadata": {},
"outputs": [],
"source": [
"ndf = pd.DataFrame(new_data).reset_index().rename(columns={0: \"court_decissions\", \"keyword__count\": \"keywords\"})"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ee0445f9",
"metadata": {},
"outputs": [],
"source": [
"ndf"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c5c34f69",
"metadata": {},
"outputs": [],
"source": [
"for x in Court.objects.filter(orig_data_csv__icontains='gericht_hoechstgericht\": 1'):\n",
" x.is_high_court = True\n",
" x.save()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e68f2cae",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Django Shell-Plus",
"language": "python",
"name": "django_extensions"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
6 changes: 6 additions & 0 deletions notebooks/xissue_85__populatelinked_to_cases.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 891aabd

Please sign in to comment.