# -*- coding: utf-8 -*-
from ..extensions import db
from ..models.administrative import ZUPC, Departement
from flask.ext.script import prompt_pass
from validate_email import validate_email
from . import manager
from sqlalchemy import create_engine, Table, Column, String, Integer, MetaData
import glob, os, csv, sqlalchemy
from geoalchemy2 import shape
from shapely import geometry, wkt
import json


@manager.command
def load_zupc(cs_zupc, zupc_path):

    with open(zupc_path) as f:
        for feature in json.load(f)['features']:
            wkb = shape.from_shape(geometry.shape(feature['geometry']))
            parent = ZUPC.query.filter_by(insee=feature['properties'][0]).first()
            for insee in feature['properties']:
                zupc = ZUPC.query.filter_by(insee=insee).first()
                if not zupc:
#This is the case in Paris and Lyon, but it's not important
                    continue
                zupc.shape = wkb
                zupc.parent_id = parent.id
            db.session.commit()

@@ -429,17 +429,8 @@
 upc(
-cs_zupc, 
 zupc
@@ -814,16 +814,230 @@
 t zupc:%0A
+                    zupc = ZUPC()%0A                    zupc.insee = insee%0A                    zupc.departement = parent.departement%0A                    zupc.nom = parent.nom%0A                    db.session.add(zupc)%0A
 #This is
@@ -1092,37 +1092,8 @@
 ant%0A
-                    continue%0A
     

Fix load ZUPC