From 09d62500747866f70be69fb6d08b55a206f18138 Mon Sep 17 00:00:00 2001 From: GabrielCastelo-31 Date: Wed, 21 Feb 2024 22:14:27 -0300 Subject: [PATCH 1/6] Add department name to Department Model --- api/api/migrations/0009_department_name.py | 18 ++++++++++++++++++ api/api/models.py | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 api/api/migrations/0009_department_name.py diff --git a/api/api/migrations/0009_department_name.py b/api/api/migrations/0009_department_name.py new file mode 100644 index 0000000..cc7b85b --- /dev/null +++ b/api/api/migrations/0009_department_name.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.10 on 2024-02-22 01:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0008_schedule_created_at'), + ] + + operations = [ + migrations.AddField( + model_name='department', + name='name', + field=models.CharField(default='', max_length=128), + ), + ] diff --git a/api/api/models.py b/api/api/models.py index e3cf823..d2f1d6c 100644 --- a/api/api/models.py +++ b/api/api/models.py @@ -16,7 +16,7 @@ def delete(self, *args, **kwargs): try: cache.delete(kwargs['cache_key']) kwargs.pop('cache_key') - except: # pragma: no cover + except: # pragma: no cover raise ValueError(cache_error_msg) else: super(CustomModel, self).delete() @@ -29,6 +29,7 @@ class Department(CustomModel): year:str -> Ano do departamento period:str -> Período do departamento """ + name = models.CharField(max_length=128, default='') code = models.CharField(max_length=10) year = models.CharField(max_length=4, default='0000') period = models.CharField(max_length=1, default='1') From 38e3497451bfac4a9334c4c1619458074ae3fa6a Mon Sep 17 00:00:00 2001 From: GabrielCastelo-31 Date: Wed, 21 Feb 2024 22:20:47 -0300 Subject: [PATCH 2/6] update dbhandler to create department with name --- api/utils/db_handler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/utils/db_handler.py b/api/utils/db_handler.py index 08e4cb7..989d404 100644 --- a/api/utils/db_handler.py +++ b/api/utils/db_handler.py @@ -15,9 +15,9 @@ """Este módulo lida com as operações de banco de dados.""" -def get_or_create_department(code: str, year: str, period: str) -> Department: +def get_or_create_department(code: str, name: str, year: str, period: str) -> Department: """Cria um departamento.""" - return Department.objects.get_or_create(code=code, year=year, period=period)[0] + return Department.objects.get_or_create(code=code, name=name, year=year, period=period)[0] def get_or_create_discipline(name: str, code: str, department: Department) -> Discipline: From bd02b96a24a03527a8fc4fc48fd4330eb9c49469 Mon Sep 17 00:00:00 2001 From: GabrielCastelo-31 Date: Wed, 21 Feb 2024 22:26:54 -0300 Subject: [PATCH 3/6] update admin visualization for departments --- api/api/admin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/api/admin.py b/api/api/admin.py index 035d2d0..29ab991 100644 --- a/api/api/admin.py +++ b/api/api/admin.py @@ -6,9 +6,9 @@ @admin.register(Department) class DepartmentAdmin(admin.ModelAdmin): - list_display = ['code', 'year', 'period'] - search_fields = ['code'] - ordering = ['year', 'period'] + list_display = ['name', 'code', 'year', 'period'] + search_fields = ['code', 'name'] + ordering = ['year', 'period', 'name'] @admin.register(Discipline) From 9b8dcafd899f6b923be29e9acdbcfaa31ac71492 Mon Sep 17 00:00:00 2001 From: GabrielCastelo-31 Date: Wed, 21 Feb 2024 22:31:02 -0300 Subject: [PATCH 4/6] update webscraping to get department name --- api/utils/web_scraping.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/api/utils/web_scraping.py b/api/utils/web_scraping.py index e6db21e..fc69243 100644 --- a/api/utils/web_scraping.py +++ b/api/utils/web_scraping.py @@ -25,7 +25,7 @@ ''' -def get_list_of_departments(response=get_response(create_request_session())) -> Optional[List]: +def get_list_of_departments(response=get_response(create_request_session())) -> Optional[tuple[list[str], list[str]]]: """Obtem a lista de departamentos da UnB.""" soup = BeautifulSoup( response.content, "html.parser") # Create a BeautifulSoup object @@ -38,14 +38,15 @@ def get_list_of_departments(response=get_response(create_request_session())) -> # Find all