Rename all tables/models for Harvest "cache"
make this more explicit, for better naming convention
This commit is contained in:
parent
509405cb34
commit
aa87ce57be
7 changed files with 324 additions and 88 deletions
|
@ -49,11 +49,11 @@ class FromHarvestToRattail(importing.ToRattailHandler):
|
|||
|
||||
def get_importers(self):
|
||||
importers = OrderedDict()
|
||||
importers['HarvestUser'] = HarvestUserImporter
|
||||
importers['HarvestClient'] = HarvestClientImporter
|
||||
importers['HarvestProject'] = HarvestProjectImporter
|
||||
importers['HarvestTask'] = HarvestTaskImporter
|
||||
importers['HarvestTimeEntry'] = HarvestTimeEntryImporter
|
||||
importers['HarvestCacheUser'] = HarvestCacheUserImporter
|
||||
importers['HarvestCacheClient'] = HarvestCacheClientImporter
|
||||
importers['HarvestCacheProject'] = HarvestCacheProjectImporter
|
||||
importers['HarvestCacheTask'] = HarvestCacheTaskImporter
|
||||
importers['HarvestCacheTimeEntry'] = HarvestCacheTimeEntryImporter
|
||||
return importers
|
||||
|
||||
|
||||
|
@ -90,14 +90,14 @@ class FromHarvest(importing.Importer):
|
|||
return data
|
||||
|
||||
|
||||
class HarvestUserImporter(FromHarvest, rattail_harvest_importing.model.HarvestUserImporter):
|
||||
class HarvestCacheUserImporter(FromHarvest, rattail_harvest_importing.model.HarvestCacheUserImporter):
|
||||
"""
|
||||
Import user data from Harvest
|
||||
"""
|
||||
|
||||
@property
|
||||
def supported_fields(self):
|
||||
fields = list(super(HarvestUserImporter, self).supported_fields)
|
||||
fields = list(super().supported_fields)
|
||||
|
||||
# this is for local tracking only; is not in harvest
|
||||
fields.remove('person_uuid')
|
||||
|
@ -111,7 +111,7 @@ class HarvestUserImporter(FromHarvest, rattail_harvest_importing.model.HarvestUs
|
|||
return self.webapi.get_users()['users']
|
||||
|
||||
def normalize_host_object(self, user):
|
||||
data = super(HarvestUserImporter, self).normalize_host_object(user)
|
||||
data = super().normalize_host_object(user)
|
||||
if data:
|
||||
|
||||
# TODO: for some reason the API used to include the these
|
||||
|
@ -131,7 +131,7 @@ class HarvestUserImporter(FromHarvest, rattail_harvest_importing.model.HarvestUs
|
|||
return data
|
||||
|
||||
|
||||
class HarvestClientImporter(FromHarvest, rattail_harvest_importing.model.HarvestClientImporter):
|
||||
class HarvestCacheClientImporter(FromHarvest, rattail_harvest_importing.model.HarvestCacheClientImporter):
|
||||
"""
|
||||
Import client data from Harvest
|
||||
"""
|
||||
|
@ -140,14 +140,14 @@ class HarvestClientImporter(FromHarvest, rattail_harvest_importing.model.Harvest
|
|||
return self.webapi.get_clients()['clients']
|
||||
|
||||
|
||||
class HarvestProjectImporter(FromHarvest, rattail_harvest_importing.model.HarvestProjectImporter):
|
||||
class HarvestCacheProjectImporter(FromHarvest, rattail_harvest_importing.model.HarvestCacheProjectImporter):
|
||||
"""
|
||||
Import project data from Harvest
|
||||
"""
|
||||
|
||||
@property
|
||||
def supported_fields(self):
|
||||
fields = list(super(HarvestProjectImporter, self).supported_fields)
|
||||
fields = list(super().supported_fields)
|
||||
|
||||
# this is for local tracking only; is not in harvest
|
||||
fields.remove('deleted')
|
||||
|
@ -156,16 +156,16 @@ class HarvestProjectImporter(FromHarvest, rattail_harvest_importing.model.Harves
|
|||
|
||||
def cache_query(self):
|
||||
model = self.model
|
||||
return self.session.query(model.HarvestProject)\
|
||||
return self.session.query(model.HarvestCacheProject)\
|
||||
.filter(sa.or_(
|
||||
model.HarvestProject.deleted == False,
|
||||
model.HarvestProject.deleted == None))
|
||||
model.HarvestCacheProject.deleted == False,
|
||||
model.HarvestCacheProject.deleted == None))
|
||||
|
||||
def get_host_objects(self):
|
||||
return self.webapi.get_projects()
|
||||
|
||||
def normalize_host_object(self, project):
|
||||
data = super(HarvestProjectImporter, self).normalize_host_object(project)
|
||||
data = super().normalize_host_object(project)
|
||||
if not data:
|
||||
return
|
||||
|
||||
|
@ -211,7 +211,7 @@ class HarvestProjectImporter(FromHarvest, rattail_harvest_importing.model.Harves
|
|||
return True
|
||||
|
||||
|
||||
class HarvestTaskImporter(FromHarvest, rattail_harvest_importing.model.HarvestTaskImporter):
|
||||
class HarvestCacheTaskImporter(FromHarvest, rattail_harvest_importing.model.HarvestCacheTaskImporter):
|
||||
"""
|
||||
Import task data from Harvest
|
||||
"""
|
||||
|
@ -220,7 +220,7 @@ class HarvestTaskImporter(FromHarvest, rattail_harvest_importing.model.HarvestTa
|
|||
return self.webapi.get_tasks()['tasks']
|
||||
|
||||
|
||||
class HarvestTimeEntryImporter(FromHarvest, rattail_harvest_importing.model.HarvestTimeEntryImporter):
|
||||
class HarvestCacheTimeEntryImporter(FromHarvest, rattail_harvest_importing.model.HarvestCacheTimeEntryImporter):
|
||||
"""
|
||||
Import time entry data from Harvest
|
||||
"""
|
||||
|
@ -239,7 +239,7 @@ class HarvestTimeEntryImporter(FromHarvest, rattail_harvest_importing.model.Harv
|
|||
return self.webapi.get_time_entry(entry_id)
|
||||
|
||||
def normalize_host_object(self, entry):
|
||||
data = super(HarvestTimeEntryImporter, self).normalize_host_object(entry)
|
||||
data = super().normalize_host_object(entry)
|
||||
if not data:
|
||||
return
|
||||
|
||||
|
|
|
@ -37,20 +37,20 @@ log = logging.getLogger(__name__)
|
|||
# harvest cache models
|
||||
##############################
|
||||
|
||||
class HarvestUserImporter(ToRattail):
|
||||
model_class = model.HarvestUser
|
||||
class HarvestCacheUserImporter(ToRattail):
|
||||
model_class = model.HarvestCacheUser
|
||||
|
||||
class HarvestClientImporter(ToRattail):
|
||||
model_class = model.HarvestClient
|
||||
class HarvestCacheClientImporter(ToRattail):
|
||||
model_class = model.HarvestCacheClient
|
||||
|
||||
class HarvestProjectImporter(ToRattail):
|
||||
model_class = model.HarvestProject
|
||||
class HarvestCacheProjectImporter(ToRattail):
|
||||
model_class = model.HarvestCacheProject
|
||||
|
||||
class HarvestTaskImporter(ToRattail):
|
||||
model_class = model.HarvestTask
|
||||
class HarvestCacheTaskImporter(ToRattail):
|
||||
model_class = model.HarvestCacheTask
|
||||
|
||||
class HarvestTimeEntryImporter(ToRattail):
|
||||
model_class = model.HarvestTimeEntry
|
||||
class HarvestCacheTimeEntryImporter(ToRattail):
|
||||
model_class = model.HarvestCacheTimeEntry
|
||||
|
||||
# flags to auto-create records for "unknown" references
|
||||
auto_create_unknown_project = True
|
||||
|
@ -59,12 +59,12 @@ class HarvestTimeEntryImporter(ToRattail):
|
|||
warn_for_unknown_project = True
|
||||
|
||||
def setup(self):
|
||||
super(HarvestTimeEntryImporter, self).setup()
|
||||
super().setup()
|
||||
model = self.model
|
||||
|
||||
if 'project_id' in self.fields:
|
||||
self.harvest_projects_by_id = self.app.cache_model(
|
||||
self.session, model.HarvestProject, key='id')
|
||||
self.session, model.HarvestCacheProject, key='id')
|
||||
|
||||
def cache_query(self):
|
||||
query = super().cache_query()
|
||||
|
@ -81,12 +81,12 @@ class HarvestTimeEntryImporter(ToRattail):
|
|||
return self.harvest_projects_by_id.get(project_id)
|
||||
|
||||
model = self.model
|
||||
return self.session.query(model.HarvestProject)\
|
||||
.filter(model.HarvestProject.id == project_id)\
|
||||
return self.session.query(model.HarvestCacheProject)\
|
||||
.filter(model.HarvestCacheProject.id == project_id)\
|
||||
.first()
|
||||
|
||||
def update_object(self, entry, data, local_data=None):
|
||||
entry = super(HarvestTimeEntryImporter, self).update_object(entry, data, local_data)
|
||||
entry = super().update_object(entry, data, local_data)
|
||||
model = self.model
|
||||
|
||||
if 'project_id' in self.fields:
|
||||
|
@ -97,7 +97,7 @@ class HarvestTimeEntryImporter(ToRattail):
|
|||
logger("unknown project id %s for time entry id %s: %s",
|
||||
project_id, entry.id, entry)
|
||||
if self.auto_create_unknown_project:
|
||||
project = model.HarvestProject()
|
||||
project = model.HarvestCacheProject()
|
||||
project.id = project_id
|
||||
project.name = "(unknown)"
|
||||
self.session.add(project)
|
||||
|
|
|
@ -34,11 +34,11 @@ class FromRattailToRattailHarvestMixin(object):
|
|||
"""
|
||||
|
||||
def add_harvest_importers(self, importers):
|
||||
importers['HarvestUser'] = HarvestUserImporter
|
||||
importers['HarvestClient'] = HarvestClientImporter
|
||||
importers['HarvestProject'] = HarvestProjectImporter
|
||||
importers['HarvestTask'] = HarvestTaskImporter
|
||||
importers['HarvestTimeEntry'] = HarvestTimeEntryImporter
|
||||
importers['HarvestCacheUser'] = HarvestCacheUserImporter
|
||||
importers['HarvestCacheClient'] = HarvestCacheClientImporter
|
||||
importers['HarvestCacheProject'] = HarvestCacheProjectImporter
|
||||
importers['HarvestCacheTask'] = HarvestCacheTaskImporter
|
||||
importers['HarvestCacheTimeEntry'] = HarvestCacheTimeEntryImporter
|
||||
return importers
|
||||
|
||||
|
||||
|
@ -46,19 +46,19 @@ class FromRattailToRattailHarvestMixin(object):
|
|||
# harvest cache models
|
||||
##############################
|
||||
|
||||
class HarvestUserImporter(base.FromRattail, rattail_harvest_importing.model.HarvestUserImporter):
|
||||
class HarvestCacheUserImporter(base.FromRattail, rattail_harvest_importing.model.HarvestCacheUserImporter):
|
||||
pass
|
||||
|
||||
class HarvestClientImporter(base.FromRattail, rattail_harvest_importing.model.HarvestClientImporter):
|
||||
class HarvestCacheClientImporter(base.FromRattail, rattail_harvest_importing.model.HarvestCacheClientImporter):
|
||||
pass
|
||||
|
||||
class HarvestProjectImporter(base.FromRattail, rattail_harvest_importing.model.HarvestProjectImporter):
|
||||
class HarvestCacheProjectImporter(base.FromRattail, rattail_harvest_importing.model.HarvestCacheProjectImporter):
|
||||
pass
|
||||
|
||||
class HarvestTaskImporter(base.FromRattail, rattail_harvest_importing.model.HarvestTaskImporter):
|
||||
class HarvestCacheTaskImporter(base.FromRattail, rattail_harvest_importing.model.HarvestCacheTaskImporter):
|
||||
pass
|
||||
|
||||
class HarvestTimeEntryImporter(base.FromRattail, rattail_harvest_importing.model.HarvestTimeEntryImporter):
|
||||
class HarvestCacheTimeEntryImporter(base.FromRattail, rattail_harvest_importing.model.HarvestCacheTimeEntryImporter):
|
||||
|
||||
def query(self):
|
||||
query = super().query()
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -30,44 +30,44 @@ from rattail.importing import versions as base
|
|||
class HarvestVersionMixin(object):
|
||||
|
||||
def add_harvest_importers(self, importers):
|
||||
importers['HarvestUser'] = HarvestUserImporter
|
||||
importers['HarvestClient'] = HarvestClientImporter
|
||||
importers['HarvestProject'] = HarvestProjectImporter
|
||||
importers['HarvestTask'] = HarvestTaskImporter
|
||||
importers['HarvestTimeEntry'] = HarvestTimeEntryImporter
|
||||
importers['HarvestCacheUser'] = HarvestCacheUserImporter
|
||||
importers['HarvestCacheClient'] = HarvestCacheClientImporter
|
||||
importers['HarvestCacheProject'] = HarvestCacheProjectImporter
|
||||
importers['HarvestCacheTask'] = HarvestCacheTaskImporter
|
||||
importers['HarvestCacheTimeEntry'] = HarvestCacheTimeEntryImporter
|
||||
return importers
|
||||
|
||||
|
||||
class HarvestUserImporter(base.VersionImporter):
|
||||
class HarvestCacheUserImporter(base.VersionImporter):
|
||||
|
||||
@property
|
||||
def host_model_class(self):
|
||||
return self.model.HarvestUser
|
||||
return self.model.HarvestCacheUser
|
||||
|
||||
|
||||
class HarvestClientImporter(base.VersionImporter):
|
||||
class HarvestCacheClientImporter(base.VersionImporter):
|
||||
|
||||
@property
|
||||
def host_model_class(self):
|
||||
return self.model.HarvestClient
|
||||
return self.model.HarvestCacheClient
|
||||
|
||||
|
||||
class HarvestProjectImporter(base.VersionImporter):
|
||||
class HarvestCacheProjectImporter(base.VersionImporter):
|
||||
|
||||
@property
|
||||
def host_model_class(self):
|
||||
return self.model.HarvestProject
|
||||
return self.model.HarvestCacheProject
|
||||
|
||||
|
||||
class HarvestTaskImporter(base.VersionImporter):
|
||||
class HarvestCacheTaskImporter(base.VersionImporter):
|
||||
|
||||
@property
|
||||
def host_model_class(self):
|
||||
return self.model.HarvestTask
|
||||
return self.model.HarvestCacheTask
|
||||
|
||||
|
||||
class HarvestTimeEntryImporter(base.VersionImporter):
|
||||
class HarvestCacheTimeEntryImporter(base.VersionImporter):
|
||||
|
||||
@property
|
||||
def host_model_class(self):
|
||||
return self.model.HarvestTimeEntry
|
||||
return self.model.HarvestCacheTimeEntry
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue