Skip to content

Commit

Permalink
add event action - make a copy of existing event config instead of us…
Browse files Browse the repository at this point in the history
…ing latest event template
  • Loading branch information
salabh-aot committed Nov 6, 2023
1 parent eb88dd1 commit 2fb1fc2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions epictrack-api/src/api/actions/add_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
from api.actions.base import ActionFactory
from api.models import db
from api.models.event_configuration import EventConfiguration
from api.models.event_template import EventTemplate
from api.models.phase_code import PhaseCode
from api.models.work_phase import WorkPhase
from api.schemas.response.event_configuration_response import EventConfigurationResponseSchema
from api.schemas.response.event_template_response import EventTemplateResponseSchema


# pylint: disable=import-outside-toplevel


class AddEvent(ActionFactory): # pylint: disable=too-few-public-methods
class AddEvent(ActionFactory):
"""Add a new event"""

def run(self, source_event, params) -> None:
Expand Down Expand Up @@ -49,32 +49,22 @@ def get_additional_params(self, params):
.filter(WorkPhase.is_active.is_(True))
.first()
)
event_template = (
db.session.query(EventTemplate)
old_event_config = (
db.session.query(EventConfiguration)
.filter(
EventTemplate.phase_id == phase_query.c.id,
EventTemplate.name == params.pop("event_name"),
EventTemplate.is_active.is_(True),
EventConfiguration.work_phase_id == work_phase.id,
EventConfiguration.name == params.pop("event_name"),
EventConfiguration.is_active.is_(True),
)
.first()
)
event_configuration = {
"name": event_template.name,
"parent_id": event_template.parent_id,
"event_type_id": event_template.event_type_id,
"event_category_id": event_template.event_category_id,
"start_at": params["start_at"],
"number_of_days": event_template.number_of_days,
"mandatory": event_template.mandatory,
"event_position": event_template.event_position,
"multiple_days": event_template.multiple_days,
"sort_order": event_template.sort_order,
"template_id": event_template.id,
"work_phase_id": work_phase.id,
}

event_configuration = EventConfigurationResponseSchema().dump(old_event_config)
event_configuration["start_at"] = params["start_at"]
del event_configuration["id"]
event_configuration = EventConfiguration(**event_configuration)
event_configuration.flush()
template_json = EventTemplateResponseSchema().dump(event_template)
template_json = EventTemplateResponseSchema().dump(old_event_config.event_template)
WorkService.copy_outcome_and_actions(template_json, event_configuration)
event_data = {
"event_configuration_id": event_configuration.id,
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 2fb1fc2

Please sign in to comment.