summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/management/commands/import_geofla_csv.py17
-rw-r--r--ishtar_common/management/commands/import_insee_comm_csv.py20
-rw-r--r--ishtar_common/tests.py13
3 files changed, 36 insertions, 14 deletions
diff --git a/ishtar_common/management/commands/import_geofla_csv.py b/ishtar_common/management/commands/import_geofla_csv.py
index 7ef0e0a38..3ef5eff1c 100644
--- a/ishtar_common/management/commands/import_geofla_csv.py
+++ b/ishtar_common/management/commands/import_geofla_csv.py
@@ -34,18 +34,25 @@ class Command(BaseCommand):
parser.add_argument(
'--year', type=int, default=2014, dest='year',
help='Default year to affect to the town')
+ parser.add_argument(
+ '--quiet', dest='quiet', action='store_true',
+ help='Quiet output')
def handle(self, *args, **options):
csv_file = options['csv_file']
default_year = options['year']
- sys.stdout.write('* using year {} as a default\n'.format(default_year))
- sys.stdout.write('* Opening file {}\n'.format(csv_file))
+ quiet = options['quiet']
+ if not quiet:
+ sys.stdout.write('* using year {} as a default\n'.format(
+ default_year))
+ sys.stdout.write('* Opening file {}\n'.format(csv_file))
nb_created, nb_changed = 0, 0
with open(csv_file, 'rb') as csvfile:
reader = csv.DictReader(csvfile)
for idx, row in enumerate(reader):
- sys.stdout.write('Processing town %d.\r' % (idx + 1))
- sys.stdout.flush()
+ if not quiet:
+ sys.stdout.write('Processing town %d.\r' % (idx + 1))
+ sys.stdout.flush()
num_insee = row['INSEE_COM']
if len(num_insee) < 5:
num_insee = '0' + num_insee
@@ -79,6 +86,8 @@ class Command(BaseCommand):
if not created:
nb_changed += 1
town.save()
+ if quiet:
+ return
sys.stdout.write('\n* {} town created'.format(nb_created))
sys.stdout.write('\n* {} town changed\n'.format(nb_changed))
sys.stdout.flush()
diff --git a/ishtar_common/management/commands/import_insee_comm_csv.py b/ishtar_common/management/commands/import_insee_comm_csv.py
index 24eb2013e..d3bbc4a61 100644
--- a/ishtar_common/management/commands/import_insee_comm_csv.py
+++ b/ishtar_common/management/commands/import_insee_comm_csv.py
@@ -34,12 +34,18 @@ class Command(BaseCommand):
parser.add_argument(
'--year', type=int, default=2015, dest='year',
help='Year to affect to new towns')
+ parser.add_argument(
+ '--quiet', dest='quiet', action='store_true',
+ help='Quiet output')
def handle(self, *args, **options):
csv_file = options['csv_file']
default_year = options['year']
- sys.stdout.write('* using year {} for new towns\n'.format(default_year))
- sys.stdout.write('* opening file {}\n'.format(csv_file))
+ quiet = options['quiet']
+ if not quiet:
+ sys.stdout.write('* using year {} for new towns\n'.format(
+ default_year))
+ sys.stdout.write('* opening file {}\n'.format(csv_file))
r = re.compile(r"(.*)\((.*)\)")
nb_created = 0
nb_link = 0
@@ -49,8 +55,9 @@ class Command(BaseCommand):
with open(csv_file, 'rb') as csvfile:
reader = csv.DictReader(csvfile)
for idx, row in enumerate(reader):
- sys.stdout.write('Processing town %d.\r' % (idx + 1))
- sys.stdout.flush()
+ if not quiet:
+ sys.stdout.write('Processing town %d.\r' % (idx + 1))
+ sys.stdout.flush()
old_insee = row['DepComA']
if len(old_insee) < 5:
@@ -86,10 +93,13 @@ class Command(BaseCommand):
old_town.children.add(new_town)
linked.add(new_town)
nb_limit = 0
- sys.stdout.write('\nGenerate limits...'.format(nb_created))
+ if not quiet:
+ sys.stdout.write('\nGenerate limits...'.format(nb_created))
for town in linked:
if town.generate_geo():
nb_limit += 1
+ if quiet:
+ return
sys.stdout.write('\n* {} town created\n'.format(nb_created))
sys.stdout.write('* {} link created\n'.format(nb_link))
sys.stdout.write('* {} limit generated\n'.format(nb_limit))
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index a46a81070..7e852a770 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -115,10 +115,12 @@ class CommandsTestCase(TestCase):
town_nb = q.count()
out = StringIO()
call_command('import_geofla_csv',
- '../ishtar_common/tests/geofla-test.csv', stdout=out)
+ '../ishtar_common/tests/geofla-test.csv', '--quiet',
+ stdout=out)
self.assertEqual(town_nb + 9, models.Town.objects.count())
call_command('import_geofla_csv',
- '../ishtar_common/tests/geofla-test.csv', stdout=out)
+ '../ishtar_common/tests/geofla-test.csv', '--quiet',
+ stdout=out)
# no new town
self.assertEqual(town_nb + 9, models.Town.objects.count())
@@ -148,14 +150,15 @@ class CommandsTestCase(TestCase):
", " + ", ".join(reversed(union_end)) + ", 0 0, " + first + ")))"
out = StringIO()
call_command('import_insee_comm_csv',
- '../ishtar_common/tests/insee-test.csv', stdout=out)
+ '../ishtar_common/tests/insee-test.csv', '--quiet',
+ stdout=out)
self.assertEqual(town_nb + 1, models.Town.objects.count())
new = models.Town.objects.order_by('-pk').all()[0]
self.assertEqual(new.parents.count(), 2)
self.assertEqual(new.limit.wkt, union)
- call_command('import_insee_comm_csv',
+ call_command('import_insee_comm_csv', '--quiet',
'../ishtar_common/tests/insee-test.csv', stdout=out)
# no new town
self.assertEqual(town_nb + 1, models.Town.objects.count())
@@ -1081,7 +1084,7 @@ class IshtarSiteProfileTest(TestCase):
profile.files = True
profile.save()
response = c.get(reverse('start'))
- self.assertTrue("section-file_management" in response.content)
+ self.assertIn('href="/file_search/"', response.content)
def testExternalKey(self):
profile = models.get_current_profile()