0001-sector-add-a-sector_name-column-for-readability-5702.patch
passerelle/apps/sector/migrations/0001_initial.py | ||
---|---|---|
51 | 51 |
'titles_in_first_line', |
52 | 52 |
models.BooleanField( |
53 | 53 |
default=True, |
54 |
help_text='If not, column titles are: street_id,parity,min_housenumber,max_housenumber,sector_id,sector_name, …', |
|
54 |
help_text='If not, column titles are: street_id,street_name,parity,min_housenumber,max_housenumber,sector_id,sector_name, …',
|
|
55 | 55 |
verbose_name='First line defines column titles', |
56 | 56 |
), |
57 | 57 |
), |
... | ... | |
87 | 87 |
), |
88 | 88 |
( |
89 | 89 |
'min_housenumber', |
90 |
models.PositiveIntegerField(default=0, verbose_name='Minimal house number'),
|
|
90 |
models.PositiveIntegerField(default=0, verbose_name='Minimum house number (included)'),
|
|
91 | 91 |
), |
92 | 92 |
( |
93 | 93 |
'max_housenumber', |
94 |
models.PositiveIntegerField(default=999999, verbose_name='Maximal house number'),
|
|
94 |
models.PositiveIntegerField(default=999999, verbose_name='Maximum house number (included)'),
|
|
95 | 95 |
), |
96 | 96 |
( |
97 | 97 |
'sector', |
passerelle/apps/sector/migrations/0002_sectorization_street_name.py | ||
---|---|---|
1 |
# Generated by Django 2.2.19 on 2021-10-15 11:38 |
|
2 | ||
3 |
from django.db import migrations, models |
|
4 | ||
5 | ||
6 |
class Migration(migrations.Migration): |
|
7 | ||
8 |
dependencies = [ |
|
9 |
('sector', '0001_initial'), |
|
10 |
] |
|
11 | ||
12 |
operations = [ |
|
13 |
migrations.AddField( |
|
14 |
model_name='sectorization', |
|
15 |
name='street_name', |
|
16 |
field=models.CharField(blank=True, max_length=150, verbose_name='Street Name'), |
|
17 |
), |
|
18 |
] |
passerelle/apps/sector/models.py | ||
---|---|---|
43 | 43 |
(PARITY_EVEN, _('even')), |
44 | 44 |
) |
45 | 45 | |
46 |
CSV_TITLES = ['street_id', 'parity', 'min_housenumber', 'max_housenumber', 'sector_id', 'sector_name'] |
|
46 |
CSV_TITLES = [ |
|
47 |
'street_id', |
|
48 |
'street_name', |
|
49 |
'parity', |
|
50 |
'min_housenumber', |
|
51 |
'max_housenumber', |
|
52 |
'sector_id', |
|
53 |
'sector_name', |
|
54 |
] |
|
47 | 55 | |
48 | 56 |
MAX_HOUSENUMBER = 999_999 |
49 | 57 | |
... | ... | |
194 | 202 |
parity=parity, |
195 | 203 |
min_housenumber=min_housenumber, |
196 | 204 |
max_housenumber=max_housenumber, |
205 |
street_name=row['street_name'], |
|
197 | 206 |
) |
198 | 207 | |
199 | 208 |
@endpoint( |
... | ... | |
267 | 276 |
writer.writerow( |
268 | 277 |
[ |
269 | 278 |
sectorization.street_id, |
279 |
sectorization.street_name, |
|
270 | 280 |
parity.get(sectorization.parity, mix), |
271 | 281 |
sectorization.min_housenumber if (limits or sectorization.min_housenumber) else '', |
272 | 282 |
sectorization.max_housenumber |
... | ... | |
351 | 361 |
class Sectorization(models.Model): |
352 | 362 |
sector = models.ForeignKey(Sector, on_delete=models.CASCADE, verbose_name=_('Sector')) |
353 | 363 |
street_id = models.CharField(max_length=64, verbose_name=_('Street Identifier')) |
364 |
street_name = models.CharField(max_length=150, verbose_name=_('Street Name'), blank=True) |
|
354 | 365 |
parity = models.SmallIntegerField( |
355 | 366 |
choices=PARITY_CHOICES, default=PARITY_ALL, verbose_name=_('Parity of numbers') |
356 | 367 |
) |
... | ... | |
365 | 376 |
ordering = ['street_id', 'min_housenumber', 'parity'] |
366 | 377 | |
367 | 378 |
def __str__(self): |
379 |
if self.street_name: |
|
380 |
street = '%s (%s)' % (self.street_id, self.street_name) |
|
381 |
else: |
|
382 |
street = self.street_id |
|
368 | 383 |
return '%s, parity:%s, min:%s, max:%s → %s' % ( |
369 |
self.street_id,
|
|
384 |
street,
|
|
370 | 385 |
dict(PARITY_CHOICES).get(self.parity), |
371 | 386 |
self.min_housenumber, |
372 | 387 |
self.max_housenumber, |
tests/test_address.py | ||
---|---|---|
206 | 206 |
"version": "draft", |
207 | 207 |
} |
208 | 208 | |
209 |
CSV = """street_id,parity,min_housenumber,max_housenumber,sector_id,sector_name |
|
210 |
75114_1912,P,,,gs-moulin,Groupe Scolaire Moulin |
|
211 |
75114_1912,I,0,167,gs-zola,Groupe Scolaire Zola |
|
212 |
75114_1912,I,168,999999,ecole-hugo,École Hugo |
|
213 |
75114_1913,,,,ecole-pascal,École Pascal |
|
209 |
CSV = """street_id,street_name,parity,min_housenumber,max_housenumber,sector_id,sector_name
|
|
210 |
75114_1912,rue du Château,P,,,gs-moulin,Groupe Scolaire Moulin
|
|
211 |
75114_1912,rue du Château,I,0,167,gs-zola,Groupe Scolaire Zola
|
|
212 |
75114_1912,rue du Château,I,168,999999,ecole-hugo,École Hugo
|
|
213 |
75114_1913,rue 1913,,,,ecole-pascal,École Pascal
|
|
214 | 214 |
""" |
215 | 215 | |
216 | 216 |
tests/test_sector.py | ||
---|---|---|
34 | 34 |
from passerelle.apps.sector.models import Sectorization, SectorResource |
35 | 35 |
from passerelle.base.models import AccessRight |
36 | 36 | |
37 |
CSV = """street_id,parity,min_housenumber,max_housenumber,sector_id,sector_name |
|
38 |
75114_1912,P,,, gs-moulin, Groupe Scolaire Moulin |
|
39 |
75114_1912,I,0,999999,gs-zola,Groupe Scolaire Zola |
|
40 |
75114_1913,N,0,999999,ecole-hugo,École Hugo |
|
41 |
75114_1914,,,10,ecole-hugo, École Hugo |
|
42 | ||
43 |
75114_1914,,11,, ecole-hugo2, École Hugo 2 |
|
44 |
75114_1915,,,,ecole-hugo2 , École Hugo 2 |
|
37 |
CSV = """street_id,street_name,parity,min_housenumber,max_housenumber,sector_id,sector_name
|
|
38 |
75114_1912,rue du Château,P,,, gs-moulin, Groupe Scolaire Moulin
|
|
39 |
75114_1912,rue du Château,I,0,999999,gs-zola,Groupe Scolaire Zola
|
|
40 |
75114_1913,rue des Moulins ,N,0,999999,ecole-hugo,École Hugo
|
|
41 |
75114_1914,rue du Vent,,,10,ecole-hugo, École Hugo
|
|
42 | ||
43 |
75114_1914,rue du Vent,,11,, ecole-hugo2, École Hugo 2
|
|
44 |
75114_1915, ,,,,ecole-hugo2 , École Hugo 2
|
|
45 | 45 |
""" |
46 | 46 | |
47 | 47 |
CSV_BOM = force_str(force_text(CSV, 'utf-8').encode('utf-8-sig')) |
48 | 48 | |
49 |
CSV_NO_FIRST_LINE = """75114_1912,P,,, gs-moulin, Groupe Scolaire Moulin |
|
50 |
75114_1912,I,0,999999,gs-zola,Groupe Scolaire Zola |
|
51 |
75114_1913,N,0,999999,ecole-hugo,École Hugo |
|
52 |
75114_1914,,,10,ecole-hugo, École Hugo |
|
49 |
CSV_NO_FIRST_LINE = """75114_1912,rue du Château,P,,, gs-moulin, Groupe Scolaire Moulin
|
|
50 |
75114_1912,rue du Château,I,0,999999,gs-zola,Groupe Scolaire Zola
|
|
51 |
75114_1913,,N,0,999999,ecole-hugo,École Hugo
|
|
52 |
75114_1914,rue du Vent,,,10,ecole-hugo, École Hugo
|
|
53 | 53 | |
54 |
75114_1914,,11,, ecole-hugo, École Hugo""" |
|
54 |
75114_1914,rue du Vent,,11,, ecole-hugo, École Hugo"""
|
|
55 | 55 | |
56 |
CSV_REORDERED = """sector_id,sector_name,street_id,parity,min_housenumber,max_housenumber,foo,bar |
|
57 |
gs-moulin, Groupe Scolaire Moulin, 75114_1912,P,,,aaa,bbb |
|
58 |
gs-zola,Groupe Scolaire Zola,75114_1912,I,0,999999,xxx,yyy |
|
59 |
ecole-hugo,École Hugo,75114_1913,N,0,999999,000,1 |
|
60 |
,,75114_1999,N,0,999999,, |
|
56 |
CSV_REORDERED = """sector_id,sector_name,street_id,parity,min_housenumber,max_housenumber,foo,street_name,bar
|
|
57 |
gs-moulin, Groupe Scolaire Moulin, 75114_1912,P,,,aaa,rue du Château,bbb
|
|
58 |
gs-zola,Groupe Scolaire Zola,75114_1912,I,0,999999,xxx,rue du Château,yyy
|
|
59 |
ecole-hugo,École Hugo,75114_1913,N,0,999999,000,rue des Moulins,1
|
|
60 |
,,75114_1999,N,0,999999,,avenue 999,
|
|
61 | 61 |
""" |
62 | 62 | |
63 |
CSV_MISSING_COLUMN = """street_id,min_housenumber,max_housenumber,sector_id,sector_name |
|
64 |
75114_1912,,,foo, |
|
65 |
,0,999999,gs-zola,Groupe Scolaire Zola""" |
|
63 |
CSV_MISSING_COLUMN = """street_id,street_name,min_housenumber,max_housenumber,sector_id,sector_name
|
|
64 |
75114_1912,,,,foo,
|
|
65 |
,,0,999999,gs-zola,Groupe Scolaire Zola"""
|
|
66 | 66 | |
67 |
CSV_MISSING_SECTOR = """street_id,parity,min_housenumber,max_housenumber,sector_id,sector_name |
|
68 |
75114_1912,P,,, , |
|
69 |
75114_1912,I,0,999999,gs-zola,Groupe Scolaire Zola""" |
|
67 |
CSV_MISSING_SECTOR = """street_id,street_name,parity,min_housenumber,max_housenumber,sector_id,sector_name
|
|
68 |
75114_1912,rue du Château,P,,, ,
|
|
69 |
75114_1912,rue du Château,I,0,999999,gs-zola,Groupe Scolaire Zola"""
|
|
70 | 70 | |
71 |
CSV_MISSING_STREET = """street_id,parity,min_housenumber,max_housenumber,sector_id,sector_name |
|
72 |
75114_1912,P,,,foo, |
|
73 |
,I,0,999999,gs-zola,Groupe Scolaire Zola""" |
|
71 |
CSV_MISSING_STREET = """street_id,street_name,parity,min_housenumber,max_housenumber,sector_id,sector_name
|
|
72 |
75114_1912,,P,,,foo,
|
|
73 |
,,I,0,999999,gs-zola,Groupe Scolaire Zola"""
|
|
74 | 74 | |
75 | 75 |
pytestmark = pytest.mark.django_db |
76 | 76 | |
... | ... | |
89 | 89 |
def test_sector_creation(sector): |
90 | 90 |
assert '%s' % sector == 'title [test]' |
91 | 91 |
assert sector.sector_set.count() == 4 |
92 |
rue1913 = Sectorization.objects.get(street_id='75114_1913') |
|
93 |
assert rue1913.street_name == 'rue des Moulins' |
|
94 |
assert ( |
|
95 |
'%s' % rue1913 |
|
96 |
== '75114_1913 (rue des Moulins), parity:all, min:0, max:999999 → title [test] > École Hugo [ecole-hugo]' |
|
97 |
) |
|
98 |
rue1915 = Sectorization.objects.get(street_id='75114_1915') |
|
99 |
assert rue1915.street_name == '' |
|
100 |
assert ( |
|
101 |
'%s' % rue1915 |
|
102 |
== '75114_1915, parity:all, min:0, max:999999 → title [test] > École Hugo 2 [ecole-hugo2]' |
|
103 |
) |
|
104 | ||
92 | 105 |
hugo = sector.sector_set.get(slug='ecole-hugo') |
93 | 106 |
assert Sectorization.objects.filter(sector=hugo).count() == 2 |
94 | 107 |
hugo2 = sector.sector_set.get(slug='gs-zola') |
... | ... | |
242 | 255 |
resp = app.get(url) |
243 | 256 |
assert resp.headers['content-type'] == 'text/csv' |
244 | 257 |
assert resp.text.startswith( |
245 |
'"street_id","parity","min_housenumber","max_housenumber","sector_id","sector_name"' |
|
258 |
'"street_id","street_name","parity","min_housenumber","max_housenumber","sector_id","sector_name"'
|
|
246 | 259 |
) |
247 | 260 |
assert len(resp.text.splitlines()) == 7 |
248 | 261 |
sector.titles_in_first_line = False |
249 |
- |