Skip to content

Commit 5325a42

Browse files
authored
Merge pull request #490 from countable-web/develop
Develop
2 parents e83b057 + ee7457f commit 5325a42

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import pandas as pd
2+
3+
from django.core.management.base import BaseCommand
4+
5+
from language.models import Language, Community, CommunityLanguageStats
6+
7+
8+
class Command(BaseCommand):
9+
def handle(self, *args, **options):
10+
filename = options["filename"]
11+
check = options["check"] or 1
12+
update_language_stats(filename, check)
13+
14+
def add_arguments(self, parser):
15+
parser.add_argument(
16+
"--filename", nargs="?", type=str, help="Specify the filename"
17+
)
18+
parser.add_argument(
19+
"--check",
20+
nargs="?",
21+
type=int,
22+
help="Check if there are no missing data from the database",
23+
)
24+
25+
26+
def update_language_stats(filename, check=1):
27+
print("Reading ", filename)
28+
print("Check ", check)
29+
30+
df = pd.read_csv(filename)
31+
32+
if check:
33+
error = False
34+
35+
for index, row in df.iterrows():
36+
row_number = index + 1
37+
current_community = row["Community"]
38+
current_language = row["Language"]
39+
40+
try:
41+
Community.objects.get(name__unaccent__iexact=current_community)
42+
except Community.DoesNotExist:
43+
error = True
44+
print(f"Row {row_number} - Community not found: {current_community}")
45+
46+
try:
47+
Language.objects.get(name__unaccent__iexact=current_language)
48+
except Language.DoesNotExist:
49+
error = True
50+
print(f"Row {row_number} - Language not found: {current_language}")
51+
52+
if not error:
53+
print("File check passed")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Generated by Django 2.2.13 on 2023-11-13 06:27
2+
3+
from django.db import migrations
4+
from django.contrib.postgres.operations import UnaccentExtension
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
("language", "0141_auto_20230811_0256"),
10+
]
11+
12+
operations = [UnaccentExtension()]

web/web/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"django.contrib.gis",
5757
"django.contrib.sites",
5858
"django.contrib.sitemaps",
59+
"django.contrib.postgres",
5960
'django_filters',
6061
"rest_framework",
6162
"rest_framework.authtoken",

0 commit comments

Comments
 (0)