Add HarvestProject.deleted
flag to track deletions in Harvest
set this flag instead of deleting project, so we do not lose other info about it. can delete manually if truly unwanted
This commit is contained in:
parent
259d3b0f33
commit
3883a8551f
|
@ -0,0 +1,33 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
"""add project.deleted
|
||||
|
||||
Revision ID: 5505c0e60d28
|
||||
Revises: d59ce24c2f9f
|
||||
Create Date: 2022-01-30 12:08:04.338229
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '5505c0e60d28'
|
||||
down_revision = 'd59ce24c2f9f'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
import rattail.db.types
|
||||
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
||||
# harvest_project
|
||||
op.add_column('harvest_project', sa.Column('deleted', sa.Boolean(), nullable=True))
|
||||
op.add_column('harvest_project_version', sa.Column('deleted', sa.Boolean(), autoincrement=False, nullable=True))
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
||||
# harvest_project
|
||||
op.drop_column('harvest_project_version', 'deleted')
|
||||
op.drop_column('harvest_project', 'deleted')
|
|
@ -190,6 +190,10 @@ class HarvestProject(model.Base):
|
|||
|
||||
updated_at = sa.Column(sa.DateTime(), nullable=True)
|
||||
|
||||
deleted = sa.Column(sa.Boolean(), nullable=True, doc="""
|
||||
Flag indicating the record has been deleted in Harvest.
|
||||
""")
|
||||
|
||||
def __str__(self):
|
||||
return self.name or ''
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@ import datetime
|
|||
import decimal
|
||||
import logging
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from rattail import importing
|
||||
from rattail.util import OrderedDict
|
||||
from rattail_harvest import importing as rattail_harvest_importing
|
||||
|
@ -126,6 +128,22 @@ class HarvestProjectImporter(FromHarvest, rattail_harvest_importing.model.Harves
|
|||
Import project data from Harvest
|
||||
"""
|
||||
|
||||
@property
|
||||
def supported_fields(self):
|
||||
fields = list(super(HarvestProjectImporter, self).supported_fields)
|
||||
|
||||
# this is for local tracking only; is not in harvest
|
||||
fields.remove('deleted')
|
||||
|
||||
return fields
|
||||
|
||||
def cache_query(self):
|
||||
model = self.model
|
||||
return self.session.query(model.HarvestProject)\
|
||||
.filter(sa.or_(
|
||||
model.HarvestProject.deleted == False,
|
||||
model.HarvestProject.deleted == None))
|
||||
|
||||
def get_host_objects(self):
|
||||
return self.webapi.get_projects()['projects']
|
||||
|
||||
|
@ -168,6 +186,13 @@ class HarvestProjectImporter(FromHarvest, rattail_harvest_importing.model.Harves
|
|||
|
||||
return data
|
||||
|
||||
def can_delete_object(self, project, data):
|
||||
return not project.deleted
|
||||
|
||||
def delete_object(self, project):
|
||||
project.deleted = True
|
||||
return True
|
||||
|
||||
|
||||
class HarvestTaskImporter(FromHarvest, rattail_harvest_importing.model.HarvestTaskImporter):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue