Last active
February 7, 2016 06:37
-
-
Save gordonje/7b5cfd22e2800f602273 to your computer and use it in GitHub Desktop.
for checking tsv lines while cleaning.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# django-calaccess-raw-data/calaccess_raw/__init__.py | |
def get_model_from_file_name(file_name): | |
""" | |
Returns a calaccess_raw model to which the given .CSV or .TSV file maps | |
""" | |
from django.apps import apps | |
import re | |
model_name = re.sub(r'\.\w+', '', file_name).title().replace('_', '') | |
return apps.get_app_config("calaccess_raw").get_model(model_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
from calaccess_raw import get_download_directory, get_model_from_file_name | |
#... | |
class Command(CalAccessCommand): | |
# ... | |
def handle(self, *args, **options): | |
# ... | |
for tsv_line in tsv_file: | |
# ... | |
line_dict = dict(zip(field_names, csv_field_list)) | |
model = get_model_from_file_name(self.file_name) | |
model_inst = model(**line_dict) | |
model_inst.clean_fields() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment