DRY principle - example cluster add calculation

This commit is contained in:
Ozbolt Menegatti 2020-03-30 20:32:52 +02:00
parent 49875416b2
commit e04b4d7a2f

View File

@ -3,6 +3,7 @@ from message.simple_messages import NoReset, DataChgClickMessage
import message.common_accessors as common_accessors
from browser import document
from model import Sense, Example
from model.example_clusters import ExampleClusters
class QuestionMessage(Message):
@ -111,12 +112,6 @@ class ExampleClusterAdd(DataChgClickMessage):
def update_model(self, model):
example = self.get_arg(0, Example)
max_example_cluster_num = 0
for sense in model.entry.senses:
for ex in sense.examples:
cnum = ex.get_cluster()
if cnum is not None:
max_example_cluster_num = max(max_example_cluster_num, cnum)
max_example_cluster_num = ExampleClusters.first_empty_cluster()
example.set_cluster(max_example_cluster_num + 1)