Skip to content

Commit 2939d72

Browse files
Merge pull request #1638 from IFRCGo/develop
Hotfix for pagination
2 parents 07e98b5 + e6314f4 commit 2939d72

File tree

19 files changed

+419
-17
lines changed

19 files changed

+419
-17
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## Unreleased
88

9+
## 1.1.467
10+
11+
### Added
12+
- Pagination fix (event, personnel)
13+
914
## 1.1.466
1015

1116
### Added
1217
- DREF Final Report finalization + new features
13-
- LocalUnits – first steps
18+
- LocalUnits
1419
- Event visibility fix
1520

1621
## 1.1.465
@@ -2133,7 +2138,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
21332138

21342139
## 0.1.20
21352140

2136-
[Unreleased]: https://github.com/IFRCGo/go-api/compare/1.1.466...HEAD
2141+
[Unreleased]: https://github.com/IFRCGo/go-api/compare/1.1.467...HEAD
2142+
[1.1.467]: https://github.com/IFRCGo/go-api/compare/1.1.466...1.1.467
21372143
[1.1.466]: https://github.com/IFRCGo/go-api/compare/1.1.465...1.1.466
21382144
[1.1.465]: https://github.com/IFRCGo/go-api/compare/1.1.464...1.1.465
21392145
[1.1.464]: https://github.com/IFRCGo/go-api/compare/1.1.463...1.1.464
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 3.2.16 on 2023-01-17 10:17
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api', '0160_merge_0159_auto_20221022_1542_0159_auto_20221028_0940'),
10+
]
11+
12+
operations = [
13+
migrations.AlterModelOptions(
14+
name='event',
15+
options={'ordering': ('-disaster_start_date', 'id'), 'verbose_name': 'emergency', 'verbose_name_plural': 'emergencies'},
16+
),
17+
]

api/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ class Event(models.Model):
605605
)
606606

607607
class Meta:
608-
ordering = ('-disaster_start_date',)
608+
ordering = ('-disaster_start_date', 'id',)
609609
verbose_name = _('emergency')
610610
verbose_name_plural = _('emergencies')
611611

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 3.2.16 on 2023-01-17 10:17
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('deployments', '0069_auto_20221022_1542'),
10+
]
11+
12+
operations = [
13+
migrations.AlterModelOptions(
14+
name='personnel',
15+
options={'ordering': ('deployment', 'country_to', 'country_from', 'molnix_id', 'deployedperson_ptr_id'), 'verbose_name': 'Personnel', 'verbose_name_plural': 'Personnels'},
16+
),
17+
]

deployments/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ def __str__(self):
210210
return '%s: %s - %s' % (self.type.upper(), self.name, self.role)
211211

212212
class Meta:
213+
ordering = ('deployment', 'country_to', 'country_from', 'molnix_id', 'deployedperson_ptr_id',)
213214
verbose_name = _('Personnel')
214215
verbose_name_plural = _('Personnels')
215216

deployments/snapshots/snap_tests.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@
416416
'target_total': 0
417417
},
418418
{
419-
'budget_amount_total': 6730000,
419+
'budget_amount_total': 7050000,
420420
'id': 31,
421421
'iso3': 'IBB',
422422
'name': 'country-TtOYzaCmFldtcpOlRYtastbgkeCJvBTOnPWtmzervxcfkMbqpf',
@@ -440,8 +440,8 @@
440440
{
441441
'budget_amount_total': 4260000,
442442
'id': 33,
443-
'iso3': 'STh',
444-
'name': 'country-GhslFoucligTrYZNfzfdSWfMLvoRjfavNEGPtQYlQIfZsPpOuh',
443+
'iso3': 'PNP',
444+
'name': 'country-TIuGhslFoucligTrYZNfzfdSWfMLvoRjfavNEGPtQYlQIfZsPp',
445445
'ongoing_projects': 1,
446446
'operation_types': [
447447
1
@@ -456,7 +456,7 @@
456456
'primary_sector_display': 'Health'
457457
}
458458
],
459-
'society_name': 'society-name-NKDMYIfFApbQgMPVWggwrZnUhBSCdfQshatRJHibAqQwyjPObO',
459+
'society_name': 'society-name-tSThNKDMYIfFApbQgMPVWggwrZnUhBSCdfQshatRJHibAqQwyj',
460460
'target_total': 0
461461
},
462462
{
@@ -485,16 +485,16 @@
485485
}
486486

487487
snapshots['TestProjectAPI::test_personnel_csv_api 1'] = '''event_id,event_glide_id,event_name,event_ifrc_severity_level,event_disaster_type,event_country_name,event_country_iso3,event_country_nationalsociety,event_country_regionname,role,type,name,deployed_id,deployed_to_name,deployed_to_iso3,deployed_to_nationalsociety,deployed_to_regionname,deployed_from_name,deployed_from_iso3,deployed_from_nationalsociety,deployed_from_regionname,start_date,end_date,ongoing,is_active,molnix_id,molnix_sector,molnix_role_profile,molnix_language,molnix_region,molnix_scope,molnix_modality,molnix_operation\r
488-
,,,,,,,,,,,,10,,,,,,,,,,,True,True,,,,,,,,\r
489-
,,,,,,,,,,,,9,,,,,,,,,,,True,True,,,,,,,,\r
490-
,,,,,,,,,,,,8,,,,,,,,,,,True,True,,,,,,,,\r
491-
,,,,,,,,,,,,7,,,,,,,,,,,True,True,,,,,,,,\r
492-
,,,,,,,,,,,,6,,,,,,,,,,,True,True,,,,,,,,\r
493-
,,,,,,,,,,,,5,,,,,,,,,,,True,True,,,,,,,,\r
494-
,,,,,,,,,,,,4,,,,,,,,,,,True,True,,,,,,,,\r
495-
,,,,,,,,,,,,3,,,,,,,,,,,True,True,,,,,,,,\r
496-
,,,,,,,,,,,,2,,,,,,,,,,,True,True,,,,,,,,\r
497488
,,,,,,,,,,,,1,,,,,,,,,,,True,True,,,,,,,,\r
489+
,,,,,,,,,,,,2,,,,,,,,,,,True,True,,,,,,,,\r
490+
,,,,,,,,,,,,3,,,,,,,,,,,True,True,,,,,,,,\r
491+
,,,,,,,,,,,,4,,,,,,,,,,,True,True,,,,,,,,\r
492+
,,,,,,,,,,,,5,,,,,,,,,,,True,True,,,,,,,,\r
493+
,,,,,,,,,,,,6,,,,,,,,,,,True,True,,,,,,,,\r
494+
,,,,,,,,,,,,7,,,,,,,,,,,True,True,,,,,,,,\r
495+
,,,,,,,,,,,,8,,,,,,,,,,,True,True,,,,,,,,\r
496+
,,,,,,,,,,,,9,,,,,,,,,,,True,True,,,,,,,,\r
497+
,,,,,,,,,,,,10,,,,,,,,,,,True,True,,,,,,,,\r
498498
'''
499499

500500
snapshots['TestProjectAPI::test_project_create 1'] = {

local_units/__init__.py

Whitespace-only changes.

local_units/admin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.contrib.gis import admin
2+
3+
from .models import LocalUnit, LocalUnitType
4+
5+
admin.site.register(LocalUnit, admin.OSMGeoAdmin)
6+
admin.site.register(LocalUnitType, admin.ModelAdmin)

local_units/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class LocalUnits(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'local_units'
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from django.db import transaction
2+
import csv
3+
from django.core.management.base import BaseCommand, CommandError
4+
from django.contrib.gis.geos import Point
5+
6+
from api.models import Country
7+
from ...models import LocalUnit, LocalUnitType
8+
9+
10+
class Command(BaseCommand):
11+
help = "Import LocalUnits data from CSV"
12+
missing_args_message = "Filename is missing. Filename / path to CSV file required. Required headers in CSV: distr_code, GOadm2code, ADM2"
13+
14+
def add_arguments(self, parser):
15+
parser.add_argument('filename', nargs='+', type=str)
16+
17+
@transaction.atomic
18+
def handle(self, *args, **options):
19+
filename = options['filename'][0]
20+
with open(filename) as csvfile:
21+
reader = csv.DictReader(csvfile)
22+
for row in reader:
23+
unit = LocalUnit()
24+
unit.country = Country.objects.get(iso3=row['ISO3'])
25+
unit.type, created = LocalUnitType.objects.get_or_create(
26+
level=row['TYPECODE'],
27+
name=row['TYPENAME']
28+
)
29+
if created:
30+
print(f'New LocalUnitType created: {unit.type.name}')
31+
32+
unit.name_loc = row['NAME_LOC']
33+
unit.name_en = row['NAME_EN']
34+
unit.branch_level = int(row['TYPECODE'])
35+
unit.postcode = int(row['POSTCODE']) if row['POSTCODE'] else None
36+
unit.address_loc = row['ADDRESS_LOC']
37+
unit.address_en = row['ADDRESS_EN']
38+
unit.city_loc = row['CITY_LOC']
39+
unit.city_en = row['CITY_EN']
40+
unit.focal_person_loc = row['FOCAL_PERSON_LOC']
41+
unit.focal_person_en = row['FOCAL_PERSON_EN']
42+
unit.phone = row['TELEPHONE']
43+
unit.email = row['EMAIL']
44+
unit.link = row['WEBSITE']
45+
unit.source_en = row['SOURCE_EN']
46+
unit.source_loc = row['SOURCE_LOC']
47+
unit.location = Point(float(row['LONGITUDE']), float(row['LATITUDE']))
48+
unit.save()
49+
print(f'{unit.name_en} saved')

0 commit comments

Comments
 (0)