Commit 72f8fecb authored by François Ferry's avatar François Ferry
Browse files

Apply 9 suggestion(s) to 1 file(s)

parent 523c29275ac9
Pipeline #29728 failed with stages
in 6 minutes and 12 seconds
......@@ -19,7 +19,7 @@ There are several ways to import data in CubicWeb; in this tutorial, we will use
the others are described here: :ref:`dataimport`.
First of all, we define in :file:`cubicweb-tuto/dataimport.py` a function which will read a file
from a `filepath` and create from read data entities, using a `CubicWeb connection`:
from a `filepath` and create the corresponding entities, using a `CubicWeb connection`:
.. sourcecode:: python
......@@ -71,24 +71,24 @@ To be sure we don't have several time the same city, we first query CubicWeb to
existing city. To do this, we use a specific language called **RQL**. As for SPARQL, it's a
query language designed to query linked data. See :ref:`rql_intro` for more information about it.
Then, we put existing cities in a dictionary, using zip code as key (a zip code can concern
several cities, but it's not really an issue in this tutorial).
Then, we put existing cities in a dictionary, using zip code as key. In the real world, a zip code
can concern several cities, but it's not really an issue in this tutorial.
For each line of our `csv` file, we will see if we already have the city in our base (then in
our dictionary). If not, we create it. Then, we create our Museum entity with all needed arguments.
For each line of our `csv` file, we will check if we already have the city in our base.
If not, we create it. Then, we create our Museum entity with all needed arguments.
To create an entity, we use `create_entity` method of our CubicWeb connection. This method take
To create an entity, we use the `create_entity` method of the CubicWeb connection. This method takes
as first argument the type of the entity (ie: the name of the corresponding class previously
defined in :file:`cubicweb-tuto/schema.py`), and then all arguments of the entity type.
In our example, a city need a name and a zip code; and a museum need name, a postal address,
In our example, a city needs a name and a zip code. A museum needs a name, a postal address,
a latitude, a longitude and a city. As `is_in` is a relation, we give to the corresponding argument
the eid of the city.
.. Note::
As we have defined Museum in the schema, we have to link each instance of Museum to a City,
that's why we create city before museum, and give this city as argument of the museum.
that's why we create the city before the museum, and give this city as argument of the museum.
If the city wasn't mandatory, we could add it later, using:
......@@ -96,7 +96,7 @@ the eid of the city.
museum_entity.cw_set(is_in=city)
Now we have our function we need to create a CubicWeb command using it. First, we create a file
To use our function we need to create a CubicWeb command that will call it. First, we create a file
:file:`cubicweb-tuto/ccplugin.py` (the name doesn't matter, but it is commonly used for all new
CubicWeb commands). Then, we write the following code:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment