Skip to content
This repository has been archived by the owner on Feb 28, 2018. It is now read-only.

Importing and serializing company data #263

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Finished with companies data
Ilozuluchris committed Oct 7, 2017
commit b4b65ea32b79c85e18b97bef536ca988b42b2022
23 changes: 8 additions & 15 deletions jarbas/core/management/commands/companies.py
Original file line number Diff line number Diff line change
@@ -52,6 +52,8 @@ def save_companies(self):
def transform(row):
return row._asdict()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a method for that… calling _asdict() in the for loop seams enough.




Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need these extra spaces: according to PEP8 1 line is fine to separate class methods.

def save_activities(self, row):
data = dict(
code=row['main_activity_code'],
@@ -70,25 +72,12 @@ def save_activities(self, row):

return [main], secondaries

class MyDateField(rows.fields.DateField):
INPUT_FORMAT = '%Y-%m-%dT%H:%M:%S'

value = MyDateField.deserialize('2014-02-16T00:00:00')
company = {'email': 'ahoy',
'latitude': '3.1415',
'longitude': '-42',
'opening': '31/12/1969',
'situation_date': '31/12/1969',
'special_situation_date': '31/12/1969'}

#lastthoughts:load test message as dict,then create class that extends the field time to be convert using class newclass(extended class).deseralize(value to deserialized).When company is imported is field type inferred
def serialize(self, row):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically the great point of using rows is to get rid of the serialize method. The idea is to use the force_types keyword argument when calling rows.import_from_csv and let rows serialize stuff as we need it (for example, #211).

row['email'] = rows.fields.EmailField().deserialize(row['email'])
row['email'] = self.to_email(row['email'])
dates = ('opening', 'situation_date', 'special_situation_date')
for key in dates:
row[key] = rows.fields.DatetimeField().deserialize(row[key])


row[key] = InputDateField().deserialize(row[key])
decimals = ('latitude', 'longitude')
for key in decimals:
#row[key] = self.to_number(row[key])
@@ -103,3 +92,7 @@ def to_email(email):

except ValidationError:
return None


class InputDateField(rows.fields.DateField):
INPUT_FORMAT = '%d-%m-%Y'