Skip to content

Fix for django 1.8+ (parsing args) and files in utf8 #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion teryt/management/commands/teryt_auto_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
class Command(BaseCommand):
help = 'Import TERYT data from ZIP files prepared by GUS,\
auto download, unpack and update with them.'
option_list = BaseCommand.option_list

def handle(self, *args, **options):
# download zip files from GUS site
Expand Down
23 changes: 13 additions & 10 deletions teryt/management/commands/teryt_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
already existing in database
"""

from optparse import make_option
import zipfile

from django.core.management.base import BaseCommand, CommandError
Expand All @@ -18,21 +17,25 @@
class Command(BaseCommand):
args = '[xml/zip file list]'
help = 'Import TERYT data from XML/ZIP files prepared by GUS'
option_list = BaseCommand.option_list + (
make_option('--update',
action='store_true',
dest='update',
default=False,
help='Update exisitng data'),
)

def add_arguments(self, parser):
parser.add_argument('file', nargs='+', type=str)
parser.add_argument(
'--update',
action='store_true',
dest='update',
default=False,
help='Update exisitng data'
)

def handle(self, *args, **options):
files = options['file']
force_ins = not options['update']

if not args:
if not files:
raise CommandError('At least 1 file name required')

for data_file in args:
for data_file in files:
self.stdout.write('Working on {}'.format(data_file))
if zipfile.is_zipfile(data_file):
zfile = zipfile.ZipFile(data_file)
Expand Down
2 changes: 2 additions & 0 deletions teryt/utils_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def update_database(xml_stream, fname, force_flag):
else x['SYM'])

for vals in row_list:
if len(vals) == 0:
continue
instance = teryt_class()
instance.set_val(vals)
instance.aktywny = True
Expand Down