Skip to content

Commit

Permalink
Merge pull request MaxBo#649 from MaxBo/feature/Frontend
Browse files Browse the repository at this point in the history
create quantities to questions on solution-part change; force NEW sol…
  • Loading branch information
ChrFr authored Dec 9, 2019
2 parents dbb405e + c923cd8 commit fe6f75c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 2 additions & 4 deletions repair/apps/changes/models/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ def trigger_implementationquantity_sii(sender, instance,
solution = Solution.objects.get(pk=sii.solution.id)
for question in solution.question.all():
new, is_created = ImplementationQuantity.objects.\
get_or_create(implementation=sii, question=question,
value=0)
get_or_create(implementation=sii, question=question, value=0)
if is_created:
new.save()

Expand All @@ -102,8 +101,7 @@ def trigger_implementationarea_sii(sender, instance,
for area in solution.possible_implementation_area.all():
new, is_created = ImplementationArea.objects.\
get_or_create(implementation=sii,
possible_implementation_area=area,
geom=None)
possible_implementation_area=area)
if is_created:
new.save()

Expand Down
21 changes: 21 additions & 0 deletions repair/apps/changes/serializers/solutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from repair.apps.changes.models import (SolutionCategory,
Solution,
ImplementationQuestion,
SolutionInStrategy,
ImplementationQuantity,
SolutionPart,
AffectedFlow,
PossibleImplementationArea,
Expand Down Expand Up @@ -338,6 +340,7 @@ def update(self, instance, validated_data):
affected_flows = validated_data.pop('affected_flows', None)
flow_reference = validated_data.pop('flow_reference', None)
flow_changes = validated_data.pop('flow_changes', None)
question = validated_data.pop('question', None)
instance = super().update(instance, validated_data)
if flow_reference:
if instance.flow_reference:
Expand All @@ -356,6 +359,24 @@ def update(self, instance, validated_data):
for f in affected_flows:
flow = AffectedFlow(solution_part=instance, **f)
flow.save()
if question:
implementations = SolutionInStrategy.objects.filter(
solution=instance.solution)
for implementation in implementations:
ex = ImplementationQuantity.objects.filter(
implementation=implementation, question=question)
# create if not existing (in case questions were added after
# creation the implementation by user)
if len(ex) != 1:
# workaround: old code produced duplicate quantities,
# remove duplicates
ex.delete()
new = ImplementationQuantity(
implementation=implementation,
question=question,
value=0
)
new.save()
instance.save()
return instance

1 change: 1 addition & 0 deletions repair/js/views/strategy/setup-solution-part.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ var SolutionPartView = BaseView.extend(
this.hasQuestion = (question != null);
question = this.questions.get(question);
this.isAbsolute = (this.hasQuestion) ? question.get('is_absolute'): this.model.get('is_absolute');
if (this.scheme.toLowerCase() == 'new') this.isAbsolute = true;

var questValue = (this.hasQuestion) ? 'true': 'false';
this.hasQuestionRadios.forEach(function(radio){
Expand Down

0 comments on commit fe6f75c

Please sign in to comment.