-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into remove-ods-comms
- Loading branch information
Showing
66 changed files
with
578 additions
and
277 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,34 @@ | ||
defmodule DB.EPCI do | ||
@moduledoc """ | ||
EPCI schema | ||
EPCI schema. | ||
Link the EPCI to some Communes. | ||
The EPCI are loaded once and for all by the task transport/lib/transport/import_epci.ex | ||
The EPCI are loaded by the task transport/lib/transport/import_epci.ex. | ||
The EPCI imported are only "à fiscalité propre". This excludes Etablissements Publics Territoriaux. | ||
This allows to have a 1 to 1 relation between a commune and an EPCI. | ||
""" | ||
use Ecto.Schema | ||
use TypedEctoSchema | ||
import Ecto.Changeset | ||
|
||
typed_schema "epci" do | ||
field(:code, :string) | ||
field(:insee, :string) | ||
field(:nom, :string) | ||
field(:type, :string) | ||
field(:mode_financement, :string) | ||
field(:geom, Geo.PostGIS.Geometry) :: Geo.MultiPolygon.t() | ||
has_many(:communes, DB.Commune, foreign_key: :epci_insee) | ||
end | ||
|
||
# for the moment we don't need a link relational link to the Commune table, | ||
# so we only store an array of insee code | ||
field(:communes_insee, {:array, :string}, default: []) | ||
def changeset(epci, attrs) do | ||
epci | ||
|> cast(attrs, [:insee, :nom, :geom, :type, :mode_financement]) | ||
|> validate_required([:insee, :nom, :geom, :type, :mode_financement]) | ||
|> validate_inclusion(:type, allowed_types()) | ||
|> validate_inclusion(:mode_financement, allowed_mode_financement()) | ||
end | ||
|
||
defp allowed_types, | ||
do: ["Communauté d'agglomération", "Communauté urbaine", "Communauté de communes", "Métropole", "Métropole de Lyon"] | ||
|
||
defp allowed_mode_financement, do: ["Fiscalité professionnelle unique", "Fiscalité additionnelle"] | ||
end |
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
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
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
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
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
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
Oops, something went wrong.