# Path: ngcrowd/helpers.py
# def get_utf_encoded_value(value):
#     return value.encode('utf-8').strip() if value else ''


from ngcrowd.models import *
from ngcrowd.helpers import get_utf_encoded_value
from sqlalchemy.orm import joinedload
from os import path, makedirs
from xml.etree.ElementTree import Element, SubElement, tostring
        from collections import OrderedDict
import csv
import shutil

        vrt_file = open(path.join(dir_destination, file_name + '.vrt'), 'w+')
        vrt_file.write(tostring(root))
        vrt_file.close()

    def __create_csvt_file(self, dir_destination, file_name):
        csvt_file = open(path.join(dir_destination, file_name + '.csvt'), 'w+')
        csvt_writer = csv.DictWriter(csvt_file, self.scheme)
        csvt_writer.writerow(self.scheme)
        csvt_file.close()

    def __create_readme_file(self, dir_destination, file_name='README.txt'):
        readmy_template_path = path.join(self.templates_dir, file_name)
        readmy_work = path.join(dir_destination, file_name)
        if path.exists(readmy_template_path):
            shutil.copy(readmy_template_path, readmy_work)

    def export(self, Uik):
        uik_csv = self.__temp_uik
        uik_csv['id'] = Uik[0].id
        uik_csv['lon'] = Uik[1]
        uik_csv['lat'] = Uik[2]
        uik_csv['number_official'] = Uik[0].number_official
        uik_csv['address_voting'] = get_utf_encoded_value(Uik[0].address_voting)
        uik_csv['place_voting'] = get_utf_encoded_value(Uik[0].place_voting)
        uik_csv['comment'] = get_utf_encoded_value(Uik[0].comment)
        uik_csv['is_applied'] = Uik[0].is_applied
        uik_csv['geocoding_precision'] = get_utf_encoded_value(Uik[0].geocoding_precision.name)
        uik_csv['tik'] = get_utf_encoded_value(Uik[0].tik.name)
        uik_csv['tik_id'] = Uik[0].tik.id

# Path: ngcrowd/helpers.py
# def get_utf_encoded_value(value):
#     return value.encode('utf-8').strip() if value else ''


# Path: ngcrowd/modules/export/export.py
from ngcrowd.models import *
from ngcrowd.helpers import get_utf_encoded_value
from sqlalchemy.orm import joinedload
from os import path, makedirs
from xml.etree.ElementTree import Element, SubElement, tostring
        from collections import OrderedDict
import csv
import shutil


        vrt_file = open(path.join(dir_destination, file_name + '.vrt'), 'w+')
        vrt_file.write(tostring(root))
        vrt_file.close()

    def __create_csvt_file(self, dir_destination, file_name):
        csvt_file = open(path.join(dir_destination, file_name + '.csvt'), 'w+')
        csvt_writer = csv.DictWriter(csvt_file, self.scheme)
        csvt_writer.writerow(self.scheme)
        csvt_file.close()

    def __create_readme_file(self, dir_destination, file_name='README.txt'):
        readmy_template_path = path.join(self.templates_dir, file_name)
        readmy_work = path.join(dir_destination, file_name)
        if path.exists(readmy_template_path):
            shutil.copy(readmy_template_path, readmy_work)

    def export(self, Uik):
        uik_csv = self.__temp_uik
        uik_csv['id'] = Uik[0].id
        uik_csv['lon'] = Uik[1]
        uik_csv['lat'] = Uik[2]
        uik_csv['number_official'] = Uik[0].number_official
        uik_csv['address_voting'] = get_utf_encoded_value(Uik[0].address_voting)
        uik_csv['place_voting'] = get_utf_encoded_value(Uik[0].place_voting)
        uik_csv['comment'] = get_utf_encoded_value(Uik[0].comment)
        uik_csv['is_applied'] = Uik[0].is_applied
        uik_csv['geocoding_precision'] = get_utf_encoded_value(Uik[0].geocoding_precision.name)
        uik_csv['tik'] = get_utf_encoded_value(Uik[0].tik.name)
        uik_csv['tik_id'] = Uik[0].tik.id

        uik_csv['region'] = get_utf_encoded_value(Uik[0].region.name)